Simple light transition doesn't work

Hi everyone,

I’m new with ha so also with yaml configuration files.

What I want to do is really simple but even chatgpt isn’t abble to generate a correct script for this:

“I want my light to start 30min before sunrise with a luminosity of 1% and a température color of 2000 kelvins. When my lights are on, the luminosity should go up from 1% to 100% in 30min (until real sunrise in fact). Then when the luminosity is maxed out I want a progressive change in the color from 2000 kelvin to 4000 in 15minutes.”

At the beginning I thought it this way:
`alias: Test
description: “”
trigger:

  • platform: sun
    event: sunrise
    offset: “-00:30:00”
    condition: []
    action:
  • service: light.turn_on
    entity_id: light.0xa4c1387639a4b882
    data:
    brightness_pct: “1”
    kelvin: “2000”
    • service: light.turn_on
      entity_id: light.0xa4c1387639a4b882
      data:
      brightness_pct: “100”
      transition: 1800
    • service: light.turn_on
      entity_id: light.0xa4c1387639a4b882
      data:
      kelvin: “4000”
      transition: 900
      mode: single`

When I start this up my luminosity get to 100 in 4seconds, so I began to try it with chatgpt who made me a bunch of different versions also not working (with loops and so on) because the luminosity is getting to 100% too fast it has to take 30min.

If anyone can help me it would be great.

Thanks,

Impact

Are you certain the light you are using supports long transitions?

For example, go to Developer Tools > Services, switch to YAML mode and copy-paste the following service call:

service: light.turn_on
target:
  entity _id: light.0xa4c1387639a4b882
data:
  brightness_pct: 100
  transition: 300

Then click the Call Service button. Confirm the light takes 5 minutes (300 seconds) to brighten to 100%.

Check if it works if you delete the first/second part. You seems you run both simultaneously? That’s not possible, you need a sequence.

This is the error i get when i try to paste your code in service developer mode.

But I simply made this automation with your idea, with my light already on 1% luminosity :

alias: Test
description: “”
trigger:

  • platform: sun
    event: sunrise
    offset: “-00:30:00”
    condition: []
    action:
  • service: light.turn_on
    entity_id: light.0xa4c1387639a4b882
    data:
    brightness_pct: “100”
    transition: 300
    mode: single

And it gets to 100% in a few seconds

Anyway if my light doesnt support long transition lighting, chatgpt made a script that bypass this limitation, it work a bit because it still fast when reaching the 100% luminosity but i have enough time to see the progress with my eyes (i think it start with 50% then goes up slowly) my only problem is that it start from 50% if it would start from 1% the script would be perfect:

The script call himself every minute:

alias: higher luminosity
description: “”
trigger:

  • platform: time_pattern
    minutes: /1
    seconds: 0
    condition: []
    action:
  • service: light.turn_on
    entity_id: light.0xa4c1387639a4b882
    data:
    brightness_pct: “{{ state_attr(‘light.0xa4c1387639a4b882’, ‘brightness’) + 3 }}”
    transition: 1800
  • condition: template
    value_template: “{{ state_attr(‘light.0xa4c1387639a4b882’, ‘brightness’) >= 97 }}”
    mode: single

With a quick search in this community you will find way better solutions to this. This code you shared generated by ChatGPT is useless… It will try to increase the brightness even when it is 100% or when you want the light off.
It might be good to help in your learning process though. :wink:

Which light you have? Maybe we can help more when knowing that info.

Really?
It only increases the brightness by 3% per minute.

It starts from the point where the light is… If you try to dim you light down to 10% this automation will push it back to 100% (and will try to go beyond) in a 3% increase/minute rate.

It would be nice if you select all the yaml block and then use this code icon from the dialog box in other to make easier for us to read the yaml you are sharing.

This looks much nicer than the way you shared above, and it is the same yaml, with the difference we can cooy&paste&try without having to edit the text, although still the same useless ChatGPT-generated automation (:stuck_out_tongue_winking_eye:):

alias: higher luminosity
description: “”
trigger:
  - platform: time_pattern
    minutes: /1
    seconds: 0
condition: []
action:
  - service: light.turn_on
    entity_id: light.0xa4c1387639a4b882
    data:
      brightness_pct: “{{ state_attr(‘light.0xa4c1387639a4b882’, ‘brightness’) + 3 }}”
      transition: 1800
  - condition: template
    value_template: “{{ state_attr(‘light.0xa4c1387639a4b882’, ‘brightness’) >= 97 }}”
