Turning off every light in the house. Only send off command to lights that are on, or send off command tov every light?

I have 27 smart switches.
Want to create a node red flow to turn off EVERY switch

Would it be better to add a currentstate node and then only if the light is on, send the off command (#1) Or just send the off command to every light (#2)?

I’m looking to get it done as efficently and quickly as possible. The amount of time it takes to create the flow (ie, adding a current_state node for every light) doesnt bother me, if its the preferred way.

1 Like

Use the get entities node, https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/get-entities.html
It works with Alexa notifications and announcements as well.

[{"id":"7e5db4f1.7fa31c","type":"trigger-state","z":"f2d34151.9da47","name":"Left Home","server":"8883c5ea.5f6948","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"person.mike","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"home","propertyValue":"new_state.state"},{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"not_home","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":110,"y":200,"wires":[["d14c40bb.b49a4"],[]]},{"id":"d14c40bb.b49a4","type":"ha-get-entities","z":"f2d34151.9da47","server":"8883c5ea.5f6948","name":"","rules":[{"property":"entity_id","logic":"includes","value":"binary_sensor.master_bath_door_o_c_2_2,binary_sensor.coltens_office_to_lobby_2,binary_sensor.repair_employee_bathroom_door","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":290,"y":200,"wires":[["363d2533.22d05a"]]},{"id":"363d2533.22d05a","type":"template","z":"f2d34151.9da47","name":"Format Friendly Name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":480,"y":200,"wires":[["f2edc82b.46ce58"]]},{"id":"f2edc82b.46ce58","type":"join","z":"f2d34151.9da47","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":200,"wires":[["91251c2b.1259a"]]},{"id":"525c3c64.78a6a4","type":"comment","z":"f2d34151.9da47","name":"get a notification from alexa when you leave if any doors or windows are left open.","info":"You have a presence detection of some sort running in Home Assistant and you want to get a notification when you leave if any doors or windows are left open.\n\nUsing the get entities node here to get a possible list of entity ids [binary_sensor.front_door, binary_sensor.back_door, binary_sensor.front_window, binary_sensor.back_window] if their state is equal to open. The entities are returned with the output Split. This means that a message is sent for each valid entity. We then are using a template node to format the payload into the entity friendly name and joining them back into one payload using the join node.","x":420,"y":140,"wires":[]},{"id":"91251c2b.1259a","type":"api-call-service","z":"f2d34151.9da47","name":"Alexa Speak -New TTS- not Announce - No Bell","server":"8883c5ea.5f6948","version":1,"debugenabled":false,"service_domain":"notify","service":"alexa_media_front_room","entityId":"","data":"{\"message\":\"The. .  {{payload}} . . are open.\",\"title\":\"Left Open\",\"data\":{\"type\":\"tts\",\"method\":\"all\"},\"target\":[\"media_player.front_room\"]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":940,"y":220,"wires":[[]]},{"id":"8883c5ea.5f6948","type":"server","name":"HA Main","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

@msauto

So I took that flow and I have it working, as in, it see’s which lights are on. But how do I take that information and have it then turn those lights off?

@nappyjim Here ya go

[{"id":"2436f4ef.69311c","type":"comment","z":"f2d34151.9da47","name":"power off all lights which are on ","info":"","x":450,"y":1340,"wires":[]},{"id":"2d9d9aa.d38b966","type":"api-call-service","z":"f2d34151.9da47","name":"Turn Them Off","server":"8883c5ea.5f6948","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"{{payload.entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":700,"y":1380,"wires":[[]]},{"id":"f35d4fab.7185e","type":"ha-get-entities","z":"f2d34151.9da47","server":"8883c5ea.5f6948","name":"Get Lights That are On","rules":[{"property":"entity_id","logic":"starts_with","value":"light","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":480,"y":1380,"wires":[["2d9d9aa.d38b966"]]},{"id":"640dbb2b.ae9de4","type":"inject","z":"f2d34151.9da47","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":1380,"wires":[["f35d4fab.7185e"]]},{"id":"8883c5ea.5f6948","type":"server","name":"HA Main","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

and a little bonus if you have an amazon echo

[{"id":"d14c40bb.b49a4","type":"ha-get-entities","z":"f2d34151.9da47","server":"8883c5ea.5f6948","name":"","rules":[{"property":"entity_id","logic":"starts_with","value":"light","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":270,"y":200,"wires":[["363d2533.22d05a"]]},{"id":"363d2533.22d05a","type":"template","z":"f2d34151.9da47","name":"Format Friendly Name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.attributes.friendly_name}}","output":"str","x":460,"y":200,"wires":[["f2edc82b.46ce58"]]},{"id":"f2edc82b.46ce58","type":"join","z":"f2d34151.9da47","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":200,"wires":[["c804e3f.f6c512","2a305b.fa1abfa6"]]},{"id":"937c657d.e7c228","type":"inject","z":"f2d34151.9da47","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":260,"wires":[["d14c40bb.b49a4"]]},{"id":"2a305b.fa1abfa6","type":"api-call-service","z":"f2d34151.9da47","name":"Alexa Speak -New TTS- not Announce - No Bell","server":"8883c5ea.5f6948","version":1,"debugenabled":false,"service_domain":"notify","service":"alexa_media_living_room_echo","entityId":"","data":"{\"message\":\"The {{payload}} .are on.\",\"title\":\"Left Open\",\"data\":{\"type\":\"tts\",\"method\":\"all\"},\"target\":[\"media_player.living_room_echo4\"]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":860,"y":240,"wires":[[]]},{"id":"8883c5ea.5f6948","type":"server","name":"HA Main","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]
1 Like

thanks @msauto

Just because Im curious, is the GET ENTITIES node less intensive/less communication on Zwave then if I were to do a CURRENT STATE for every light?/

@nappyjim

If using “get entities” then you only need what i sent you times 2 , one for ON and one for OFF (turn lights ON and turn lights OFF)

If you use a current state node then you will need one for each light which would be 27 current state nodes vs 2 get entity nodes unless i misunderstood your question.

If i understand correctly , you have 27 lights that could be ON or OFF at any given time and, for example, when you go to the grocery store you only want to turn OFF the lights that are ON then when you return home you want to turn those same exact lights back ON with one switch or call. Right?

So the only thing you need is what i sent times 2 then change the state property in the get entities node in one of them to OFF and change the service field on the call service node to ON. Then connect whatever you want to control with in place of the inject nodes.

So to answer your question, that is both less intensive and less communication.

Hope this helps.
Oh , and your welcome.

You understood my issues correctly, Im just trying to understand Z WAVE protocol so more and figure out what best practice is so that moving forward, I can accomplish things without flooding my z wave network with unnecessary messages.

@nappyjim
Ok, I do not know much about zwave (most of my stuff is wifi or insteon) but no matter what the protocol is, less typing (or copy pasting in my case) always equates to less communication and less comunication equates to less signal flooding as well as less points of failure to have to track down and fix when they break.
Good Luck in your Zwave adventures.

How do you like insteon? The hidden in door sensor looks neat. How is the range? How does it talk to HA?

@nappyjim
I started out 10 years ago with x10 so when i got ready to upgrade insteon was the natural choice because it would control any x10 devices that i kept (still have a few) but it didn’t take long to get tired of insteon. The protocol was and still is not very popular with software devs and automation tinkerers/devs (insteon was not supported very well in ha and still is very limited ) and the prices are crazy on most of there stuff. Don’t get me wrong for someone that wants a dependable set it and forget it system that is only capable of what it came out of the box to do, Insteon is what you want. Once set up (if you have an old house be ready for hell-insteon hates any kind of powerline noise) its pretty darn dependable as long as you don’t try to change anything or really automate anything. The range on all insteon rf only devises SUCKS , i have the hidden door sensor 20 ft line of site from my door and it works 50% of the time and then it is slow to respond (i really dont use it anymore i use wyzesense door sensor and range is unbelievable). From what i understand Zwave is a much better protocol than insteon and way more modifiable as well as cheaper but honestly i prefer wifi because its everywhere on my property so i don’t have to worry about range.
As far as talking to ha , its much better now due to a serious makover by the insteon integration devs and as long as everythings talking ha will get along fine but device info is limited.
All in All, i cant say that i would ever recommend insteon on a large system at all or for anyone that wants to integrate with ha(if your using ha that means your a tinkerer and insteon don’t tinker)
I automate both my 7000 sqft business and 3000 sqft home with lighting,door locks,automated entry,and presence detection as well as full integration with 14 hd security cameras all controlled by 4 instances of ha running on 3 laptops as servers and one vm running inside hyper-v on a dell r720 server as well as 3 instances of Monitor bluetooth presence tracking scattered across the laptops and 13 Echo devices allowing voice control of most all systems. So i am definitely a tinkerer,lol
Sorry for the long winded answer , started typing and forgot to stop.
Oh yea, there app sucks too. In 10 years they upgraded there app 1 time and that was last year.

1 Like