Hi! 😊

Morning Lights Alarm instead of sound and weather forecast

Morning Lights Alarm instead of sound and weather forecast


From my previous post (Flashing lights when you go Incognito Here), another crazy idea banged on my mind 😀

So instead of having an Alarm  in the morning, I wanted to wake up with a customised lighting source like sunrise @ 5.30AM.

Based on researched work on Light Alarms, some people who tried this method actually helps them in order to wake up early without fatigue and they no longer have to slam on the snooze button

You can check this interesting article on gizmodo.

http://gizmodo.com/a-light-up-alarm-completely-changed-my-life-1535668863

 

All I need now is a trigger to send a request to NodeRed so that it can switch on the light @5.30AM (in order to get on time at work around 8 (to be precise 8.20)) but what if it shows me lights of a forecasted weather during the day O.o…well yes, I have made it, see the actions I have done to achieve it.

The Plan:

  1. Start Light @ 5.25AM
  2. GET the weather forecast during the day
  3. Based on the weather, associate a color
  4. Switch milight Bulb On with the color (brightness lowest point)
  5. Every min from 5.25 glow the brightness by 5 untill 100 (In Progress)
  6. At 5.50, Switch off the Bulb

(set alarm on mobile @ 6hr in case I haven’t woke up)

The actions:

  • Step One – Trigger @ 5.2AM

2016-09-11-15_23_48-node-red-_-10-0-0-9

  • GET the weather forecast during the day

I have used a NODE from forecastio, (instructions for installation given below)
http://flows.nodered.org/node/node-red-node-forecastio

You will get 1000 free requests  per day and all you need is to know your longlitude/Latitude of your location and the API key (which you will get after registration on https://developer.forecast.io/)

  • Based on the weather, associate color

A function intepretWeather is used  to set a color code based on the forecasted weather, however the color pattern is still not finalised.

 

  • Switch milight Bulb On with the color (brightness lowest point)

With the milight Node (node-red-contrib-milight), it does not come with brightness parameter.

I have modified the Node module, in order  to implement a piece of code that can allow me to set my own brightness

your path to node-red modules

~PATH/.node-red/node_modules/node-red-contrib-milight/

file: MiLight.js

<<<

37 if (msg.payload === ‘white’) light.sendCommands(commands.rgbw.on(zone), commands.rgbw.brightness(100), commands.rgbw.whiteM ode(zone));
38 //Added Block Kushal – add brightness to light
39 var mypayload = msg.payload.split(“,”);
40 //if !brightness , set to 100
41 if ((mypayload[1] == “”) || (mypayload[1] == “undefined”)) mypayload[1] = 100;
42
43 if ((!isNaN(mypayload[0])) && (!isNaN(mypayload[1]) )) {
44
45 light.sendCommands(commands.rgbw.hue(mypayload[0]), commands.rgbw.brightness(mypayload[1]));
46 }
47 //End Block Kushal
48
49 }

<<<<

A restart of node-red is required (service nodered restart)

Afterwards, you can test the milight by using a post to http://IPRPI:1880/led?power=10&brightness=100

exemple msg.payload=”10,100″–> this will turn the light blue and set the brightness to 100%.

  • Every min from 5.25 glow the brightness by 5 untill 100 (In Progress)

Still in Progress, a new function will be added to do this iteration or using a timestamps.

  • At 5.50, Switch off the Bulb
    A timestamp node is used to trigger an OFF to Milight

 

The whole diagram:

2016-09-11-15_47_09-node-red-_-10-0-0-9

the codes…for node red



