Controlling only lights that are on within a group or an area with templating

bottom line - I’m looking for a way to dim only the lights that are actually “on” within a group or an area.

using some ZigBee buttons, i manage to write an automation to dim the lights up or down as long as a button is being held. i can use that automation with a single light, a group or an area. that is awesome, no complaints. yet.
sometimes, i turn on just one light , and want to dim only it. however, if the automation is for that whole bedroom group - when i try to “dim up” to make that one light a bit stronger, the automation will turn “on” all the other lights within that group - not a big surprise, but not the outcome i am trying to achieve.

the solution im looking for is:
A way to filter the lights, probably with some templating, to control with the same automation and buttons only the lights within a group\area that are on.
i can duplicate the automation from a single entity, to all the other i want to control, with a condition to check each entity state, but that will make me end-up with way to much automations for that specific task.
im sure there is an easier way of doing that - i just cant figure it out for myself…
:slight_smile:
cheers

Post you current automation.

{{ expand('group.your_lights') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}
{{ expand(area_entities('your_area')) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}
1 Like

U R THE MAN!

i love it when things r as easy as i know they should be, but dont know how to get’em by myself.
thanks dude.

now…
can i get some pointers on how to implement that in the automation as the target of “what to actually control”?
do i need to make an entity out of this template some how?

You should post your properly formatted yaml code for the automation as requested. It makes it easier for people to help you.

at least the actions section…

here it is:

action:
  - choose:
      - conditions:
          - condition: trigger
            id: held2
        sequence:
          - repeat:
              until:
                - condition: trigger
                  id: 'long release2  '
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step_pct: 5
                  target:
                    entity_id: light.desk
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
      - conditions:
          - condition: trigger
            id: held3
        sequence:
          - repeat:
              until:
                - condition: trigger
                  id: long release3
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step_pct: -5
                  target:
                    entity_id: light.desk
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
    default: []
mode: restart

i need to replace the “light.desk” entity with the templat, so the action will affect only “on” entities
hope it helps
10X

You have effectively summarized, what you need to do. Replace light.desk with the template (ensure you put the template between double-quotes).

                  target:
                    entity_id: "{{ expand('group.your_lights') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}"

when you know how to do stuff… things are EZPZ…
love this community and learning new stuff all the time.
thanks @123 and all for helping
works like the magic that it is…
cheers

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

of Corse!
you so deserve it
:1st_place_medal: