PSA: Turn on/off all lights in Home Assistant 0.104+ (group.all_* changes)

Yup, tried that too, check a couple of posts above.
So the fastest we can get is every minute by sensor.time, no option to get it to update more frequently right?

You’ll need to add a list of all binary_sensors that you wish to monitor (i.e. motion sensors) to the Template Sensor’s entity_id. The moment any of them changes state will cause the Template Sensor’s value_template to be evaluated.

That’s exactly what i was trying to avoid, or avoid having to create a group of all binary sensors.
I used auto-entities to display them on my ui, but was trying to use them as a single entity indicated somehow.
That’s how i ended up here :slight_smile:

Anyway, good thing is that they can still work as condition to automations right?
I mean the automation will have to check if the condition is met when firing… which is the most important i guess.

Yes, check in the first post, it shows how to use it in conditions.

The only thing I’m missing is the option to display them in a single entity, which is not that important.

Thanx for all the input guys.

OK. If you want to update the Template Sensor more frequently than every minute, create an automation, triggered by Time Pattern (using whatever short interval you require), that runs the homeassistant.update_entity service (to refresh the Template Sensor).

Wow that’s clever!
Thank you.

Would that put a significant load to the machine or is it acceptable / minimal?

create_every_device_group:
    sequence:
      - service: group.set
        data_template:
          object_id: "all_devices"
          entities: >
            {{ states.device_tracker |  map(attribute='entity_id') | join(',') }}
create_every_light_group:
    sequence:
      - service: group.set
        data_template:
          object_id: "all_lights"
          entities: >
            {{ states.light |  map(attribute='entity_id') | join(',') }}

adding this worked great alongside running these two scripts at startup

thanks to brianhanifin

1 Like

In a badge, for an Entity Button Card,

entity: all
hold_action:
  action: none
name: Close all lights
show_icon: false
show_name: true
tap_action:
  action: call-service
  service: light.turn_off
  service_data:
    entity_id: group.all_lights
type: entity-button

Doesn’t work. I get

Invalid Entity

entity: all
1 Like

Do you have an automation running them on every startup?
Also could there be a way to select only the entity_id’s of the items that have a specific attribute? (like device_clase:motion)

Nevermind, here is how i did it: Create groups with the device_class i want, automation to set them up on startup and a binary sensor to show them to me as safety

script:
  create_group_all_motion_sensors:
      sequence:
        - service: group.set
          data_template:
            object_id: "all_sensors_motion"
            entities: >
              {{ states.binary_sensor | selectattr('attributes.device_class','eq','motion') | map(attribute='entity_id') |  join(', ') }}
  
  create_group_all_opening_sensors:
      sequence:
        - service: group.set
          data_template:
            object_id: "all_sensors_opening"
            entities: >
              {{ states.binary_sensor | selectattr('attributes.device_class','eq','opening') | map(attribute='entity_id') | join(', ') }}

automation:
- alias: Startup Stuff - Notifications
    id: cea3ed9689054b0dasdadadsasdw
    trigger:
    - event: start
      platform: homeassistant
    action:
    - data:
        message: HomeAssistant is up
      service: telegram_bot.send_message
#......
    - alias: Create All Groups
      entity_id: script.create_group_all_motion_sensors, script.create_group_all_opening_sensors
      service: script.turn_on

binary_sensor:
#...
  - platform: template
    sensors:
#....
      all_motion_sensors_off:
        friendly_name: "No Motion"
        value_template: "{{ is_state('group.all_sensors_motion', 'on') }}"
        device_class: safety
        
      all_doors_closed:
        friendly_name: "All Doors Closed"
        value_template: "{{ is_state('group.all_sensors_opening', 'on') }}"
        device_class: safety
#had to class them as safety in order to exclude them from the previous group

When at least one motion detector is on:
image

Thanks for all the input guys :slight_smile:

1 Like

Using this in a script:

    - service: light.turn_off
      entity_id:
        - all

Gives me this error:

Invalid config for [script]: not a valid value for dictionary value @ data['script']['all_lights_off']['sequence'][1]['entity_id']. Got ['all'].

Any idea?

Adjusted to this, fixed it:

    - service: light.turn_off
      entity_id: all

A little bit of an aside from group.all_*: My code checked for each explicit person to create a binary_sensor.anyone_home, which is a little easier to utilize elsewhere in triggers and conditions. I’ll probably update to your condition template approach but wanted to mention the binary_sensor in case its useful to others.

binary_sensor.yaml file

- platform: template
  sensors:
    anyone_home:
      device_class: presence
      friendly_name: 'Anyone Home'
      value_template: "{{ is_state('person.one', 'home') or is_state('person.two', 'home') }}"

Uses:

 trigger:
    platform: state
    entity_id: binary_sensor.anyone_home
    to: 'on'
 - condition: template
   value_template: "{{ is_state('binary_sensor.anyone_home', 'on') }}"

I tried many combinations but nothing works :frowning: What can I use in Lovelace to replace an entity called group.all_lights in an Entity Button Card? The reason for this is to have a single button in the UI to turn off all the lights at once.

1 Like

My question exactly! It is sad the group.all_* was thrown away as it was very simple, yet totally adequate tool for an amateur like myself. :worried:

1 Like

Just use a script as the entity. Are you trying to gain ‘on’ and ‘off’ functionality? If so, you can make a toggle script.

script:
  all_lights:
    sequence:
      service_template: >
        {% set domain = 'light' %}
        {% set state = 'on' %}
        {% set is_on = states[domain] | selectattr('state','eq', state) | list | count > 0 %}
        {{ domain }}.turn_{{ 'off' if is_on else 'on' }}
      data_template:
        entity_id: >
          {% set domain = 'light' %}
          {% set state = 'on' %}
          {% set is_on = states[domain] | selectattr('state','eq', state) | list | count > 0 %}
          {% set state = 'off' if is_on else 'on' %}
          {{ states[domain] | selectattr('state','eq',state) | map(attribute='entity_id') | list | join(', ') }}
1 Like

Here is the explanation for it.

Thanks, that did the trick :slight_smile:

Here’s what my Lovelace code looks like:

entity: script.all_lights
hold_action:
  action: none
name: Fermer les lumières
show_icon: false
show_name: true
tap_action:
  action: call-service
  service: light.turn_off
  service_data:
    entity_id: all
type: entity-button
theme: slate
1 Like

My node red automation was based upon the status of device tracker's all devices group. Specifically two mobile phones who's combined bluetooth proximity status set the group to home or not_home. This turned my security cameras on and off. It all worked beautifully. Sadly, most of the fixes mentioned in this thread are way over my head. Please can a kind soul help this non-programmer layman?

You only need to create that group manually
Info how:

see my post above

create_every_device_group:
    sequence:
      - service: group.set
        data_template:
          object_id: "all_devices"
          entities: >
            {{ states.device_tracker |  map(attribute='entity_id') | join(',') }}
create_every_light_group:
    sequence:
      - service: group.set
        data_template:
          object_id: "all_lights"
          entities: >
            {{ states.light |  map(attribute='entity_id') | join(',') }}