Generic Transition - Dynamic State

I’m trying to create a Generic Transition for my lights that don’t support it natively. I’m having trouble getting the dynamic variable to work. With the script I am passing in the entity as the light variable:

  generictransition:
    alias: Generic Light Transition
    sequence:
      - condition: and
        conditions:
          condition: template
          value_template: >-
            '{{ states.[light].attributes.brightness < 255 }}'
      - service: light.turn_on
        data_template:
          entity_id: '{{ light }}'
          brightness: '{{ states.[light].attributes.brightness + 1 }}'
      - delay: 
          seconds: 4
      - service: script.turn_on
        entity_id: script.generictransition 
        data_template:
          light: '{{ light }}'

What am I doing wrong here, specifically with the value_template.

  generictransition:
    alias: Generic Light Transition
    sequence:
      - condition: and 
        conditions:
          - condition: template
            value_template: "{{ states.light[lightname].attributes.brightness < 252 }}"
          - condition: state
            entity_id: group.family
            state: 'home'
      - service: light.turn_on
        data_template:
          entity_id: "{{ 'light.'~lightname }}"
          brightness: "{{ states.light[lightname].attributes.brightness + 3 }}"
      - delay: 
          seconds: 4
      - service: script.generictransition
        data_template:
          lightname: "{{ lightname }}"

This is my latest. It’s working up until I attempt to recursively call the script… any ideas why?

Any suggestions?

I figured it out, apparently you can’t call the script if it is already ‘on’ so I just need to call the script.turn_off service before recursively calling it again… Now I have a generic transition that works with all my dimmable lights…

  generictransition:
    alias: Generic Light Transition
    sequence:
      - condition: and 
        conditions:
          - condition: template
            value_template: "{{ states.light[lightname].attributes.brightness < 252 }}"
          - condition: state
            entity_id: group.family
            state: 'home'
      - service: light.turn_on
        data_template:
          entity_id: "{{ 'light.'~lightname }}"
          brightness: "{{ states.light[lightname].attributes.brightness + 3 }}"
      - delay: 
          seconds: 4
      - service: script.turn_off
        entity_id: script.generictransition
      - service: script.turn_on
        entity_id: script.generictransition
        data_template:
          variables: 
            lightname: "{{ lightname }}"

And you can trigger it for a specific light, like so:

  wakeup:
    alias: 'Lights - Wakeup'
    sequence:
      - service: script.turn_on
        entity_id: script.generictransition 
        data:
          variables: 
            lightname: 'bedroom_light'
1 Like

This had been working great but within the last update or two to HA it has stopped. The script seems to fire recursively as expected but the brightness does not increase… Anyone have any recommendations or thoughts?

I’m trying to create something similar: an automation whioch triggers on any scene activation but I’m struggeling with the entity_id part. Perhaps you can help me out?

- alias: 'Scene Activated Notification'
  trigger:
    platform: event
    event_type: call_service
    event_data:
      service_data:
        entity_id:  ### what do I have to put here so it will trigger on every scene activation?
      domain: scene
      service: turn_on      
  action:   
    service: tts.amazon_polly_say
    data_template:
      entity_id: media_player.home_group
      message: 'Scene Activated'
      cache: false

I would assume you could omit it since the domain should cover all scene entities.

Can you please explain? (sorry, semi-noob here ;))

I’m thinking something like this… But again, just a guess at this point.

  trigger:
    platform: event
    event_type: call_service
    event_data:
      domain: scene
      service: turn_on

That’s exactly what I have now but does not trigger, the “entity_id” part I added in my earlier post.

Any update on this? How did you solve all that?