Light automation problem - Node Red, sun.sun offset and Darksky cloud_coverage

I’m trying to create an automation (flow) that turns on lights, based on the Darksky cloud coverage. It’s driving me crazy. It seems like the sun.sun offset doesn’t do anything. I’ve tried using EZTimer, Schedex, Trigger components and came accross this topic, but none of this works. The lights are turning on randomly during the day, nowhere near the offset of sun.sun.

This is what I’m trying to accomplish in Node red:

  1. If Darksky cloud_coverage >=51%, turn on lights based on sun.sun, with -00:45:00 offset.
  2. If Darksky cloud_coverage <=50% - >=6%, turn on lights based on sun.sun, with -00:25:00 offset.
  3. If Darksky cloud_coverage <=5%, turn on lights based on sun.sun, without offset.
[{"id":"a3458f3b.d28da","type":"comment","z":"393a4b6.bdd58b4","name":"Lights on when sunset starts","info":"","x":140,"y":380,"wires":[]},{"id":"e8f0ed2e.d7b0e","type":"api-call-service","z":"393a4b6.bdd58b4","name":"","server":"18501424.c3841c","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.woonkamer_fade_avond","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":970,"y":466,"wires":[["78fea67a.51ab08","c5056a89.c922c"]]},{"id":"78fea67a.51ab08","type":"debug","z":"393a4b6.bdd58b4","name":"test_scene","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1270,"y":402,"wires":[]},{"id":"8f43eebd.ded228","type":"api-call-service","z":"393a4b6.bdd58b4","name":"","server":"18501424.c3841c","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.eetkamer_fade_avond","data":"{\"transition\":600}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1290,"y":525,"wires":[["5a3a31ad.8dbb8"]]},{"id":"5a3a31ad.8dbb8","type":"debug","z":"393a4b6.bdd58b4","name":"test_eetkamer_scene","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1540,"y":525,"wires":[]},{"id":"c5056a89.c922c","type":"delay","z":"393a4b6.bdd58b4","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1192,"y":466,"wires":[["8f43eebd.ded228"]]},{"id":"361ce879.df2058","type":"api-current-state","z":"393a4b6.bdd58b4","name":"Light already on?","server":"18501424.c3841c","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.woonkamer","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":807,"y":400,"wires":[[],["e8f0ed2e.d7b0e"]]},{"id":"628da254.9b1b1c","type":"debug","z":"393a4b6.bdd58b4","name":"Output darksky","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":525,"wires":[]},{"id":"c3c4c98e.6a4808","type":"trigger-state","z":"393a4b6.bdd58b4","name":">=51% clouds","server":"18501424.c3841c","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.weather_cloud_coverage_0h","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"b4zotzj7e79","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":">=","comparatorValueDatatype":"num","comparatorValue":"51"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"num","x":560,"y":433,"wires":[["361ce879.df2058","628da254.9b1b1c"],["628da254.9b1b1c"]]},{"id":"7ad183ad.e21d4c","type":"trigger-state","z":"393a4b6.bdd58b4","name":"6-50% clouds","server":"18501424.c3841c","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.weather_cloud_coverage_0h","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"2ysmra2nkfb","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"<=","comparatorValueDatatype":"num","comparatorValue":"50"},{"id":"k30q5g5m2ho","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":">=","comparatorValueDatatype":"num","comparatorValue":"6"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"num","x":560,"y":480,"wires":[["361ce879.df2058","628da254.9b1b1c"],["628da254.9b1b1c"]]},{"id":"f1edafa.c42e55","type":"trigger-state","z":"393a4b6.bdd58b4","name":"<=5% clouds","server":"18501424.c3841c","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.weather_cloud_coverage_0h","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"doalh4e6xes","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"<=","comparatorValueDatatype":"num","comparatorValue":"5"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"num","x":561,"y":526,"wires":[["361ce879.df2058","628da254.9b1b1c"],["628da254.9b1b1c"]]},{"id":"468ddb6d.3cee64","type":"api-current-state","z":"393a4b6.bdd58b4","name":"Someone home?","server":"18501424.c3841c","version":1,"outputs":2,"halt_if":"1","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"sensor.people_home","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":350,"y":432,"wires":[["c3c4c98e.6a4808"],[]]},{"id":"b8875f0d.092c2","type":"api-current-state","z":"393a4b6.bdd58b4","name":"Someone home?","server":"18501424.c3841c","version":1,"outputs":2,"halt_if":"1","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"sensor.people_home","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":350,"y":480,"wires":[["7ad183ad.e21d4c"],[]]},{"id":"5d31e42b.e3150c","type":"api-current-state","z":"393a4b6.bdd58b4","name":"Someone home?","server":"18501424.c3841c","version":1,"outputs":2,"halt_if":"1","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"sensor.people_home","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":350,"y":530,"wires":[["f1edafa.c42e55"],[]]},{"id":"593a82cd.4eb2a4","type":"eztimer","z":"393a4b6.bdd58b4","name":"","debug":false,"autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"53.221192","lon":"5.840184","timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onpropertytype":"msg","onproperty":"payload","onvaluetype":"num","onvalue":"","onoffset":"-45","onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offpropertytype":"msg","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":130,"y":420,"wires":[["468ddb6d.3cee64"]]},{"id":"8d6bff19.81aa6","type":"eztimer","z":"393a4b6.bdd58b4","name":"","debug":false,"autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"53.221192","lon":"5.840184","timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onpropertytype":"msg","onproperty":"payload","onvaluetype":"num","onvalue":"","onoffset":"-25","onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offpropertytype":"msg","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":130,"y":480,"wires":[["b8875f0d.092c2"]]},{"id":"23f0567a.1c6762","type":"eztimer","z":"393a4b6.bdd58b4","name":"","debug":false,"autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"53.221192","lon":"5.840184","timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onpropertytype":"msg","onproperty":"payload","onvaluetype":"num","onvalue":"","onoffset":"","onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offpropertytype":"msg","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":130,"y":540,"wires":[["5d31e42b.e3150c"]]},{"id":"18501424.c3841c","type":"server","z":"","name":"Home Assistant","addon":true}]


Does anyone have a clue what is wrong in my current automation? I’ve tried about eight different set-ups, and sad enough I’m running out of ideas.

Thanks in advance!

The input on the trigger state node is used for enable/disable the node and testing. Doesn’t really work the way you are using it. You would want to use a current-state node.

[{"id":"29dc9199.cf3f7e","type":"api-call-service","z":"1773f17b.19a97f","name":"","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.woonkamer_fade_avond","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":762,"y":240,"wires":[["79e2a01.fff976"]]},{"id":"2ec173cd.a1fe7c","type":"api-call-service","z":"1773f17b.19a97f","name":"","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.eetkamer_fade_avond","data":"{\"transition\":600}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1146,"y":240,"wires":[[]]},{"id":"79e2a01.fff976","type":"delay","z":"1773f17b.19a97f","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":950,"y":240,"wires":[["2ec173cd.a1fe7c"]]},{"id":"55ee721e.bbf4ac","type":"eztimer","z":"1773f17b.19a97f","name":"","autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onproperty":"payload","onvaluetype":"num","onvalue":"","onoffset":"-45","onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":82,"y":192,"wires":[["b1e38c5e.c8816"]]},{"id":"7a816ee4.b4b72","type":"eztimer","z":"1773f17b.19a97f","name":"","autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onproperty":"payload","onvaluetype":"num","onvalue":"","onoffset":"-25","onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":82,"y":240,"wires":[["5ded38ed.c8c0b8"]]},{"id":"e45f9f96.7cc9e","type":"eztimer","z":"1773f17b.19a97f","name":"","autoname":"sunset","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"timerType":"2","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onproperty":"payload","onvaluetype":"num","onvalue":"","onoffset":"","onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"dusk","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"num","offvalue":0,"offoffset":0,"offrandomoffset":0,"offsuppressrepeats":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":82,"y":288,"wires":[["367f5b36.04c3b4"]]},{"id":"b1e38c5e.c8816","type":"api-current-state","z":"1773f17b.19a97f","name":">= 51%","version":1,"outputs":2,"halt_if":"51","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"sensor.weather_cloud_coverage_0h","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":236,"y":192,"wires":[["83e1aa94.f200e8"],[]]},{"id":"1d012092.5d322f","type":"api-current-state","z":"1773f17b.19a97f","name":"<= 50%","version":1,"outputs":2,"halt_if":"50","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.weather_cloud_coverage_0h","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":364,"y":240,"wires":[["83e1aa94.f200e8"],[]]},{"id":"367f5b36.04c3b4","type":"api-current-state","z":"1773f17b.19a97f","name":"<= 5%","version":1,"outputs":2,"halt_if":"5","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.weather_cloud_coverage_0h","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":226,"y":288,"wires":[["83e1aa94.f200e8"],[]]},{"id":"5ded38ed.c8c0b8","type":"api-current-state","z":"1773f17b.19a97f","name":" >= 6%","version":1,"outputs":2,"halt_if":"6","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"sensor.weather_cloud_coverage_0h","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":226,"y":240,"wires":[["1d012092.5d322f"],[]]},{"id":"83e1aa94.f200e8","type":"api-current-state","z":"1773f17b.19a97f","name":"Someone home?","version":1,"outputs":2,"halt_if":"1","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"sensor.people_home","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":554,"y":240,"wires":[["29dc9199.cf3f7e"],[]]}]

Thank you for you answer. I placed a current state-node in front of EZTimer, containing sun.sun. Is that how you ment it? Otherwise I don’t know how to work with a sun.sun offset.

I will try in the morning if it works.

Thank you once again @Kermit. As far as I can tell it seems to work. The lights are not turning on randomly anymore.

offtopic: do you happen to know a good source to learn more about making flows in Node Red? I feel like I always think different of creating a flow, rather than it’s supposed to created.