Only send "Switch.Turn_Off command to devices that are on


I am using a VeraEdge device for all my lights/switches/covers.
when I am going away or to bed, I would like to turn off all the devices that are on.

For all the devices I have connected to my Vera, I can send a Turn_Off command.
The problem with the VeraEdge is that if you send a lot of commands all in one time the device kinda locks up and becomes slow for a certain period.

Thus I would like to send only commands to the Vera when devices are on.

Please assist.


This code should work…

 - service: light.turn_off
        entity_id: >- 
          {{ states.light | selectattr('state','eq','on') | map(attribute='entity_id') | join(',') }}
1 Like

hi jwelter,

do I understand correct that this code will check all my lights for its status and turn off is needed?


Correct, any light that is on will be turned off.

You can change the states.light to states.switch to do the same for switches.

sweet! thanks!

would the same be possible for media players?

It should work; I’ve not used it for media players – only switches and lights. you could test it the template editor.

how can I filter only real socket switches, I also have docker switches. I dont want to close them.

All my socket switches starts with swiches.stp_xxxx or lights switch.light_xxxx and my dockers with switch.docker_xxxxx