Automation, Action - to do time

I have a sensor, checking something once an hour, triggering an automation.

How do I get the automation to only do the action at a certain time?

Meaning, if the automation goes off this morning at 09:00, I want the notification 10:00 this morning. If the automation goes off at 11:00 or 13:00, I want the notification at 10:00 in the morning next day.

Either there is some command that can be uses (do_time: ‘10:00:00’) or some delay calculation template?

Please advise.

action:
service: notify.ios_toms_iphone_6
data:
do_time: ‘10:00:00’ ???
title: ‘HA - Information’
message: ‘It has happened.’

Does it always have to happen at 10AM?

If so, just have the automation turn on an input_boolean and then everyday at 10am, if the input_boolean is on, send the message. After the message is played, just have an automation turn off the input_boolean.

With this approach, you would be notified at 10AM if the condition was met just as you have it outlined above. For instance, if the condition was met at 9:35AM, you would be notified at 10AM that same day. Even further, if the condition was met at 5PM, you would be notified at 10AM the next day.

Should be easy to implement. Let me know if you need any help.

Total N00b here. So your reply is helpful.
I’ll try it out.

Let us know how you get along. if you run into any issues, we should be able to smash through them. Don’t worry about the N00b thing. You’ll be up and flying pretty quick!

The workaround with the Boolean and two automations worked fine. Thanks!

I am still hoping to get it work with one automation. To make it easier for myself, let’s say I only want to delay the automation action to tomorrow at 10:00 hours.

  • alias: Test Notification
    initial_state: ‘on’
    trigger:
    platform: state
    entity_id: input_boolean.test_done
    from: ‘off’
    to: ‘on’
    action:
    • service: input_boolean.turn_off
      data:
      entity_id: input_boolean.test_done
    • delay: ‘Calculate hours to tomorrow at 10:00’
    • service: notify.me
      data_template:
      title: ‘HA - Information’
      message: “Test Notification”

I can’t wrap my head around timestamp/script. Can something like this work ?

delay: {{ (as_timestamp(now()) + (24*3600)) (set to 10:00 a clock) - (as_timestamp(now()) }}

UPDATE:
What about this pseudocode, can anyone shed some light on this. trying to trigger between to times and when boolean is true?

trigger:
platform: template
value_template: ‘{{ ( “09” < now().hour < “21” ) AND input_boolean.test_don == “on” }}’
true
{% endif %}

I gave up doing this with one automation. At least it works using two.
To other N00bs out there who don’t want to be awakened in the middle of the night by HA update notification, set your own time.

  • alias: HA Update Available Boolean Set
    initial_state: ‘on’
    trigger:
    platform: state
    entity_id: sensor.ha_upstream
    action:

    • service: input_boolean.turn_on
      data:
      entity_id: input_boolean.ha_update_received
  • alias: HA Update Available Notification
    initial_state: ‘on’
    trigger:

    • platform: time
      at: ‘09:00:00’
    • platform: time
      at: ‘21:00:00’
      condition:
      condition: state
      entity_id: input_boolean.ha_update_received
      state: ‘on’
      action:
    • service: input_boolean.turn_off
      data:
      entity_id: input_boolean.ha_update_received
    • service: notify.me
      data_template:
      title: ‘HA - Information’
      message: ‘HA update ({{ states.sensor.ha_upstream.state }}) is available.’
1 Like

I’ve never gone that far with time based templates, so I probably wouldn’t be of much help there. I think that the way you set it up will still be the best as I’ve never had much luck with a reliable template based trigger. Some people don’t have that experience, but I can’t for the life of me get template based triggers to be reliable without frequent service restarts to keep the timer in sync.

I think you did it best with your solution, and if it’s working, I’d stick with it.