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
amatt 5
I am trying to create a day/night setup via lua. Where at 8 am-10pm the variable is set to day and at 10pm-8am the variable is set to night. I cannot successfully do this via a block scene so i have used LUA to do this. Could someone help me look over my code to see if this is correct as i am fairly new in LUA. Thanks!
--[[
%% autostart
%% properties
%% globals
--]]
-- Only need to call getSourceTrigger once
-- For better debugging, I moved it to the top,
-- before countScenes
local sourceTrigger = fibaro:getSourceTrigger()
fibaro:debug("Script started because of: " .. sourceTrigger["type"])
if fibaro:countScenes()>1 then
fibaro:debug("Scene already running, aborting this one")
fibaro:abort()
end
if (sourceTrigger["type"] == "autostart") then
while true do
local currentDate = os.date("*t")
-- Do the time-string manipulation thingy here, instead of in
-- each and every if-then statement
-- %02u means unsigned int, 2 wide, leading zero
TimeAsString = string.format("%02u",currentDate.hour).. ":" ..
string.format("%02u", currentDate.min)
fibaro:debug("TimeAsString: ".. TimeAsString)
Day_night = fibaro:getGlobalValue("Day_night")
fibaro:debug("Day_night: " .. Day_night)
if
(
currentDate.wday == 1
or currentDate.wday == 2
or currentDate.wday == 3
or currentDate.wday == 4
or currentDate.wday == 5
or currentDate.wday == 6
or currentDate.wday == 7
)
and
TimeAsString == "8:00"
then
fibaro:debug("Setting scenario number 1")
fibaro:setGlobal("Day_night", "Day")
elseif
(
currentDate.wday == 1
or currentDate.wday == 2
or currentDate.wday == 3
or currentDate.wday == 4
or currentDate.wday == 5
or currentDate.wday == 6
or currentDate.wday == 7
)
and TimeAsString == "22:00"
then
fibaro:debug("Setting scenario number 2")
fibaro:setGlobal("Day_night", "Night")
else
fibaro:debug("Current time doesn't match any scenario")
end
end
fibaro:debug("Scene not started, this is autostart-only!")
end -- end of sourceTrigger["type"] == "autostart"
Link to comment
Share on other sites
1 answer 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.