I created this script but it doesn’t change the light brightness for some reason. I’ve tried using the brightness_step_pct as well as just brightness_step but neither have worked. Can anyone see why this wouldn’t work? The lights I’m trying to work with are Wiz which unfortunately don’t support transitions, hence using a script.
daves_bedside_lamp_transition_off:
alias: Daves Bedside Lamp Transition Off
sequence:
- condition: state
entity_id: light.daves_bedside_lamp
state: 'on'
- alias: "repeat the dim down of daves lamp"
repeat:
sequence:
- service: light.turn_on
data:
entity_id: light.daves_bedside_lamp
brightness_step: -1
- delay: "00:00:10"
until:
- condition: numeric_state
entity_id: light.daves_bedside_lamp
attribute: brightness
below: 1
- service: light.turn_off
data:
entity_id:
- light.daves_bedside_lamp
At the time that we want to run the script it is only at 10% brightness. These lamps never get set to 100% because it’s simply too bright. I actually have wireless buttons for each bedside lamp and they turn the lamps on at 10% only straight away.
I made a change to this script but it still does not change the light brightness. In ‘traces’ I see that the script runs through the loop but the light just stays on it’s original brightness setting.
script:
daves_bedside_lamp_transition_off:
alias: Daves Bedside Lamp Transition Off
sequence:
- condition: state
entity_id: light.daves_bedside_lamp
state: 'on'
- alias: "repeat the dim down of daves lamp"
repeat:
sequence:
- service: light.turn_on
data:
entity_id: light.daves_bedside_lamp
brightness: "{{ (state_attr('light.daves_bedside_lamp', 'brightness') -1) }}"
- delay: "00:00:10"
until:
- condition: numeric_state
entity_id: light.daves_bedside_lamp
attribute: brightness
below: 1
- service: light.turn_off
data:
entity_id:
- light.daves_bedside_lamp
Any ideas what I’m doing wrong here? (I’m guessing my template isn’t right…however it works in the Dev console)
Yep. Brightness step was my first version (first post above) and I have tried % as well. Since the brightness percentage is not shown in the entity attributes I thought the 0-255 brightness would be more successful… but it wasn’t.
EDIT:
I just tried using brightness_pct once again but that causes an error and the script doesn’t run, I’m guessing because there is no brightness_pct attribute as I mentioned.
Did you try calling the light.turn_on service manually from the developer tools with different brightness values, just to confirm the issue is not on the light side.
EDIT: Thinking more, I wonder if state_attr('light.daves_bedside_lamp', 'brightness') would not be evaluated just once, when the automation is executed.
Wouldn’t the brightness be decreased just by 1 after execution, whatever the number of loops?
EDIT2: If so, maybe try to create a script doing just the turn_on as you currently have. Maybe the attributes will be evaluated at each loop, then.
EDIT3: Nevermind. Just tested the script myself and it works as designed.
For testing, remove the turn_off from the script and check if the brightness decreased.
If not, it must be an issue with the light itself.
The whole brightness thing is a bit of black magic. I have bulbs have no brightness attribute in the light, yet I can dim them via a scene or the UI, and in automations.
What I have done in a similar way is loop through different colours and noticed that difference light types (bulbs vs LED strips for example) react to the colour looping very differently, and need different delays set because they aren’t designed to have a stream of commands sent to them.
But again, given that you are using a 10 second delay, that also shouldn’t be a problem.
As a hack/trial, you could create (say) 10 scenes at different brightness levels and step through those ?
Also, I presume you’ve defnitively proved (perhaps via the UI) that the bulb does support dimming ?
Does this thread help at all? seems to be talking about exactly the same issue
Yep, they are Wiz vintage style globes that can dim and range between cool and warm white. Controlling the dimming and colour temp works fine via the UI. The reason for trying to use a script is that unfortunately they don’t accept transition timing.
More testing… If I send a specific brightness to the light via a service call, it works fine. But using my template to reduce the brightness by 1 does not. No errors logged.
It works on other dimmable lights. It seems like an issue with Wiz lights but I would have thought that HA would simply be sending a new brightness value and therefore the light not seeing any difference compared to my earlier fixed value service call.