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

That’s entirely due to how you’ve designed the automation, not how the group is created.

Whether you create the all_trackers group manually (like pollinolas suggested) or dynamically (like gazzaman2k suggested) the end-result is identical: it’s a group containing two device_trackers.

Strange that… How one method worked and the other didn’t… Nonetheless, I have the solution now. Thanks to all for their input.

Go to Developer Tools > States and look at the group generated by the script (group.all_devices). How does it differ from a manually defined group like the one I posted above?

The only factor that could cause different group behavior is the all option. Otherwise, given a group’s default options, whether the group is defined via script or manually, the end-result is the same kind of group behavior.

so I use a picture glance to toggle all my lights. especially off is important.

aspect_ratio: 50%
entity: group.all_lights
hold_action:
  action: none
image: 'https://www.home-assistant.io/images/merchandise/shirt-frontpage.png'
name: Appartement
show_name: true
show_state: true
tap_action:
  action: toggle
type: picture-entity

How do I make this work again? the easy way please. I dont think people should have to make this more complicated just because some $#%^&* decided it was better… (pardon my french as I am slightly agitated of me having to fix a thing that was perfectly fine to begin with… again.)

looking all the options I have above in this topic I can either make a script or start adding all the lights. thats just great…

If I was in your situation, I would use VDRainer’s approach (posted above):

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

It consists of one automation and one python_script. That’s it, that’s all. Easy-peasy.

That one python_script can be used to make a group containing all lights, or all switches, or all locks, or whatever other domain you want. So if in the future you need a group.all_covers you only need to append this to the automation:

      - service: python_script.create_all_group
        data:
          domain: cover
          group: all_covers
1 Like

This project is still in beta, so you can expect more breaking changes along the way to version 1.0

With two changes you can make this work.

  1. Change group.all_lights to a random light entity in your house, in my case light.kitchen worked.
  2. Change tap_action: to
tap_action:
  action: call-service
  service: light.toggle
  service_data:
    entity_id: all

I tested the following code, and it toggled every light in my house. Here is your simplified solution.

- aspect_ratio: 50%
  entity: light.kitchen
  hold_action:
    action: none
  image: 'https://www.home-assistant.io/images/merchandise/shirt-frontpage.png'
  name: Appartement
  show_name: true
  show_state: true
  tap_action:
    action: call-service
    service: light.toggle
    service_data:
      entity_id: all
  type: picture-entity
2 Likes

erm yeah… I have a button by my bed that is the “bedtime” switch. Turns off ALL light and various switches… I was wondering why my lights didn’t go off…

hello @petro I’m struggling in having this old trigger working with your method:

    - platform: state
      entity_id: 'group.all_lights'
      to: 'on'

Do you have any suggestion?
Thanks

Follow VDRainer’s solution and it will automatically generate an updated group.all_lights every time you restart Home Assistant.

1 Like

Thanks @123, in the end I used VDRainer’s solution :slight_smile:

2 Likes

Hi everyone. Sorry for my ineptitude with both Home Assistant and Python, but what would be a quick equivalent of this code?

# add all the switches with "relay" in their name
group_entities = hass.states.get('group.all_switches').attributes['entity_id']
timer_entities = []
for e in group_entities:
	if "relay" in e:
		timer_entities.append(e)

# append light entities
timer_entities.extend(hass.states.get('group.all_lights').attributes['entity_id'])

I was having a check in Node-Red to send me a telegram message with (yes/no replyback) asking if I want to turn off the lights if I’m not home and if any of the lights are on… I was using the the current state of group.all_lights to check if any of the lights was on which doesn’t work now.

I could follow approaches like the one to create groups (via scripts) when HA starts but it is another bespoke workaround configuration… I guess we should aim simplification no? otherwise our configuration files will become each time more complex which will lead to harder maintenance (especially when new releases come with more breaking changes)

Just use one of the example template sensors that counts lights.

True… actually is what I’m using now. Although the flexibility that we have is great and allow for all that I was just wondering if it was really the right move because we are just creating more dependencies on the config which with time will make it harder to mantain.
In other end I also kind of understand we can’t support in core all possible features.

Im trying to use this code but I get nothing back, has something changed since this was posted?

{% set domain = 'light' %}
{% set state = 'on' %}
{% set count = states[domain] | selectattr('state','eq', state) | map(attribute='entity_id') | list | count %}

you gotta output count…

{% %} means don’t output anything

{{ }} means output whats in the brackets

{% set domain = 'light' %}
{% set state = 'on' %}
{% set count = states[domain] | selectattr('state','eq', state) | map(attribute='entity_id') | list | count %}
{{ count }}
1 Like

Aha that made the trick, thanks for the quick answer. Much appreciated!

1 Like

I applied this to a template sensor since I want to display how many lights thats turned on in a view. However it looks like the sensor is not updated when I turn on and off lights. Is that normal and if so, is it possible to make it update frequently?

you have to list out all entities under the entity_id field if you want it to update when anything inside the template updates.