Help needed with light transition

This is what I have now… and it does nothing!

input_boolean:
  ib_fishtank01_brightness_overide:
    name: Brightness Overide
    icon: mdi:arrow-collapse-up

input_number:
  in_fishtank01_brightness_level:
    name: Brightness (/255)
    initial: 0
    min: 0
    max: 256
    step: 1
    mode: box
    icon: mdi:arrow-expand-vertical

automation:
  - alias: au_fishtank01_brightness_overide_timer
    trigger:
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
    action:
      - service: script.turn_off
        entity_id: script.sc_fishtank01_overide_timer
      - service_template: script_{{trigger.to_state.state}}
        entity_id: script.sc_fishtank01_overide_timer
  - alias: au_fishtank01_adjust_brightness
    trigger:
      - platform: state
        entity_id: input_number.in_fishtank01_brightness_level
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
      - platform: time_pattern
        seconds: '/80'
    action:
      - service: script.sc_fishtank01_calc_level
      - delay: '00:00:01'
      - service: light.turn_on
        entity_id: light.0x680ae2fffeb18442_light
        data_template:
          brightness: "{{ states('input_number.in_fishtank01_brightness_level') }}"
          transition: 10

script:
  sc_fishtank01_overide_timer:
    alias: FT Overide Timer Script
    sequence:
    - delay: "00:20:00"
    - service: input_boolean.turn_off
      entity_id: input_boolean.ib_fishtank01_brightness_overide
  sc_fishtank01_calc_level:
    alias: Fish Tank 01 Calc Brightness
    sequence:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.in_fishtank01_brightness_level
        value: >
          {% set ovrd = is_state('input_boolean.ib_fishtank01_brightness_overide', 'on') %}
          {% set tnow = as_timestamp(now()) %}
          {% set frm12 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '12:00')) %}
          {% set frm17 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '17:00')) %}
          {% set frm22 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '22:00')) %}
          {% set cnt = frm22 < 0 <= frm12 %}
          {% set rise = cnt and frm17 < 0 %}
          {% set fall = cnt and frm17 >= 0 %}
          {% set outp = 0.0 %}
          {% if ovrd %}
            {% set outp = 255 %}
          {% elif rise %}
            {% set outp = frm12 / 80 + 30 %}
          {% elif fall %}
            {% set outp = 255 - frm12 / 80 %}
          {% else %}
            {% set outp = 0 %}
          {% endif %}
          {{ (outp + 0.5) | int }}

see my post just above yours

it did work, it’s just that your input number didn’t like having -39 assigned to it (0 to 256 range) not sure why I did the 256 now, could get away with 255

Amended that, but still nothing after a server reboot.

input_boolean:
  ib_fishtank01_brightness_overide:
    name: Brightness Overide
    icon: mdi:arrow-collapse-up

input_number:
  in_fishtank01_brightness_level:
    name: Brightness (/255)
    initial: 0
    min: 0
    max: 256
    step: 1
    mode: box
    icon: mdi:arrow-expand-vertical

automation:
  - alias: au_fishtank01_brightness_overide_timer
    trigger:
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
    action:
      - service: script.turn_off
        entity_id: script.sc_fishtank01_overide_timer
      - service_template: script_{{trigger.to_state.state}}
        entity_id: script.sc_fishtank01_overide_timer
  - alias: au_fishtank01_adjust_brightness
    trigger:
      - platform: state
        entity_id: input_number.in_fishtank01_brightness_level
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
      - platform: time_pattern
        seconds: '/80'
    action:
      - service: script.sc_fishtank01_calc_level
      - delay: '00:00:01'
      - service: light.turn_on
        entity_id: light.0x680ae2fffeb18442_light
        data_template:
          brightness: "{{ states('input_number.in_fishtank01_brightness_level') }}"
          transition: 10

script:
  sc_fishtank01_overide_timer:
    alias: FT Overide Timer Script
    sequence:
    - delay: "00:20:00"
    - service: input_boolean.turn_off
      entity_id: input_boolean.ib_fishtank01_brightness_overide
  sc_fishtank01_calc_level:
    alias: Fish Tank 01 Calc Brightness
    sequence:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.in_fishtank01_brightness_level
        value: >
          {% set ovrd = is_state('input_boolean.ib_fishtank01_brightness_overide', 'on') %}
          {% set tnow = as_timestamp(now()) %}
          {% set frm12 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '12:00')) %}
          {% set frm17 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '17:00')) %}
          {% set frm22 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '22:00')) %}
          {% set cnt = frm22 < 0 <= frm12 %}
          {% set rise = cnt and frm17 < 0 %}
          {% set fall = cnt and frm17 >= 0 %}
          {% set outp = 0.0 %}
          {% if ovrd %}
            {% set outp = 255 %}
          {% elif rise %}
            {% set outp = frm12 / 80 + 30 %}
          {% elif fall %}
            {% set outp = 255 - frm17 / 80 %}
          {% else %}
            {% set outp = 0 %}
          {% endif %}
          {{ (outp + 0.5) | int }}


