Trigger an automation by changing time

I’m having an issue getting an automation to fire when I change the time on a datetime.

It works ok for boolean type entities but does not seem to be triggering datetime time entries, Im using the ‘state’ trigger but maybe thats not the right one, numeric_state does not seem to work either.

I’m still learning so sorry if this seems like a dumb question

TIA

- alias: Irrigation - Set Next Run Time When Schedule Enabled Or Time Changed
   trigger:
     - platform: state
       entity_id:
         - input_datetime.cycle_1_on_time
         - input_datetime.cycle_2_on_time

Did you build this in the UI automation editor?

No, its a separate file in a packages folder,

Ok. The UI editor mangles lists.

I don;t see anything wrong with what you have posted. It should trigger whenever you change either input datetime.

Maybe it triggers and is held up by a condition?

Have you looked at the automation trace?

To enforce what Tom says, it will only trigger when the input datetime change.

If you further want it to run when “Time Changed”, as in you comment, you should also add a time pattern trigger. See

hmm does not look like I can do that on a non UI created automation

Add a time pattern trigger?

Yes you can.

I’m doing this but it seems to break it.

      - platform:  state
        entity_id:
          - input_datetime.cycle_1_on_time
          - input_datetime.cycle_2_on_time
        minutes: "*"

Yeah want it to run any time the time gets changed, doesnt have to be for a specific time

You’re using the wrong type of trigger. What you want is a Time Trigger, not a State Trigger.

   trigger:
     - platform: time
       at:
         - input_datetime.cycle_1_on_time
         - input_datetime.cycle_2_on_time

It will trigger at the times specified by the two input_datetimes, even if you change their values.

On the other hand, if you only want it to trigger when you modify the value of either input_datetime, but not trigger at the specified times, then I don’t believe that’s possible with a State Trigger. Maybe you can try using a Template Trigger to monitor the input_datetime’s last_changed property. EDIT: you can in fact use a State Trigger (see below).

EDIT

I just confirmed that you can indeed use a State Trigger to detect when an input_datetime’s state value has changed. I tested three different kinds of input_datetimes, time-only, date-only, time-and-date, and changing any one them caused the automation’s State Trigger to trigger.

- alias: input_datetime_monitor
  trigger:
  - platform: state
    entity_id:
    - input_datetime.test_time
    - input_datetime.test_date
    - input_datetime.test_time_and_date
  action:
  - service: notify.persistent_notification
    data:
      title: input_datetime_monitor
      message: Changed!

I’ve just done an isolated test and it does appear to work fine, the problem must be in the action side of things so I will look into that.

thanks for the help everyone.

1 Like