Automation working for notify, but not for entity_id

I have the following automation set up that SHOULD turn the lights in my kids room green at certain times to let them know that they can come out (either in the morning or from nap time). It hasn’t been working so I set up the notify action as well to see if my template was working fine. The notify action will send me the entity_id I want like it’s supposed to, but the automation is not triggering. If I set the variable to a static entity, it works fine. I’m thinking that the template returns a string, and the script is looking for something else, but I’m not sure what or how to convert it.

Automation:

- id: '1589220886910'
  alias: Kids Light Turns Green
  description: ' '
  trigger:
  - entity_id: sensor.time
    platform: state
    to: 06:45
  - entity_id: sensor.time
    platform: state
    to: '14:30'
  - entity_id: sensor.time
    platform: state
    to: '15:30'
  - entity_id: sensor.time
    platform: state
    to: '14:26'
  condition: []
  action:
  - data:
      variables:
        entity_id: {{ state_attr( {% if states.sensor.time.state == '06:45' %}'light.charlottes_light,light.justins_light'{%
          elif states.sensor.time.state == '14:30' %}'light.charlottes_light'{%
          elif states.sensor.time.state == '15:30' %}'light.justins_light'{% elif
          states.sensor.time.state == '14:26' %}'light.office_lamp'{% endif %} ) }}
    entity_id: script.1589220206391
    service: script.turn_on
  - data_template:
      data:
        push:
          thread-id: test
      message: '{% if states.sensor.time.state == '06:45' %}'light.charlottes_light,light.justins_light'{%
        elif states.sensor.time.state == '14:30' %}'light.charlottes_light'{%
        elif states.sensor.time.state == '15:30' %}'light.justins_light'{% elif
        states.sensor.time.state == '14:26' %}'light.office_lamp'{% endif %}'
      title: Test
    service: notify.mobile_app_brians_iphone

Script:

'1589220206391':
  alias: Kids Lights Turn Green
  sequence:
  - data_template:
      brightness: 1
      entity_id: '{{ entity_id }}'
    service: light.turn_on
  - data_template:
      color_name: green
      entity_id: '{{ entity_id }}'
    service: light.turn_on

You are missing a closing single quote here:

description: '

I’m surprised anything after that works.

Sorry, I actually have that closed quote in my actual automation, copy/paste failure. I will update my original post.

Anyone have any ideas?

Yes. Your templates are a mess. If you convert them to multi-line templates and apply some indentation to aid readability you should be able to see the problems.

For example, the open and close single quotes here:

message: '{% if states.sensor.time.state == '

If I change it to something like this it still doesn’t work.

- id: '1589220886910'
  alias: Kids Light Turns Green
  description: ' '
  trigger:
  - entity_id: sensor.time
    platform: state
    to: 06:45
  - entity_id: sensor.time
    platform: state
    to: '14:30'
  - entity_id: sensor.time
    platform: state
    to: '15:30'
  - entity_id: sensor.time
    platform: state
    to: '14:26'
  condition: []
  action:
  - data:
      variables:
        entity_id: "{% if states.sensor.time.state == '06:45' %}'light.charlottes_light,light.justins_light'{%
          elif states.sensor.time.state == '14:30' %}'light.charlottes_light'{%
          elif states.sensor.time.state == '15:30' %}'light.justins_light'{% elif
          states.sensor.time.state == '14:26' %}'light.office_lamp'{% endif %}"
    entity_id: script.1589220206391
    service: script.turn_on

Try it like this:

- id: '1589220886910'
  alias: Kids Light Turns Green
  trigger:
  - platform: time
    at: '06:45'
  - platform: time
    at: '14:30'
  - platform: time
    at: '15:30'
  - platform: time
    at:'14:26'
  action:
  - service: script.turn_on
    entity_id: script.1589220206391
    data_template:
      variables:
        entity_id: >
          {% if states.sensor.time.state == '06:45' %}
            light.charlottes_light,light.justins_light
          {% elif states.sensor.time.state == '14:30' %}
            light.charlottes_light
          {% elif states.sensor.time.state == '15:30' %}
            light.justins_light
          {% elif states.sensor.time.state == '14:26' %}
            light.office_lamp
          {% endif %}
'1589220206391':
  alias: Kids Lights Turn Green
  sequence:
  - data_template:
      brightness: 1   ### this is very dim, 255 = fully on.
      entity_id: '{{ entity_id }}'
    service: light.turn_on
  - data_template:
      color_name: green
      entity_id: '{{ entity_id }}'
    service: light.turn_on

OK, let me give that a shot. And I know it’s very dim, I only want it barely on so it doesn’t wake them up. Also sengled seems to have issues with transitions where the bulb has to be on before transition works. So I could turn it on to 1, then transition to 255 over 5 minutes or so if I wanted. If I go from off to 255 over 5 minutes, it instantly turns on.

Also, I tried the time trigger, but it seemed to be off by a few seconds from the states.sensor.time.state so it never actually triggered.

Yeah but depending on your light type you probably won’t even notice a brightness of 1.

These are sengled, and in a dark room during nap time you do notice a brightness of 1.

states.sensor.time.state Does not have seconds.

Yes, but if I have the trigger set to 15:30 using the time platform, states.sensor.time.state is still at 15:29. Maybe 10 seconds later or so it will actually change to 15:30 but by then the trigger has already been checked as false.

Ok, keep your original triggers then. Quote that fist time. Use data_template instead of data in your actions and see how it goes.

If you have a way to fix that I would rather use the time platform as it’s cleaner but it didn’t seem to work for me.

Did you just manually trigger the automation?

You have no else statement for that.

It worked! Thank you for helping me with my template formatting.