In Domoticz I made a user variable integer 'Alarmtime', a virtual on/off switch 'WakeupHans' and off course the Yeelight switch.
On my (Android) cell phone I use the free app Automate to get the time my alarm is set and sent that to Domoticz into the user variable via an HTTP request. (Other apps like Tasker should also be suitable to do this I suppose). The alarm time is in epoch (Unix time), but that's not a big issue.
Next to the alarm time Automate also sets the virtual switch to On. This to be sure my Wakeuplight will not go on by accident.
The flow in Automate is just 4 blocks and looks like this: The HTTP requests are as follow:
Code: Select all
http://192.168.0.10:8080/json.htm?type=command¶m=updateuservariable&vname=Alarmtime&vtype=integer&vvalue=" ++ alarm
Code: Select all
http://192.168.0.10:8080/json.htm?type=command¶m=switchlight&idx=84&switchcmd=On"
From that moment Domoticz is taking over with the following LUA event:
Code: Select all
commandArray = {}
currenttime = os.time(); -- get currentime in epoch format
alarmtime = uservariables['AlarmHans']; -- get alarmtime in Epoch format which is set by Automate
wakeuptime = alarmtime-915; -- 900 seconds (15 minutes) before my alarm is set. But I added 15 seconds more as Domoticz runs time event scripts only once a minute.
if (currenttime > wakeuptime) and -- condition is true when the currenttime is after the wakeuptime
(otherdevices['WakeupHans'] == 'On') then -- condition to be sure my wakeuplight only starts when Automate set my alarm
PORT = '55443'
IP = '192.168.0.34'
runcommandWakeupHans = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"cf_\",1,1,\"50,1,16731392,1,360000,2,1700,10,540000,2,2700,100\"]}\\r\\n' | nc -w1 " ..IP.." " ..PORT..""; -- Yeelight command for wakeuplight in 15 minutes
os.execute(runcommandparty);
print(runcommandWakeupHans);
commandArray['WakeupHans']='Off' -- Turn of the virtual switch
end
return commandArray
So all I got to do before I go to bed is set my alarm time and start this Automate flow (you can also change the flow that it keeps running in background, but I choose not to).
Maybe you like it and got ideas to improve it.