How to add transition to lights scene activation / automation?

Hi there,
I’m trying to make my Hue lights in the bedroom to fade on over 15 minutes in the morning, and fade to darkness over about an hour at night.

I have scenes set up to turn the lights off and on. I’ve read that it’s possible to use “transition” in some YAML code somehow to add transition length, but it’s unclear where I should add the code. I’ve tried reading through the docs, and looking up tutorials and in the forum, but it’s still unclear.

So what’s the easiest way to add a transition to a scene / group of lights being turned on / off? If it has to be done with YAML, then at least where exactly should the code go and can I at least edit the YAML through the HA interface?

Thanks for any help!

1 Like

You set it in the turn on call:

# Example automation
automation:
  trigger:
    platform: state
    entity_id: device_tracker.sweetheart
    from: "not_home"
    to: "home"
  action:
    service: scene.turn_on
    data:
      entity_id: scene.romantic
      transition: 2.5

Transitions are currently only support by lights, which in their turn, have to support it as well. However, the scene itself does not have to consist of only lights to have a transition set.

2 Likes

Thanks for the reply, Tinkerer!

I saw and read that documentation page before when I was researching. It just wasn’t clear where to put the code you quoted. When I tried adding it to the scene or the automation action (via the 3 dot overflow menu > Edit YAML) it just complains:

"Message malformed: extra keys not allowed @ data['transition']".

I didn’t see any reference to what file the code should be inserted into, on the scenes doc page though. So where do I actually add the code for the transition?

Wow.

His code literally says example automation at the top.

That code is directly copied from the docs.

Anything in the docs is written as if it went in configuration.yaml. When you’re applying to your own config you need to adjust for how it’s split up with your build.

As for the error, well, you have to share the YAML here so we can help you :wink:

Thanks! That was the key piece of info I didn’t see on the docs page linked to (although I’m sure it’s on another page, I just hadn’t seen yet).

It looks like my (default) configuration.yaml is a bit different as you mentioned, just linking in a number of other files including automation.yaml:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

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

Currently my automation.yaml looks like this:

- id: '1602321233356'
  alias: Good morning
  description: ''
  trigger:
  - platform: time
    at: 06:00
  condition: []
  action:
  - scene: scene.room1_lights_on
  mode: single

It doesn’t have any “service” or “data” sections. I tried adding “transition: 60” after the scene statement, ie:

  action:
  - scene: scene.zachary_s_lights_on
    transition: 60
  mode: single

…and after the trigger time:

  trigger:
  - platform: time
    at: 06:00
    transition: 60
  condition: []

…and at the end after the mode:

  mode: single
  transition: 60

…but when I save and choose “Reload automations”, all of these give me a notification that I have an error, and my automation disappears from the Automations GUI.

My automations.yaml file doesn’t have a data/service section, so I’m not sure if this format is deprecated and the docs haven’t been updated, or if I should be changing the format of my automations.yaml file to match… or possibly I should be adding the transition key to another file? (scenes.yaml?)

On a side note, thank you for being an exemplary role model for the community, by being welcoming and patient with a new community member who is trying to ask for help in the right way, but is still learning.

I hope to be equally helpful to other people here when I’ve learned enough to do so!

Always, always, do a command line config check after making changes, see here for details.

If you don’t get into the habit of doing that, at some point you’ll make a change that stops HA from starting, and there will be tears :wink:

That automation appears to have been created by the UI editor, based on what you selected. It has the minimal format required for that. If you’re going to manually edit it, it’s up to you to get the formatting right :wink:

I even provided the example from the docs in my first response:

  action:
    service: scene.turn_on
    data:
      entity_id: scene.romantic
      transition: 2.5

That’s what yours should look like, but with your scene name instead of scene.romantic

Everybody has something to learn, whether they realise it or not :wink: Sadly not everybody wants to learn.

1 Like

Trying to use transition with scenes.
action:
service: scene.turn_on
data:
entity_id: scene.home_door_closed
transition: 3

not working.

Just as @Tinkerer said here: How to add transition to lights scene activation / automation?

Transitions are currently only support by lights, which in their turn, have to support it as well. However, the scene itself does not have to consist of only lights to have a transition set.

You can’t use it for anything other than lights. If you are using it for a scene that controls lights, check to ensure that your light actually can utilize transitions. I have heard of a few that don’t honor transitions.

Thanks so much @Tinkerer ! It’s working! What it boiled down to was that the format of the code example in the docs looked different than what I was seeing in my yaml files, which had me thinking it wasn’t correct/up to date. In short, it was both, and now that I’ve followed your advice, it works fine with the following code in automations.yaml:

- id: '1602351233358'
  alias: Good morning
  description: ''
  trigger:
  - platform: time
    at: 06:00
  condition: []
  action:
  - service: scene.turn_on
    data:
      entity_id: scene.room1_lights_on
      transition: 600

Thanks again!

1 Like

A post was split to a new topic: Wondering the difference between ‘data’ and ‘target’