Tim based automation does fires script, but does execute Boolean Toggle

I have a time-based automation that triggers every morning at 9:00. The purpose of this automation is to run a script. The script should check the current time, and if it’s past 9:00, the service call should execute. This check is necessary for my use case.

I followed various troubleshooting steps, such as running the automation separately and comparing entity entries before and after execution. The script always triggers on time, but the boolean does not change as expected. Additionally, I added a delay between the automation and the trigger to see if I had a timing issue, but this had no effect one way or the other. However, I can run either the automation or the script manually without any problems.

Here is the YAML for the automation:

alias: Craig Pill late automation
description: ""
trigger:
  - platform: time
    at: "09:00:00"
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: script.turn_on
    target:
      entity_id: script.craig_pill_late_script
    data: {}
mode: single

And here is the YAML for the script:

alias: Craig Pill Late Script
description: Script to turn on the Craig Pill Late boolean if the time is after 9:00 AM
sequence:
  - condition: template
    value_template: "{{ now().hour > 9 or (now().hour == 9 and now().minute > 0) }}"
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.craig_pill_late
mode: single

How can I effectively implement this time check in my script to ensure the boolean changes correctly and ensure the service call to Google Sheets executes properly?

Your condition in the script will be false when the automation triggers because the minute will not be greater than zero. (zero is not greater than zero).

You can remove the and now().minute > 0 clause or you can change the automation trigger to fire at 9:01.

Thanks for the quick reply, I will test. I not sure it it will work, as I have tested running the automation at 9:05AM, which is later than the subsequent script of 9:00AM.

Same result using less code:

  - condition: template
    value_template: "{{ now().hour >= 9 }}"

thanks, I will use that exact code.

The template was unnecessarily complex, when I changed it as suggested, the script fired as expected. Thanks

1 Like