can you display the input number ?
can you see if it changes ?
do you have any errors ?

This value doesn’t change:
Screenshot_2020-03-14_18-58-25

Brightness override not working either.

I reiterate : -

Do you have control the lovelace ?

Just insert
input_number.in_fishtank01_brightness_level

No, it just displays 123, which isn’t the actual value the dimmer is currently at, and changing this through the interface doesn’t change the levels and the value jumps back to 123
Screenshot_2020-03-14_19-56-07

UPDATE: The value is not showing 120, so maybe it’s ramping down? It doesn’t look like actual dimmer value is changing however.

Turning on brightness override sets the above value to 255, however it does not change the light level.

It looks like all the functions are working but not sending the values to the dimmer controller

That’s what we are trying to determine.

Monitor the number, it ‘should’ basically change every 80 seconds and go to 30 at 22:00 and jump to 0 and stay that way till 12:00 tomorrow jump to 30, ramp up, ramp down, rinse and repeat.

Check you don’t have this light anywhere else in you automations

The number is going down, it’s now 97, but it’s not dimming the light.

It does not appear to be sending the value to the dimmer, as neither the decreasing values nor the override have any effect on the dimmer.

Check that the name of the light in the automation is exactly the same as your actual light

Screenshot_2020-03-14_20-55-28

From package:

    action:
      - service: script.sc_fishtank01_calc_level
      - delay: '00:00:01'
      - service: light.turn_on
        entity_id: light.0x680ae2fffeb18442_light
        data_template:
          brightness: "{{ states('input_number.in_fishtank01_brightness_level') }}"
          transition: 10

From automation with delays (working):

  action:
  - data:
      brightness: 11
    entity_id: light.0x680ae2fffeb18442_light
    service: light.turn_on
  - delay: 00:00:10
  - data:
      brightness: 255
      transition: 18000
    entity_id: light.0x680ae2fffeb18442_light
    service: light.turn_on
  - delay: 00:00:18000
  - data:
      brightness: 11
      transition: 18000
    entity_id: light.0x680ae2fffeb18442_light
    service: light.turn_on
  - delay: 00:00:18000
  - data: {}
    entity_id: light.0x680ae2fffeb18442_light
    service: light.turn_off

Edit : There is a problem with brightnes: vs brightness_pct: (No Idea Why) Please go down to Post 95 for the workaround

I’m doing some experiments.

As an aside :
@jwelter if you look at the entities created you will see that the code is based on useage of an editor that reads your whole configuration for autocomplete ability (like VSC) so my file would be called fishtank01.yaml
if I ever need to change the config for in_fishtank01_brightness_level I know I can find it in the fishtank01 file
Also when I’m typing and I want to use an entity, I start typing “inp” and options come up for input_boolean, input_number, input_select etc. I just click the one I want
hit “.” and all the input_numbers (in this case) come up. As I type the list is narrowed.
the ‘in_’ is just for easy recognition in entities lists (and it also helps in scanning through lists as alphabetically I will know where to find them), the next bit is the package, then what I’m using it for.
It makes coding a LOT faster.

