Yeelight wakeuplight based on alarm from cell phone

Moderator: leecollings

Post Reply
hansies
Posts: 4
Joined: Thursday 04 January 2018 15:25
Target OS: Linux
Domoticz version: stable
Contact:

Yeelight wakeuplight based on alarm from cell phone

Post by hansies »

I want to use my Yeelight RGB as Wake up light based on my alarm time from my cell phone. It should start 15 minutes before my alarm is set. After 15 minutes the process is done and at the same time my alarm should go off.

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:
Screenshot_20180125-131625.png
Screenshot_20180125-131625.png (32.32 KiB) Viewed 764 times
The HTTP requests are as follow:

Code: Select all

http://192.168.0.10:8080/json.htm?type=command&param=updateuservariable&vname=Alarmtime&vtype=integer&vvalue=" ++ alarm
'alarm' in the above command is a variable I get from the second block.

Code: Select all

http://192.168.0.10:8080/json.htm?type=command&param=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.
Domoticz stable | Intel NUC | VirtualBox | Ubuntu 16.04
RPI2B | RFLink
Yeelight | Sonoff Tasmota
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest