Script runs but not changing the light brightness

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)


Have you tried using brightness percent instead ?
Or possibly brightness step ?

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.

As you can see, the script runs when I use the last code posted above.

…but the light brightness never changes.

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…
Current light brightness:

Calling the service manually (copied directly from the script):

New brightness:

As we see… no change…

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.

This works:

service: light.turn_on
data:
  entity_id: light.daves_bedside_lamp
  brightness: 126

This does not work:

service: light.turn_on
data:
  entity_id: light.daves_bedside_lamp
  brightness: "{{ (state_attr('light.daves_bedside_lamp', 'brightness') -1) }}"

Any ideas?

I just tried this:

light_brightness_decriment:
  sequence:
  - service: light.turn_on
    target:
      entity_id: light.lifx_wardrobe
    data:
      brightness: "{{ state_attr('light.lifx_wardrobe', 'brightness') - 1 }}"

It works as expected. The brightness decreases by one every time the script is called.

I just tried your version.

Before service call:

service call in dev tool:

service: light.turn_on
target:
  entity_id: light.daves_bedside_lamp
data:
  brightness: "{{ state_attr('light.daves_bedside_lamp', 'brightness') - 1 }}"

After:

… no change

Have you tried it on another light?

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.

Ah ok.

Each light type has its own integration for control. The integration acts like a “driver” between the home assistant services and the device.

It would seem that there is an issue with the Wiz integration. You should open a new issue here:

Done.

You might want to include a note that this issue is only for the Wiz light and that other light types work as expected with your provided example.

Good point. I’ll do that now.

And that the brightness_step: option does not seem to work either.

Have you ever sorted this out? Got 2 WiZ Tunables here and am also not able to change brightness through a script. The lights turn either straight to full brightness or to “OFF” (brightness: null). No stepping possible.

I had given up on it but I just swapped them to the new Wiz app a few weeks ago and I have a feeling that the bulbs got a firmware update through that process. There is no way to check for updates or even see the firmware version in the app but since doing the swap the bulbs have been super stable vs the old situation of them going unavailable all the time.

So, I really should try and see if transitions work now…

Are you using the old / original Wiz app or the current one? It wasn’t just an update, its a new app altogether. “Wiz V2”