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

Thoughts on conditions?

condition: state
entity_id: group.all_lights
state: 'off' 

Becomes what?

I use that one in combination with a time condition to work out when everyone who is home has gone to bed. I’ve had to resort to listing all the lights for now but it’s a bit messy.

A hot mess.

condition: template
value_template: >
  {{ states.light | count == states.light | selectattr('state','eq','off') | list | count }}
3 Likes

It’s a truck load prettier than what I typed out earlier! Cheers :sunglasses:

Yeah, nobody turns off all_lights anyways, right? :crazy_face:

hello, does anyone know how to replace the group.all_devices as trigger and condition in an automation?

  trigger:
  - entity_id: group.all_devices
    platform: state
    to: not_home


  - condition: state
    entity_id: group.all_devices
    state: home

The trigger is tricky.

Probably the easiest without listing all the devices:

trigger:
- platform: event
  event_type: state_changed
condition:
- condition: template
  value_template: "{{ trigger.event.entity_id.split('.')[0] == 'device_tracker' }}"

The condition is also tricky, but easier

- condition: template
  value_template: "{{ states.device_tracker | count == states.device_tracker | selectattr('state','eq','home') | list | count }}"
1 Like

thanks a lot,ill try it and change all them

the problem is that with group.all_devices when one of the device_tracker entities has the value “home”, the status of the group also changes to “home”, the condition does not work, the trigger has not yet been able to test it.
thanks

Ah ok, use this

- condition: template
  value_template: "{{ states.device_tracker | selectattr('state','eq','home') | list | count > 0 }}"

Hey Google… turn off all the lights…

5 Likes

TOP,thanks a lot again,thats its working,
I just need to try the trigger

Maybe is a silly question, but if I create a group with all device_tracker I have, wouldn’t it work just like the old group.all_devices?
EDIT: thats working,i think is the best fix for me
:grinning:

I though I understood how piping worked in Home Assistant but the use of the piping here really confuses me. Anybody cares to explain to me what’s going on?

The way I see it, states[domain] returns a list of states the entities of type domains are and piping that to count will result in the number of devices returned. So what piping that number to an equality test with the list again do?

Bit disappointed with this update.

How can I now easily check if all door are locked. Now i need to maintain the group myself. A pitty they did not foresee an option to make the groups available again.

I have a Node-red flow to turn off ALL lights except a few (using a function node), guess I know have to iterate over all the entities …

1 Like

No you don’t. I posted a solution here:

Change domain to ‘lock’ and state to ‘locked’.

- condition: template
  value_template: >
    {% set domain = 'lock' %}
    {% set state = 'locked' %}
    {{ states[domain] | count == states[domain] | selectattr('state','eq', state) | list | count }}
2 Likes

Again, no you don’t. Node red calls a service. Instead of using entity_id: ‘group.all_lights’, use entity_id: ‘all’.

I get that, but previously I iterated over the entities in the group. Using all only works when trying to turn off the lights, not for getting the list of entities.

Luckily I’ve put all that code in a subflow, so it’s a change on 1 place, but still. This change kinda sucks.

dude, i posted that solution as well…

Use this as a list of entity_id’s to return to entity_id’s

{{ states.switch | map(attribute='entity_id') | list | join(', ') }}

Use this to find all items in a domain

{{ states.switch | map(attribute='entity_id') | list }}

EDIT: In the words of southpark “Rabble rabble rabble rabble”

What about some tiny python_script to get your group.all_* back?

automation:
  - alias: HA Start automation
    trigger:
      platform: homeassistant
      event: start
    action:
      - service: python_script.create_all_group
        data:
          domain: light
          group: all_lights

python_scripts/create_all_group.py

domain = data.get('domain')
group = data.get('group')

service_data = {"object_id": group, "entities": hass.states.entity_ids(domain)}
hass.services.call("group", "set", service_data, False)

I have no clue if this is safe, but it works for me. :sunglasses: It is!

EDIT: optimized create_all_group.py

5 Likes

Nice list @petro, thanks for compiling.

adding my bit: just discovered we can also expand the domain, as an alternative:

count

{% set lights = expand(states.light)
|selectattr('state','eq','off')|list|count %}
{{lights}}

list:

{% set lights = expand(states.light)
|selectattr('state','eq','off')|map(attribute='name')|list %}
{{lights}}
1 Like