Dimming and brightening just what is already turned on

hi good people, need some assistant with my home

the end result i wish to achieve - dim and bright only the lights that are already on within a group or area.

to do so, i created a group, with all the lights in my bedroom, and i created a template to call only the lights that are on:

|{{ expand('group.NAME_OFF_GROUP') | selectattr('state', 'eq', 'on') ||
|map(attribute='entity_id') | list }}|

when i check the “template”, it works fine, and spot just the bulbs that are on with no prob.

what would be the best implantation of this with a button in the dashboard?
can i use a mushrooms light card with a slider to just control the “on state” lights?
maybe a “costume button card” would be better (as i can tell it to repeat an action like “light.turn_on” at 5%" while being held)?

any ideas to tackle this would be great.
cheers

managed to figure it out, i’ll leave the code i am using if anyone will try to do the same:

  1. Start with creating a group in “helpers” with the lights you want in the group. call it what you want. something like: “light.backlights_wleds_hyperion”

  2. creat a script with this script config (to allow control of the lights that are already on, and just them):

service: light.turn_on
data:
  brightness_step_pct: 5
target:
  entity_id: >-
    {{ expand('light.backlights_wleds_hyperion') | selectattr('state', 'eq',
    'on') | map(attribute='entity_id') | list }}
  1. download the custom:button card from hacs (as it allows to add the “repeat while holding”)
    use this config for it
    custom:button-card config
type: custom:button-card
entity: script.backlights_wleds_hyperion_dim_up
icon: mdi:chevron-triple-up
name: dimming up
tap_action:
  action: call-service
  service: script.backlights_wleds_hyperion_dim_up
hold_action:
  action: call-service
  service: script.backlights_wleds_hyperion_dim_up
  repeat: 100

that works great with a “button”, and dim or brighten the already “on” lights.

if anyone can add a support for a “light card” like mushroom, or else, with a slider - that will be great.
:slight_smile:
if anyone needs help with this, leave a Q
cheers.

1 Like

Great example, and just what I was looking for.

However, I fail to be able to save, regardless of I try thisi in an automation or in a script.

Not a valid value for dictionary value @ data

How did you get around that?

hey man
the part i mentioned is just the “action/sequence” part of the script.
if you want to start with an empty one, and go directly to YAML mode, you will need some more lines.

this example should work fine for pasting into a blank script page.
change the “alias” to what you want, and the make sure the group name is consistent with whatever you called yours.
after saving, you can go back to UI mode, and see how things are laid out, change icons etc.

let me know how you do.

cheers

alias: backlights wleds hyperion dim up
sequence:
  - service: light.turn_on
    data:
      brightness_step_pct: 5
    target:
      entity_id: >-
        {{ expand('light.backlights_wleds_hyperion') | selectattr('state', 'eq',
        'on') | map(attribute='entity_id') | list }}
mode: single
icon: mdi:chevron-triple-up

That is exactly what I have tried, with the exemption of the alias and the type of service action.

alias: Dimma ned tända lampor
sequence:
  - service: light.turn_on
    data:
      brightness_pct: 5
    target:
      entity_id: >-
  {{ expand('group.lampor_light') | selectattr('state','eq','on') | map(attribute='entity_id') | list}}
mode: single

However, there is a slight difference as you seem not to have a group domain, but a light domain instead - but the actual template works when I try it in developer tool

['light.kok_diskbank', 'light.kok_fonster', 'light.matrum_fonster', 'light.sovrum_annika_hylla', 'light.sovrum_erika_fonster', 'light.trapphall_bokhylla', 'light.vagglampa_trappa', 'light.vardagsrum_bursprak', 'light.vardagsrum_sideboard_fonster']

i think you will have to use the “light” domain, otherwise you will not be able to use the “light.turn_on” function, and without that (as far as i know), there is no dimming.

the “turn on/off” will work, and the template will still be able to know what is on, and what’s off - as they work on switches too, and a “group” domain can be lights & switches.

but since we want “dimming” - as i mentioned, i think you will have to use as a light domain.

In your example, the template isn’t indented sufficiently. It should be like this:

alias: Dimma ned tända lampor
sequence:
  - service: light.turn_on
    data:
      brightness_pct: 5
    target:
      entity_id: >-
        {{ expand('group.lampor_light') | selectattr('state','eq','on') | map(attribute='entity_id') | list}}
mode: single

Yes, you can use the expand filter with a traditional group entity.

@123 - Thank you! Problem solved.

thanks for the clarifications.
i am no coder, and having a professional eye looking over our shoulders is always a good thing.
cheers