I have very simple LUA script that was working well for years but i want to improve it a little.
When my childs switch on the light in the night, before i was switching off after 15 minutos. This is the script that was working well.
Now i want to invoke an option in the HUE bridge that is named "Go to sleep" function that itself go dimming down the light during 15 minutos and finally switch off.
The problem is that i am detecting the event of swith on the light by my childs with a "devicechanged" event, and that event is triggering again in an infinite loop when the HUE bridge itself is dimming down the light.
Code: Select all
commandArray = {}
if (devicechanged['Irina']) then
if (devicechanged['Irina'] == 'Set Color) then
print('Luz Irina changed to ON')
date = os.date("*t")
-- print (date.hour)
if (date.hour < 7 or date.hour >= 21) then
-- commandArray['Irina']='Off AFTER 900' -- this was the first implementation
commandArray['Dormir Irina']='On' -- this is the new invoke to the funcion of HUE "Go to sleep".
end
end
end
return commandArray
This is the log of triggering the first event of switch on the light and entering in the loop:
2020-10-28 23:43:09.507 Status: EventSystem: Script event triggered: Apagar_Luz_Irina
2020-10-28 23:43:20.869 Status: LUA: Luz Irina changed to ON
2020-10-28 23:43:20.870 Status: EventSystem: Script event triggered: Apagar_Luz_Irina
2020-10-28 23:43:32.306 Status: LUA: Luz Irina changed to ON
2020-10-28 23:43:32.307 Status: EventSystem: Script event triggered: Apagar_Luz_Irina
2020-10-28 23:43:43.651 Status: LUA: Luz Irina changed to ON
2020-10-28 23:43:43.652 Status: EventSystem: Script event triggered: Apagar_Luz_Irina
2020-10-28 23:43:55.016 Status: LUA: Luz Irina changed to ON
2020-10-28 23:43:55.018 Status: EventSystem: Script event triggered: Apagar_Luz_Irina
2020-10-28 23:44:17.705 Status: LUA: Luz Irina changed to ON
I don't know why in that log is not appearing the events of (HUE) that is other times like this (switching manually the "Dormir Irina" switch):
2020-10-29 19:30:16.619 (HUE) Color Switch (Dormir Irina)
2020-10-29 19:30:16.489 Status: User: Admin initiated a switch command (179/Dormir Irina/On)
2020-10-29 19:30:20.999 (HUE) Color Switch (Irina)
2020-10-29 19:30:21.018 (HUE) Color Switch (Group Dormitorio Irina)
Thank you very much for any clue about how to resolve this issue....