Switch off all lights and devices accept x

I need advice how to solve it :wink: I have quit a lot devices and lights to switch.
I have automation when I leave the home all devices and lights are switching off right now all devices added manually switch.1, light.2 , switch.3 etc.
I can add switch - group.all_switches and group.all_lights then I don’t have add all manually - especially when adding a new device then I must remember to change automations as well.
My question is - can I use switch off groups, but I don’t want to switch off one ore two lights ( light.entrance and switch.decor)
Can I do new group switch2 or how I can ignore or write out from lights/ switches so that they are in a separate group ?

And second question ?

I added one switch before my TV, receiver, SAT box - which turns off all devices, that they should not be in standby mode but completely OFF
then the HA gonna missing those devices ( Update for media_player.yamaha_receiver fails ) touring I not in home It’s OK for HA or better leave the devices on standby mode ?

1 Like

There are 2 ways that come to mind to achieve this, which is best/easiest will depend on your config.

1 - create a group for the things you want to switch off, excluding the things you want to leave on, and switch off that group in your ‘leaving home’ automation.

2 - create a group for the things you want to leave on, and in your ‘leaving home’ automation switch everything off, and then your new group back on.

Here’s a thread where we discuss an almost identical situation:
https://community.home-assistant.io/t/my-template-fails-as-ha-does-not-recognize-difference-from-jinja2-filters

You can build an array of all your lights, then remove the ones you don’t want to turn off.
The only downside to this is that at the time of testing home_assistant.turn_off did not work, so you will have to group the entities by their type. So, you would have one set of code for ligths, one set for switches etc…
Here is the code that worked in that case:

- alias: listtest
  trigger:
    - platform: state
      entity_id: input_boolean.attic_fan
      from: 'off'
      to: 'on'

  action:
    - service: switch.turn_on        
      data_template: 
        entity_id: >
         {% set list = ['switch.office1', 'switch.sun', 'switch.office2']%}
         {% set ignore = ['switch.office2'] %}
         {%-for l in list if (l not in ignore) -%}
           {{l}}{% if not loop.last %}{{ ", " }}{% endif %}
         {%-endfor-%}

Of course, in your case, you would want to build the list from scratch with a for loop, something like this:

{%set ignorelist = ['switch.zone1']%}
{% for state in states-%}
{%-if state.entity_id.startswith("switch") and state.entity_id not in ignorelist -%}
{{state.entity_id}}  {% if not loop.last %}{{ ", "}}{% endif %}
{%-endif-%}
{%endfor%}
1 Like

second way will not work, because one off lights what I don’t want to turn off or change status is entrance light. But lights’ is working with automation -when sun is below or above horizon then lights on or off but let’s say I leaving home middle of the ray then all lights are switching off and then switch the entrance light back on, and that’s not OK :wink:

But yes seems to some groups is easier and more sensible - then I can use in automation specific group and when I add new device ( light or switch ) then I must just add it to this group as well. Not having to go through all my automation’s and add the the new device where necessary