I meant to edit the "Sunrise alarm" function in the flow I posted on my second message. Anyway, I changed the code to have a gentler sunrise, starting from a red with minimum brightness to a yellow with full brightness, then switch to white at about 30% of brightness (maybe it could be changed with 25% or something like that to have a smoother transition) and go all the way up to white 100% (note I have warm white RGBW led lamp).
Just copy the code below and import it.
I'm also trying to get the suncalc + presence (with owntracks android app) thing working, but I have some problems. For testing purposes (and maybe some other nice things) I've installed the pushbullet node (and the android app) to have notifications for when I leave home (and be sure the lights are switched off). For now I only implemented a "turn on the light when I'm at home, in the evening and awake" because suncalc node only tells you about the beginning of day and night, but not how much light there could be outside. Maybe using multiple suncalc nodes and setting them with diferent types of ends (sunset, civil twilight, golden hour, dusk, etc) we can build the logic to set the brightness and color of the lights... just a thought.
[{"id":"a1e6a9c6.5e1958","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"33d9dd31.cc2622","type":"mqtt in","name":"Alarm Clock MQTT","topic":"alarmclock","broker":"a1e6a9c6.5e1958","x":115.99999237060547,"y":225.75,"z":"77df6b64.882094","wires":[["f7bcc557.084338","3e04700a.c1fb9"]]},{"id":"f68d624d.0972a","type":"mqtt out","name":"Lights MQTT","topic":"","qos":"","retain":"","broker":"a1e6a9c6.5e1958","x":697,"y":222,"z":"77df6b64.882094","wires":[]},{"id":"94e11e5b.6b1ee","type":"http request","name":"Mopidy JsonRPC","method":"POST","url":"
http://localhost:6680/mopidy/rpc","x":756.75,"y":342.50000190734863,"z":"77df6b64.882094","wires":[[]]},{"id":"f7bcc557.084338","type":"function","name":"Sunrise Alarm Control","func":"var lightMsg = [];\nvar audioMsg = [];\nswitch (msg.payload) {\n\tcase \"setup\":\n\t\tcontext.stopped = 1;\n\t\tlightMsg = [{topic:\"lights/1/whitemode\", payload:\"yes\"},{topic:\"lights/1/brightness\", payload:30},{topic:\"lights/1/hue\", payload:174},{topic:\"lights/1/brightness\", payload:1},{topic:\"lights/0/power\", payload:\"off\"}];\n\t\taudioMsg = {payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.playback.stop\"}};\t\n\t\tmsg = null;\n\t\tbreak;\n\tcase \"start\":\n\t\t//initialize loop, switch on the lights at minimum brightness and start classical music from spotify, but muted\n\t\tcontext.stopped = 0;\n\t\tmsg.payload = 1;\n\t\tlightMsg = [{topic:\"lights/1/hue\", payload:174},{topic:\"lights/1/brightness\", payload:1}];\n\t\taudioMsg = [{payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.tracklist.clear\"}},\n\t\t\t\t\t{payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.tracklist.add\",\"params\":{\"uri\":\"spotify:user:spotify:playlist:63dDpdoVHvx5RkK87g4LKk\"}}},\n\t\t\t\t\t{payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.tracklist.shuffle\"}},\n\t\t\t\t\t{payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.playback.set_volume\",\"params\":[0]}},\n\t\t\t\t\t{payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"
core.playback.play\"}}];\n\t\tbreak;\n\tcase \"stop\":\n\t\t//switch off the light and stops the music\n\t\tcontext.stopped = 1;\n\t\tmsg = null;\n\t\tlightMsg = {topic:\"lights/1/power\", payload:\"off\"};\n\t\taudioMsg = {payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.playback.stop\"}};\n\t\tbreak;\n\t//case 101:\n\tcase 80:\n\t\t//natural end of the loop\n\t\tmsg = null;\n\t\tbreak;\n\tdefault:\n\t\tif (context.stopped == 0) {\n\t\t\tif (msg.payload < 48) {\n\t\t\t\t//from dim red to bright yellow\n\t\t\t\tlightMsg = [{topic:\"lights/1/hue\", payload:(175-msg.payload)},{topic:\"lights/1/brightness\", payload:(Math.ceil(1+(msg.payload-1)*99/46))}];\n\t\t\t} else if (msg.payload == 48) {\n\t\t\t\t//switch to white, 30% of brightness\n\t\t\t\tlightMsg = [{topic:\"lights/1/whitemode\", payload:\"yes\"},{topic:\"lights/1/brightness\", payload:30}];\n\t\t\t} else {\n\t\t\t\t//increase white brightness\n\t\t\t\tlightMsg = [{topic:\"lights/1/brightness\", payload:(Math.ceil(30+(msg.payload-48)*70/31))}];\n\t\t\t}\n\t\t\taudioMsg = {payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.playback.set_volume\",\"params\":[Math.ceil(1+(msg.payload-1)*72/76)]}};\n\t\t\tmsg.payload ++;\n\t\t\t//set the right brightness and volume based on the payload value and increments it\n\t\t\t//lightMsg = {topic:\"lights/1/brightness\", payload:msg.payload};\n\t\t\t//audioMsg = {payload:{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"core.playback.set_volume\",\"params\":[Math.ceil(1+(msg.payload-1)*72/99)]}};\n\t\t\t//msg.payload ++;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmsg = null;\n\t\t}\n\t\tbreak;\n}\nreturn [ msg , lightMsg, audioMsg ];","outputs":"3","x":361.75,"y":313.75000190734863,"z":"77df6b64.882094","wires":[["18ea3251.e715ce"],["f68d624d.0972a"],["57f68bf0.a80974"]]},{"id":"18ea3251.e715ce","type":"delay","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":355.75,"y":257.75,"z":"77df6b64.882094","wires":[["f7bcc557.084338"]]},{"id":"57f68bf0.a80974","type":"delay","name":"","pauseType":"rate","timeout":"3","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":580.5,"y":342.50000190734863,"z":"77df6b64.882094","wires":[["94e11e5b.6b1ee"]]}]