Set Dimmer Group level when ANY Dimmer in the Group changes?

I have 4 dimmers in a Group. I’m trying to create an automation that will set ALL dimmers in that group to the level of whichever Dimmer changes. I’m not seeing a direct way to do this - I’m new so assuming I’m missing something simple?

I also looked for a Blueprint, didnt see one?

I need to do this a lot in my house as I have several multi-way circuits with z-wave dimmers and/or switches them.

thanks for the help!

1 Like

I don’t think you can do this reliably[*] with a group, unfortunately, because a state-based trigger on the group won’t, as far as I can tell, let you ascertain which entity in the group actually changed. And you need to know that, so that you can figure out what it changed from and to, in order to figure out what to do with the other entities.

What kind of entities are you grouping? Lights or sensors? If sensors, who’s providing the sensor–is it a template sensor you’ve created or is the sensor coming from the integration? Depending on the answers, there is almost certainly a good way to do what you’re trying to do.

[*] I say reliably because you likely COULD write an automation that, once triggered by the group, does some magic to iterate over the group members to figure out which one was changed most recently. But I have a feeling that this wouldn’t work too well for a number of reasons, and would be pretty ugly as far as code goes. A simpler solution is probably better here.

Not being able to trigger on individual Entity status within a group is a big oversight in the design of Groups.

The intent of Groups is to get status and control multiple similar items all at once.

Pull value/status of the individual Entities within that Group is an essential feature to be able to fully utilize the benefit of groups. For comparing values and/or if/when things changed… value is larger than / smaller than, turned on within the last N seconds, and many more.

Groups entities can change as devices are replaced/etc and still the automation is at the group level, so admin is 100x easier… greatly reduce re-work for building/updating Automations.

In Homeseer it is a simple 2 line automation. The THEN statement calls a ‘Global Variable’ set in the WHEN statement…

I think you can set the brightness for the group, but to detect the changed entity you need to itemize each member in the trigger list of an automation.

triggers:
  - trigger: state
    entity_id:
      - light.dimmer_1
      - light.dimmer_2
      - light.dimmer_3
      - light.dimmer_4
    attribute: brightness
actions:
  - action: light.turn_on
    data:
      brightness: "{{ state_attr(trigger.entity_id, 'brightness') }}"
    target:
      entity_id: light.groupname

It’d be cool if you could use templates to auto-expand the group entities, like {{ state_attr(light.groupname, 'entity_id')|list }} but that didn’t work when I tried it; triggers only support “limited templates” and maybe someone more knowledgeable knows how to construct one here.

Lastly, since you have Z-Wave dimmers, you may have other options. Many zwave dimmers support group associations on the multilevel switch, so one dimmer directly commands the others when its level changes. HA is not involved, so works even if your server is offline.

One drawback of that approach, @peterxian, is that it obviates the usefulness of having a group. You’d be better off listing all the entity IDs in the light call than relying on the group, because at least that way if you change the list, you don’t need to go update it in two different subsystems.

But if the group is a group of lights, then it’s probably not possible to implement this and still get the benefit of using a group, which I think is what you’re saying too.

Also, at least for light groups, it’s possible to get a list of the entity_ids in the group using

state_attr(GROUP_ENTITY_ID, 'entity_id')

The approach I alluded to above–which I would not recommend here–is to iterate over that list and figure out the most recently updated light using states[entity_id][‘last_updated’]. But there is no way to do that safely – it will sooner or later spill its guts because the states object isn’t guaranteed to be complete; see the yellow Warning box here.

(Oh, also. Just realized, you were exploring using the entity_id attribute for the trigger. I wish.)

Without even having attempted it I don’t see why not. In a template, simply expand the group to get the individual lights. If you want to get fancy, compare the state context id of the individual lights against the to_state of the group. If you don’t, simply assume that the light that saw the most recent change probably was the one to have its brightness changed to trigger the automation.

If it wasn’t already midnight and really time to get some sleep I’d write up a quick proof of concept. Might do that tomorrow if no-one else does it during my night.

What the heck, couldn’t help myself. Completely untested of course as I don’t even use light groups (well I do, but on the Zigbee network level, not HASS groups). Probably has a typo or some required details missing, but the concept should be sound.

triggers:
- trigger: state
  entity_id: light.my_group
  attribute: brightness
actions:
- action: light.turn_on
  target:
    entity_id: light.my_group
  data:
    brightness: >-
     {{ expand('light.my_group')
     | sort(attribute='last_updated')
     | last | attr('attributes.brightness') }}

Alternatively, if one wants to experiment with context which may or may not be even more accurate, substitute the template for something like this:

{{ expand('light.my_group')
| selectattr('context.id', trigger.to_state.context.id)
| first | attr('attributes.brightness') }}

That works if your light gives you a “last_updated” attribute. My Hue lights, for example, don’t.

Wrong and right. last_updated is not an attribute of the light, it is an attribute on the state object. But you are correct in that there is an error in my code (as I said, untested and bound to have typos!), there is an attributes (well two, if counting the context example) too much. Removed them now.

Are you suggesting looking at the ID of the parent context of the to_state of the group, and then comparing that to the context ID of each light in the light group? Your code definitely doesn’t get you there, but I suspect that that approach would be even less reliable than using the state object. For one, there is no guarantee that the brightness change of the light that triggered the group state change is the very last state change of that light.

Guaranteed no, but surely quite likely yes. Nothing preventing including both, if there is no exact match on context (due of too rapidly fluctuating state) then fallback to whichever light was updated last.

As I said, I don’t use light groups except on the Zigbee level. I have no idea if HASS would consider both the individual light and the group to have been updated by the same state object, or if the light would be the parent of the group. But that should be simple to test, if you do have light groups.

{{ (expand('light.my_group')
| selectattr('context.id', trigger.to_state.context.id)
| list or expand('light.my_group')
| sort(attribute='last_updated', reverse=true))
| first | attr('attributes.brightness') | int(0) }}

Or alternatively in the event that the individual light state is considered a parent of the group state:

{{ (expand('light.my_group')
| selectattr('context.id', trigger.to_state.context.parent_id)
| list or expand('light.my_group')
| sort(attribute='last_updated', reverse=true))
| first | attr('attributes.brightness') | int(0) }}

(Though now that I think about it some more, this may need some additional safeguards. If the light was turned off the new brightness will be none which I don’t believe light.turn_on will like… so for this proof of concept lets make it simple with an int(0) filter at the end. Will break if the group includes lights that doesn’t support brightness though.)

Guys, I really appreciate you jumping in! I’m super new to HA, and barely know how to spell YAML… camel? :wink:

I don’t know how to implement any of the code you are thrown around. If someone is feeling generous and wants to make a blueprint, I’d love to test it… and buy you drink of your choice!

Would help to get the answer to this from my earlier post:

Hi, sorry. I only know of a Dimmer being a Light. I’ve never seen that term used in other context, but I’m 1 week new to HA so there is a lot I dont know yet. Thanks for the help!