Dimming over time with transition

I am trying to turn on a light over time so that it reaches 100% brightness slowly.

To see whether the transition is working I currently have the transition set to 25 seconds, I’ll adjust later.

When I run the action it goes straight to 100% brightness without ever transitioning. No matter what I try it’s always the same result.

How can I get this to work? I thought the transition would take care of it automatically, documentation is spectacularly lacking and I wasn’t able to find any answer by googling it, none of the proposed solutions work.

Here’s what I’m using now, that doesn’t work.

service: light.turn_on
data:
  entity_id: light.salon
  transition: 25
  brightness_pct: 100

The answer is that depends on the hardware - Home Assistant doesn’t itself handle transitions - it passes the instruction to the hardware. For example - I can happily send transition commands to my Zigbee lights connected via Zigbee2MQTT, but my ZWave bulbs ignore transition commands and just immediately go to the requested brightness.

Could be, I’m using proprietary hardware by my electricity provider on their zigbee hub.

Could this be done another way, say with a script?

I’ve been trying to understand how to implement them and I even saw some python examples but the documentation is lacking as to how to actually integrate them?

Sure, here is a script I use to gradually increase the volume of Google Nest speakers - this can easily be adapted to change light brightness instead of media volume.

alias: Music Walk Volume Adjust
fields:
  media_target:
    description: The media player to target
    example: media_player.kitchen_nest
  volume_target:
    description: The target volume to increase to
    example: 0.96
sequence:
  - condition: template
    value_template: >-
      {{ (state_attr(media_target,'volume_level')|float(0)|round(1) <
      (volume_target|float(0))) or ((volume_target|float(0)) <
      (state_attr(media_target,'volume_level')|float(0)|round(1))) }}
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ (state_attr(media_target,'volume_level')|float(0)|round(1) <
              (volume_target|float(0))) }}
        sequence:
          - repeat:
              until:
                - condition: template
                  value_template: >-
                    {{ state_attr(media_target,'volume_level')|float(0)|round(1)
                    >= volume_target }}
              sequence:
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 650
                - service: media_player.volume_set
                  data:
                    entity_id: "{{ media_target }}"
                    volume_level: >
                      {% set cv =
                      state_attr(media_target,'volume_level')|float(0) %} {% set
                      nv = cv + 0.0450|float|round(3) %} {{ nv }}
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: media_player.volume_set
            data:
              entity_id: "{{ media_target }}"
              volume_level: "{{ volume_target }}"
      - conditions:
          - condition: template
            value_template: >-
              {{ ((volume_target|float(0)) <
              (state_attr(media_target,'volume_level')|float(0)|round(1))) }}
        sequence:
          - repeat:
              until:
                - condition: template
                  value_template: >-
                    {{ state_attr(media_target,'volume_level')|float(0)|round(1)
                    < volume_target }}
              sequence:
                - service: media_player.volume_down
                  data:
                    entity_id: "{{ media_target }}"
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 650
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: media_player.volume_set
            data:
              entity_id: "{{ media_target }}"
              volume_level: "{{ volume_target }}"
    default: []
mode: parallel
max: 5

Simple change the service call to light.turn_on instead and the volume_level to brightness

1 Like

Here is what I use to transition my deck light at sunset over about 15 minutes:

  - alias: LC Deck Light Fade On at Dusk
    initial_state: 'on'
    mode: restart
    trigger:
      - platform: state
        entity_id: sensor.dark_outside
        to: 'true'
      - platform: sun
        event: sunset
        offset: "+00:07:00"
    condition:
      - condition: state
        entity_id: light.deck_light_0a4c
        state: 'off'
    action:
      - service: light.turn_on
        data:
          entity_id: light.deck_light_0a4c
          brightness: 5
      - repeat:
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.deck_light_0a4c
                brightness: "{{ state_attr('light.deck_light_0a4c', 'brightness') | int + 1 }}"
            - delay: 2
          until:
            condition: or
            conditions:
              - condition: template
                value_template: "{{ state_attr('light.deck_light_0a4c', 'brightness') | int >= 254 }}"
              - condition: state
                entity_id: light.deck_light_0a4c
                state: 'off'

the only issue is that if HA gets restarted or automations get reloaded during the transition it will be stuck there. So I use this one to resume the transistion:

  - alias: LC Deck Light Resume Fade On at Dusk
    mode: restart
    trigger:
      - platform: homeassistant
        event: start
      - platform: event
        event_type: automation_reloaded
    condition:
      - condition: state
        entity_id: light.deck_light_0a4c
        state: 'on'
      - condition: template
        value_template: "{{ state_attr('light.deck_light_0a4c', 'brightness') | int < 254 }}"
    action:
      - delay:
          seconds: 10
      - repeat:
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.deck_light_0a4c
                brightness: "{{ state_attr('light.deck_light_0a4c', 'brightness') | int + 1 }}"
            - delay: 2
          until:
            condition: or
            conditions:
              - condition: template
                value_template: "{{ state_attr('light.deck_light_0a4c', 'brightness') | int >= 254 }}"
              - condition: state
                entity_id: light.deck_light_0a4c
                state: 'off'

I could probably combine them into one but I’m not that anal about having everything in one automation.

2 Likes

I don’t use this (because my lighting accepts transition) but it might interest you:

1 Like

Hadn’t thought of repeat, that’s not a bad idea at all.

1 Like

Was the Light Fader I had suggested of any use to you? Or did you solve your problem by creating a script like finity like in finity’s example?

I ended up using the python script suggested. Got me to learn how to integrate them at the same time so it’s a win-win

1 Like