@bedfellow so, I don’t actually use brightness, I use brightness_pct and when I cenvert the package to brightness_pct it works (not been through a full day yet though.
Here is my ‘modified’ package I’m testing with : -

input_boolean:
  ib_fishtank01_brightness_overide:
    name: Brightness Overide
    icon: mdi:arrow-collapse-up

input_number:
  in_fishtank01_brightness_level:
    name: Brightness (/255)
    initial: 0
    min: 0
    max: 255
    step: 1
    mode: box
    icon: mdi:arrow-expand-vertical

automation:
  - alias: au_fishtank01_brightness_overide_timer
    trigger:
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
    action:
      - service: script.turn_off
        entity_id: script.sc_fishtank01_overide_timer
      - service_template: script_{{trigger.to_state.state}}
        entity_id: script.sc_fishtank01_overide_timer
  - alias: au_fishtank01_adjust_brightness
    trigger:
      - platform: state
        entity_id: input_number.in_fishtank01_brightness_level
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
      - platform: time_pattern
        seconds: '/80'
    action:
      - service: script.sc_fishtank01_calc_level
      - delay: '00:00:01'
      - service: light.turn_on
#        entity_id: light.fishtank01_level
        entity_id: light.fibdim2_lgl1_level
        data_template:
          brightness_pct: "{{ states('input_number.in_fishtank01_brightness_level') }}"
          transition: 10

script:
  sc_fishtank01_overide_timer:
    alias: FT Overide Timer Script
    sequence:
    - delay: "00:20:00"
    - service: input_boolean.turn_off
      entity_id: input_boolean.ib_fishtank01_brightness_overide
  sc_fishtank01_calc_level:
    alias: Fish Tank 01 Calc Brightness
    sequence:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.in_fishtank01_brightness_level
        value: >
          {% set ovrd = is_state('input_boolean.ib_fishtank01_brightness_overide', 'on') %}
          {% set tnow = as_timestamp(now()) %}
          {% set frm12 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '12:00')) %}
          {% set frm17 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '17:00')) %}
          {% set frm22 = tnow - as_timestamp(now().strftime('%Y-%m-%d ' ~ '22:00')) %}
          {% set cnt = frm22 < 0 <= frm12 %}
          {% set rise = cnt and frm17 < 0 %}
          {% set fall = cnt and frm17 >= 0 %}
          {% set outp = 0.0 %}
          {% if ovrd %}
            {% set outp = 255 %}
          {% elif rise %}
            {% set outp = frm12 / 80 + 30 %}
          {% elif fall %}
            {% set outp = 255 - frm12 / 80 %}
          {% else %}
            {% set outp = 0 %}
          {% endif %}
          {{ ((outp + 0.5) * 100 / 255) | int }}

It seems to be a tiny syntax discrepancy which I can’t find. hopefully @anon43302295 , @123 , @finity or @pnbruckner could cast an eye over the two and point out exactly where I have f****d up :face_with_symbols_over_mouth:
Sorry about this, I thought the two were more of less interchangeable. If necessary I can rewrite this again using pct and reducing your processor load.

Sorry, no, I left this thread many posts ago. I’m sure you’ll solve it. Good luck.

1 Like

Okay, I found a thread with a solution to brightness: using a template by pnbruckner.

I remeber reading that ‘some’ devices are picky about specific indentation and don’t seem to follow normal rules, as the above shows.
I changed tthe syntax accordingly but still no joy.
I’ve given up
It does work for pct so I’ve modified the package for that.
Using 0 = off, 11 = minimum brightness, 100 = maximum, then over 5hrs (18,000 seconds) that’s a step every 202.247 (and some change). So I set the update to 101 (more than twice the required frequency but still a saving on the previous).
As the entity definitions have changed, it will require a restart

input_boolean:
  ib_fishtank01_brightness_overide:
    name: Brightness Overide
    icon: mdi:arrow-collapse-up

input_number:
  in_fishtank01_brightness_level:
    name: Brightness (percent)
    initial: 0
    min: 0
    max: 100
    step: 1
    mode: box
    icon: mdi:arrow-expand-vertical

automation:
  - alias: au_fishtank01_brightness_overide_on
    trigger:
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
        from: 'off'
        to: 'on'
    action:
      - service: script.sc_fishtank01_overide_timer
  - alias: au_fishtank01_brightness_overide_off
    trigger:
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
        from: 'on'
        to: 'off'
    action:
      - service: script.turn_off
        entity_id: script.sc_fishtank01_overide_timer
      - service: script.sc_fishtank01_overide_timer
  - alias: au_fishtank01_adjust_brightness
    trigger:
      - platform: state
        entity_id: input_number.in_fishtank01_brightness_level
      - platform: state
        entity_id: input_boolean.ib_fishtank01_brightness_overide
      - platform: time_pattern
        seconds: '/101'
    action:
      - service: script.sc_fishtank01_calc_level
      - delay: '00:00:01'
      - service: light.turn_on
#        entity_id: light.fishtank01_level
        entity_id: light.fibdim2_lgl1_level
        data_template:
          brightness_pct: "{{ states('input_number.in_fishtank01_brightness_level') }}"
          transition: 5