mode: single

There was a typo (an unexpected blank space) on entity_id in the original yaml shared by @123. Please try this and if the error persists could you please share a screenshot of that screen with your YAML and this error message?

service: light.turn_on
target:
  entity_id: light.0xa4c1387639a4b882
data:
  brightness_pct: 100
  transition: 300

That’s due to a simple typo. There’s an unnecessary space character in the word entity _id. It should be entity_id.

If the light increases to 100% much faster than 5 minutes, then it doesn’t support the transition command.

ChatGPT has proven to be an unreliable source for automations and scripts. Please do not post non-functional examples created by ChatGPT. For more information, refer to this blog post.

If you want to dim/brighten a light over a long period of time, and it doesn’t support transition, then you will need to use a script that sends consecutive discrete commands. The problem was discussed and resolved in the following topic:

Here’s another solution to the same problem that also offers non-linear fading.

1 Like

Hi thanks for all thoses replies.

It’s official this little script in dev tools does light up from 1% to 100% in ±20seconds instead of 5 minutes

> service: light.turn_on
> target:
>   entity_id: light.0xa4c1387639a4b882
> data:
>   brightness_pct: 100
>   transition: 300

First and foreall here is my led strip I bought from amazon (it’s not zigbee)
led strip

So to make it abble to communicate with home assistant I had to buy this:
dual white zigbee ledstrip adapter

To recognize this device I just scanned into the mqtt zigbee window and it found instantly the device.
I also have a little card on my dashboard that enable me to set on/off , set the brightness and set the color.

Now I want to make it automatic through the automation yaml script and clearly there is something wrong with it, don’t know why a 300 transition set the light bright from 1% to 100% in few seconds but this made me search for hours and still not explainable.

If anyone has another clue about it, I also took a look at the “light fader by transition time” but it seems nothing happens, I’m also not sure I understand the whole script right.

Thanks.

Take a look on the links shared above. By taking a quick look I found this comment where it is explained by steps how to set up a script for that and how to call that script from your automation.

Let us know if you get stuck after that.

Well I tried also this code but here is what i have as error when I try to create a script containing this code:

image

I tried to add a script in automation => scripts => Add script

fade_light:
  description: "Fades lights to a desired level over a specified transition period."
  fields:
    light:
      name: Light
      description: Entity_id of light.
      selector:
        entity: light.0xa4c1387639a4b882
          domain: 
      example: 
    end_pct:
      name: End brightness Level
      description: Integer value from 0 to 100 representing the desired final brightness level.
      selector:
        number:
          min: 0
          max: 100
          step: 1
          mode: slider
      default: 50
      example: "50"
    transition:
      name: Transition Time
      description: Transition time for fading in seconds.
      selector:
        number:
          min: 0
          max: 1800
          step: 1
          mode: slider
      default: 10
      example: "10"
  mode: parallel
  sequence:
    - variables:
        start_pct: "{{ ((state_attr(light, 'brightness') | int(0))/255*100) | round(0, default=0) }}"
        end_pct: "{{ end_pct | int(0) | round(0, default=0) }}"
        delay_msec: >-
          {{ ([100, (((transition / (end_pct - start_pct)) | abs) | round(3, default=0) * 1000) | int(0)]|sort)[1] }}
        sign: "{{ 1 if start_pct < end_pct else -1 }}"
        n: "{{ 1000 * transition / delay_msec | int(0) }}"
    - repeat:
        while:
          - condition: template
            value_template: >-
              {{  repeat.index <= n }}
        sequence:
          - delay:
              milliseconds: "{{ delay_msec }}"
          - service: light.turn_on
            target:
              entity_id: "{{ light }}"
            data:
              brightness_pct: "{{ ([0, (start_pct + (repeat.index * sign)), 100]|sort)[1] }}"

It’s meant to be copied directly into the scripts.yaml file.

Are you talking about this ?:

I had to download file editor and it seems it’s a system file, I pasted the function there I’m working on it :slight_smile: and will give you feedback

EDIT:

Ok so, the code is successfully saved into scripts.yaml and inside configuration.yaml you can see this:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

So my scripts.yaml is included, but when I go to developper tool => services. It doesn’t show me the function “fade_light”.

EDIT: I had to reboot HA, the function works perfectly for luminosity ! now I have to find it for color :smiley:

1 Like

What you wanna do for color?