Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
Bips 0
I have set a global variable called "LightsOn" in the HC2 variable panels with a value of 0
What im trying to do is set the value to 1 if the time of day is after 17:00 and before 07:00.
Got other scenes that will switch on lights if the value is 1, which seem to work ok when the value is 1.
Problem im having is the LUA code im using doesnt trigger by itself, if i run it, it sets to 1 if the time is from 17:00-07:00, and zero if not.
How can i get the code to trigger automatically, even though i have set it to auto
Or is there a better way of setting the global variable?
--[[
%% autostart
%% properties
%% weather
%% events
%% globals
LightsOn
--]]
local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
local LightsOn = fibaro:getGlobalValue("LightsOn")
if (
( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "17", "15")) or tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "07", "00"))) and (math.floor(os.time()/60)-math.floor(1676306520/60))%1 == 0 )
)
then
fibaro:setGlobal("LightsOn", "1");
fibaro:debug("Stage 1")
fibaro:debug(LightsOn)
end
setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
startSource["type"] == "other"
)
then
fibaro:setGlobal("LightsOn", "0");
fibaro:debug("Stage 2")
fibaro:debug(LightsOn)
end
end
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.