script:
  sc_fishtank01_overide_timer:
    alias: FT Overide Timer Script
    sequence:
    - delay: "00:01:00"
    - service: input_boolean.turn_off
      entity_id: input_boolean.ib_fishtank01_brightness_overide
  sc_fishtank01_calc_level:
    alias: Fish Tank 01 Calc Brightness
    sequence:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.in_fishtank01_brightness_level
        value: >
          {% set ovrd = is_state('input_boolean.ib_fishtank01_brightness_overide', 'on') %}
          {% set tnow = as_timestamp(now()) %}
          {% set date = now().strftime('%Y-%m-%d ') %}
          {% set frm12 = tnow - as_timestamp(date ~ '12:00') %}
          {% set frm17 = tnow - as_timestamp(date ~ '17:00') %}
          {% set frm22 = tnow - as_timestamp(date ~ '22:00') %}
          {% set cnt = frm22 < 0 <= frm12 %}
          {% set rise = cnt and frm17 < 0 %}
          {% set fall = cnt and frm17 >= 0 %}
          {% set outp = 0.0 %}
          {% if ovrd %}
            {% set outp = 100 %}
          {% elif rise %}
            {% set outp = frm12 / 202.247 + 11 %}
          {% elif fall %}
            {% set outp = 100 - (frm17  /  202.247) %}
          {% else %}
            {% set outp = 0 %}
          {% endif %}
          {{ (outp + 0.5) | int }}

Again the light used is a test lamp so you will have to replace that with “your light”

PLEASE ensure you delete (or at least comment out all other instances of turn on/off etc of your light entity, as I said before this should do the lot.

I’ll await someone a ‘LOT’ wiser than I (sets the bar pretty low) to explain what’s going on with brightness vs brightness_pct

I’m playing with at Tasmota RGBCT light.
What you have there looks like the second step to me.

From what I have working you need to add two data sections:

action:
  - data:
      brightness_pct: 12
    entity_id: light.0x680ae2fffeb18442_light
    service: light.turn_on
  - data:
      brightness_pct: 100
      transition: 18000
    entity_id: light.0x680ae2fffeb18442_light
    service: light.turn_on
  - data:
       brightness_pct: 12
      transition: 18000
    entity_id: light.0x680ae2fffeb18442_light
    service: light.turn_on

It might be you need a delay between the steps (I could be imagining it but it seems to help for some of my transitions)

  - delay:
      seconds: 1

I did this today. Got the code from a YouTuber and slightly modified it. It’s so flexible - you could do whatever you want.

input_number:

  dining_room_morning_light:

    name: Dining Room Motning Light

    initial: 5

    min: 5

    max: 150

    step: 1

script:

 

  dining_room_morning_lighting:

    sequence:

      - repeat:

          sequence:

            - service: script.dining_room_lights_w_level

              data:

                  level: '{{ states("input_number.dining_room_morning_light") }}'

                  colortemp: 400

            - service: input_number.increment

              entity_id: input_number.dining_room_morning_light

            - delay: 00:00:15

          until:

            - condition: template

              value_template: '{{ states("input_number.dining_room_morning_light") | int == 150 }}'

      - service: input_number.set_value

        data:

          entity_id: input_number.dining_room_morning_light

          value: 5

  dining_room_evening_lighting:

    sequence:

      - service: script.dining_room_lights_w_level

        data:

            level: 255

            colortemp: 270

  dining_room_lights_w_level:

    sequence:

      - service: light.turn_on

        entity_id: light.dining_room_main_lights

        data:

          brightness: >

            {{ level | int }}

          color_temp: >

            {{colortemp}}

I recently had to do the same thing for a powerhead in my aquarium, I wanted to ramp up/down the speed over an hour however it wouldnt work using the transition command. I ended up using the repeat command to increase the percentage every x minutes.

So in your case since you want it to ramp up 88% over 18000 seconds you would need to increase the light 1% every 204 seconds (3 min & 24 seconds). So try the following:

alias: light-ramp-up
description: ""
trigger:
  - platform: time
    at: "00:00:00"
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: 12
    target:
      entity_id:  your light
  - repeat:
      until:
        - condition: numeric_state
          entity_id: your light
          above: 99
      sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: 1
          target:
            entity_id: your light
        - delay:
            hours: 0
            minutes: 3
            seconds: 24
            milliseconds: 0
mode: single

to ramp back down:

alias: light-ramp-down
description: ""
trigger:
  - platform: time
    at: "05:00:00"
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: 100
    target:
      entity_id:  your light
  - repeat:
      until:
        - condition: numeric_state
          entity_id: your light
          below: 12
      sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: -1
          target:
            entity_id: your light
        - delay:
            hours: 0
            minutes: 3
            seconds: 24
            milliseconds: 0
mode: single

then add an action to turn off the light or set it to 12%