[{"id":"d069937b.c169f","type":"MiLight","z":"7bd37bf2.0d1004","name":"MiLight","bulbtype":"rgbw","zone":"0","ip":"YOUR-IP","broadcast":false,"x":629.4285888671875,"y":228.4285888671875,"wires":[]},{"id":"34f440af.446ae","type":"http in","z":"7bd37bf2.0d1004","name":"Get-HttpRequests/led","url":"/led","method":"get","swaggerDoc":"","x":105.85714721679688,"y":87.4286117553711,"wires":[["4e822b8.4c444d4"]]},{"id":"d9a2fe17.dfe71","type":"debug","z":"7bd37bf2.0d1004","name":"","active":false,"console":"true","complete":"true","x":631.1428833007812,"y":432.57147216796875,"wires":[]},{"id":"4e822b8.4c444d4","type":"function","z":"7bd37bf2.0d1004","name":"checkInput","func":"//note to self\n//numHue 0 (blue) 50 (green) 80 (yellow) 99 (redish\n//code:- ON off disco white numhue\n\nif ( msg.payload.power == \"on\") {\n    msg.payload = 'on';\n}\n\nelse if  ( msg.payload.power == \"off\") {\n        msg.payload = 'off';\n}\n\nelse if  ( msg.payload.power == \"white\") {\n        msg.payload = 'white';\n}\n\nelse if  ( msg.payload.power == \"disco\") {\n        msg.payload = 'disco';\n}\nelse {\n    //random colors :D\n    //msg.payload= Math.floor (Math.random() * 100) ;\n    if ((msg.payload.brightness === \"\") || (msg.payload.brightness === \"undefined\")) msg.payload.brightness = 100;\n   msg.payload =  msg.payload.power + \",\" +  msg.payload.brightness \n  // msg.payload.hue =  msg.payload.power;\n  // msg.payload.brightness = msg.payload.brightness;\n\n}\n\nreturn msg;\n\n","outputs":"1","noerr":0,"x":357.857177734375,"y":161.5714569091797,"wires":[["d069937b.c169f","84a2f3db.09efc","400524fc.b40b5c","d9a2fe17.dfe71"]]},{"id":"94a44768.5188e8","type":"inject","z":"7bd37bf2.0d1004","name":"off","topic":"","payload":"{ \"power\": \"off\" }","payloadType":"json","repeat":"","crontab":"50 06 * * 1,2,3,4,5","once":false,"x":80,"y":213,"wires":[["4e822b8.4c444d4"]]},{"id":"87790643.e589e8","type":"inject","z":"7bd37bf2.0d1004","name":"AlarmDisco","topic":"Disco","payload":"{\"power\":\"disco\"}","payloadType":"json","repeat":"","crontab":"","once":false,"x":104,"y":147,"wires":[["4e822b8.4c444d4"]]},{"id":"43b195b0.b97d4c","type":"inject","z":"7bd37bf2.0d1004","name":"On","topic":"On","payload":"{ \"power\": \"on\"}","payloadType":"json","repeat":"","crontab":"20 05 * * 1,2,3,4,5","once":false,"x":81,"y":287,"wires":[["4e822b8.4c444d4","126272e.079708d"]]},{"id":"126272e.079708d","type":"forecastio","z":"7bd37bf2.0d1004","forecastio":"","name":"GetWeather","lon":"YOURLONG","lat":"YOURLAT","date":"","time":"","mode":"node","units":"auto","x":207,"y":338,"wires":[["76dd2a04.8027f4","d9a2fe17.dfe71","84a2f3db.09efc"]]},{"id":"76dd2a04.8027f4","type":"function","z":"7bd37bf2.0d1004","name":"InterpretWeather","func":"//note to self\n//numHue 0 (blue) 50 (green) 80 (yellow) 99 (redish\n//code:- ON off disco white numhue\n\n //clear-day, clear-night, rain, \n //snow, sleet, wind, fog, cloudy,\n// partly-cloudy-day, or partly-cloudy-night. \n// (Developers should ensure \n// that a sensible default is defined,\n// as additional values, such as hail, \n// thunderstorm, or \n// tornado, may be defined in the future.)\n \nif ( ( msg.payload.weather == \"clear-day\") || (msg.payload.weather == \"clear-night\") ) {\n    msg.payload.power = '30';\n}\n\nelse if ( ( msg.payload.weather == \"partly-cloudy-day\") || (msg.payload.weather == \"partly-cloudy-night\") ) {\n    msg.payload.power = '70';\n}\n\nelse if ( ( msg.payload.weather == \"fog\") || (msg.payload.weather == \"thunderstorm\") || (msg.payload.weather == \"tornado\")) {\n    msg.payload.power = '99';\n}\n\nelse if ( ( msg.payload.weather == \"rain\") || (msg.payload.weather == \"wind\") || (msg.payload.weather == \"cloudy\")) {\n    msg.payload.power = '10';\n}\n\nelse {\n    //life is like a disco-do not know what will happen!\n   msg.payload.power = 'disco';\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"x":359,"y":265,"wires":[["4e822b8.4c444d4","84a2f3db.09efc","d9a2fe17.dfe71"]]},{"id":"84a2f3db.09efc","type":"file","z":"7bd37bf2.0d1004","name":"Logs","filename":"/home/pi/alarmlights.txt","appendNewline":true,"createDir":false,"overwriteFile":"false","x":622,"y":336,"wires":[]},{"id":"400524fc.b40b5c","type":"http response","z":"7bd37bf2.0d1004","name":"Output","x":616,"y":152,"wires":[]}]


 

Hope it will actually help me in the morning!!

note: don’t forget to set an ALARM on your mobile In case the light don’t wake you up 😀

Made with ♡ ♥💕❤ from Mauritius