Script runs but not changing the light brightness

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

Sure? From full brightness, at -1 step each 10 secs, it’ll take 42 minutes for your light to turn off :slight_smile:

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)


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.