• Professional advice
  • Order before 23.59 uur shipped today
  • Almost always available (+31 73 762 0 762)
  • Monday open late

Day Night scene with LUA

Question from a customer "I want the scene only to run between sunrise and sunset"

This is a very common question. So we wrote a piece of script to solve this issue.

Step 1:
Create a predefined variable in the variable panel.
Variabele aanmaken

 

Step 2:
Make a LUA-script that will change the variable from sunset to sunrise at the right moment.g:


--[[
%% autostart
%% properties
%% globals
--]]

 
--What has started the scene? 
local sourceTrigger = fibaro:getSourceTrigger();
 
--------------------------------------------------
if (sourceTrigger["type"] == "autostart") then
 
   --check every minute the actual time
   while true do
 
   --Define times
   local currentDate = os.date("*t");
   local TimeNow = (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min))
   local sunrise=fibaro:getValue(1, "sunriseHour")
   local sunset=fibaro:getValue(1, "sunsetHour")
 
   local startSource = fibaro:getSourceTrigger();
 
   fibaro:debug("The time is: "..TimeNow)
  fibaro:debug("Sunrise: "..sunrise)
   fibaro:debug("Sunset: "..sunset)
  --At sunrise    
  if (TimeNow == sunrise) then
      fibaro:setGlobal("DayNight","Day")
  end
 
   --at sunset    
  if (TimeNow == sunset) then
      fibaro:setGlobal("DayNight","Night")
  end
    
   --wait a minute 
   fibaro:sleep(60*1000);
end
else
   --This is what happens when you start the scene manualy
   ---------------------------------------------------
   local DayNight=fibaro:getGlobalValue("DayNight")
   if DayNight == "Night" then
      fibaro:setGlobal("DayNight","Day")
   else
      fibaro:setGlobal("DayNight","Night")
   end
end
 
Step 3:
The use of the variable in a scene:
FIBARO scene with variable
 
Customer Service Phone

+31737620762
mon-fri: 10am-5pm and sat 10am-3pm

 
Adress

Gerstakker 16 5236 VG Empel Netherlands

Google maps