Turning on a light early if its cloudy

Hello everyone, I am new to Home Assistant & Node-Red. I am playing around with an automation to turn my bulb on early if it is overcast, raining or snowing. I was wondering if any of you would be able to evaluate my simple flow to let me know if you think that this will work?

[{"id":"3e2bdc26.d4977c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3af28997.d3b346","type":"bigtimer","z":"3e2bdc26.d4977c","outtopic":"","outpayload1":"","outpayload2":"","name":"Big Timer","comment":"","lat":0,"lon":0,"starttime":"5004","endtime":"5000","starttime2":0,"endtime2":0,"startoff":"-45","endoff":"-10","startoff2":0,"endoff2":0,"offs":0,"outtext1":"","outtext2":"","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"day7":0,"month7":0,"day8":0,"month8":0,"day9":0,"month9":0,"day10":0,"month10":0,"day11":0,"month11":0,"day12":0,"month12":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xday7":0,"xmonth7":0,"xday8":0,"xmonth8":0,"xday9":0,"xmonth9":0,"xday10":0,"xmonth10":0,"xday11":0,"xmonth11":0,"xday12":0,"xmonth12":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"randon1":false,"randoff1":false,"randon2":false,"randoff2":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":500,"y":120,"wires":[["f1044ed7.a30d48"],[],[]]},{"id":"532fe589.009294","type":"poll-state","z":"3e2bdc26.d4977c","name":"","server":"7a554823.e94b48","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"weather.home","state_type":"str","halt_if":"cloudy, rainy, snowy","halt_if_type":"str","halt_if_compare":"is","outputs":2,"x":170,"y":140,"wires":[["3af28997.d3b346"],[]]},{"id":"3af1544b.ba03dc","type":"server-state-changed","z":"3e2bdc26.d4977c","name":"","server":"7a554823.e94b48","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sun.sun","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"below_horizon","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":170,"y":200,"wires":[["f1044ed7.a30d48"],[]]},{"id":"f1044ed7.a30d48","type":"api-call-service","z":"3e2bdc26.d4977c","name":"","server":"7a554823.e94b48","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.living_room_light_lamp_2","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":830,"y":160,"wires":[[]]},{"id":"7a554823.e94b48","type":"server","name":"Home Assistant","addon":true}]e

I’d do this.

Instead of polling the weather state every minute and having another event state node for the sun, I’d group weather.home and sun.sun whithin the same event state node. I left the state blank so if any of those two triggers update their state, the flow will trigger anyways. Setting “substring” instead of “exact” allows you to set a comma separated string of entities.

Now, since your flow triggers every time any of those two triggers update, use current state nodes to filter your actions.

If it’s below horizon, always turn on. If it’s above horizon, only turn on if it’s cloudy, rainy or snowy. Note that I set “in” instead of “is”. Much like the “substring”, it allows to set a comma separated string of states.

[{"id":"8b213254.19585","type":"server-state-changed","z":"3425db79.2f7dd4","name":"Triggers","server":"9405c3fe.d0a6c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sun.sun, weather.home","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":120,"y":380,"wires":[["1a244ff4.1414e"]]},{"id":"1a244ff4.1414e","type":"api-current-state","z":"3425db79.2f7dd4","name":"above horizon?","server":"9405c3fe.d0a6c","version":1,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sun.sun","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":true,"x":300,"y":380,"wires":[["6b77a141.a8f04"],["c8505c3a.4d6b1"]]},{"id":"6b77a141.a8f04","type":"api-current-state","z":"3425db79.2f7dd4","name":"cloudy, rainy or snowy ?","server":"9405c3fe.d0a6c","version":1,"outputs":2,"halt_if":"cloudy, rainy, snowy","halt_if_type":"str","halt_if_compare":"includes","override_topic":false,"entity_id":"weather.home","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":true,"x":550,"y":340,"wires":[["c8505c3a.4d6b1"],[]]},{"id":"c8505c3a.4d6b1","type":"api-call-service","z":"3425db79.2f7dd4","name":"","server":"7a554823.e94b48","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.living_room_light_lamp_2","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":790,"y":400,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true},{"id":"7a554823.e94b48","type":"server","name":"Home Assistant","addon":true}]
1 Like

Hi obaldius, Thanks for the suggestions. I am still struggling with some of your suggestions as I believe that you only sent the “Get current weather” node in your previous reply? My first question is what would you use as a trigger? I have attached the code for the updated flow that I have made so far. Thanks again for your help.

[{"id":"d674ce4c.57d4c","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"e1a1dbaf.d137c8","type":"api-current-state","z":"d674ce4c.57d4c","name":"Get current weather","server":"9405c3fe.d0a6c","version":2,"outputs":2,"halt_if":"sunny.clear-night,windy,exceptional ","halt_if_type":"str","halt_if_compare":"includes","entity_id":"weather.home","state_type":"str","blockInputOverrides":true,"outputProperties":[],"x":520,"y":120,"wires":[["e879f361.534e58"],[]]},{"id":"e08d0a1e.b31228","type":"api-current-state","z":"d674ce4c.57d4c","name":"Sun Above Horizon","server":"7a554823.e94b48","version":2,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":190,"y":240,"wires":[["e1a1dbaf.d137c8"],["e879f361.534e58"]]},{"id":"e879f361.534e58","type":"api-call-service","z":"d674ce4c.57d4c","name":"","server":"7a554823.e94b48","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.test_tp_link_switch","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":240,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"7a554823.e94b48","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

No problem, I’m glad to help. I’m sorry, my mistake, I updated the flow in the previous post. Ask if you don’t understand anything.

EDIT

I would use both as triggers

1 Like

You could use a sun event eg sunset to turn the lights on. You can use another that will send a signal 45 minutes before sunset. Then use a get state, if it’s cloudy it will let the message pass.

[{"id":"14a8a555.6fbcc3","type":"sunrise","z":"d6a46901.ebee1","name":"Sunset start","lat":"","lon":"","start":"sunrise","end":"sunsetStart","soff":0,"eoff":0,"x":270,"y":2820,"wires":[[],["8936af05.66be98"]]},{"id":"da453d76.075aa8","type":"sunrise","z":"d6a46901.ebee1","name":"45 min before start of sunset","lat":"","lon":"","start":"sunrise","end":"sunsetStart","soff":0,"eoff":"-45","x":220,"y":2920,"wires":[[],["605311f5.152e78"]]},{"id":"4af7dec2.ec1ce8","type":"api-call-service","z":"d6a46901.ebee1","name":"light on","server":"6b1110b5.183a4","version":3,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":800,"y":2820,"wires":[[]]},{"id":"8936af05.66be98","type":"switch","z":"d6a46901.ebee1","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":2820,"wires":[[],["4af7dec2.ec1ce8"]],"outputLabels":["day","night"]},{"id":"605311f5.152e78","type":"switch","z":"d6a46901.ebee1","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":2920,"wires":[[],["9f014e48.cb6b1"]],"outputLabels":["day","night"]},{"id":"9f014e48.cb6b1","type":"api-current-state","z":"d6a46901.ebee1","name":"is it cloudy","server":"6b1110b5.183a4","version":2,"outputs":2,"halt_if":"cloudy, overcast","halt_if_type":"str","halt_if_compare":"is","entity_id":"","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":590,"y":2920,"wires":[["4af7dec2.ec1ce8"],[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

1 Like

Hi Mikefila,

Thanks for taking the time to look into this. Ill give it a try now. I really appreciate your help!

Hi obaldius, Thanks for pointing me in the right direction.

1 Like

Thanks for the idea. I’m running a similar routine and just replaced a few nodes with one based on your code.

2 Likes