What is wrong with this

Hi can anyone help me with this. I don’t know what I am doing wrong here. Nothing happens when I restart hassio.

  • id: alarm_light
    alias: “Alarm Light”
    trigger:
    • platform: state
      entity_id: input_boolean.alarm_clock_status
      to: ‘on’
      condition:
    • condition: template
      value_template: “{{ now.time().strftime(’%-H’) == states.sensor.alarm_clock_hour.state and
      now.time().strftime(’%-M’) == states.sensor.alarm_clock_minute.state }}”
      action:
    • service: light.turn_on
      data:
      entity_id: light.living_room_light
      brightness_pct: 50
      rgb_color: [25, 250, 25]

That automation will fire if a boolean is switched on and at the exact time it is switched on the time matches a predefined time in a sensor.

At the very least I suspect your trigger and condition are the wrong way round, other than that, without knowing what you’re trying to do, and without being able to see the formatting of your code, we’re shooting blindly in to the wilderness with a blunderbuss.

Please reformat the automation using the appropriate editor function ( </> )

I guess there is something wrong with indentation.

  • id: alarm_light
    alias: “Alarm Light”
    trigger:
    • platform: template
      value_template: ‘{{ now.time().strftime("%-H") == states.sensor.alarm_clock_hour.state and now.time().strftime("%-M") == states.sensor.alarm_clock_minute.state }}’
      condition:
    • condition: state
      entity_id: input_boolean.alarm_clock_status
      state: ‘on’
      action:
    • service: light.turn_on
      data:
      entity_id: light.living_room_light
      brightness_pct: 50
      rgb_color: [25, 25, 25]

I tried using the </> but it still comes out like this. I know my indentation is correct, I do the hassio homeassistant check and it’s good but it just does not do anything when I restart.

Is the automation on?

Yes just check and it’s on.

OK, any errors in the logs?

If not, set the time to like 2 minutes from now and monitor the logs for errors, confirmation of trigger etc.

Shouldn’t it be now().hour and minute in the template? I don’t think now.time() is right, maybe now().time , but you want the hours and minutes.

And finally, wouldn’t a time sensor and an input_datetime be better still?

I set it for 17:27 hassio check good and hassio restart good but the light did not come on.

Repeating the questions you didn’t answer…

OK, any errors in the logs?

Shouldn’t it be now().hour and minute in the template? I don’t think now.time() is right, maybe now().time , but you want the hours and minutes.

And finally, wouldn’t a time sensor and an input_datetime be better still?

Hey your help is appreciated. I am a newby at hassio, I saw this on an example on the homeassistant.io page and decided to try it. I thought if the hassio check shows ok, then all would be fine.

Still haven’t answered the questions.

Best I can do is show you my fully working alarm clock package for my bedroom, which uses a time sensor, environmental data and presence data from elsewhere, but basically you set the time, and switch it on and then if we’re in it turns on the radio at the time specified and if its dark turns the lights on…

link removed

Thanks, I am going to play around and see what I come up with.

I got it worked out. I had all the stuff in front of me all this time and I just realized it. Thanks for the eye opener!!

1 Like