Trouble Configuring Numeric State Time Based Trigger

Hello,

I am new to HA and I’m just tying up the last few loose ends of my conversion. I’ve tried to trigger automations based on an input date/time but I cannot figure out the magical combination to make the trigger fire the way I want. My input automations are solid and they update the timestamp appropriately. Its the firing of subsequent automations based on how old that input datetime is that’s giving me the trouble.

I’ve looked at dozens of threads, videos, and the docs but this all seems overly complicated for such a simple thing.

I just want this automation to fire when the date/timestamp is greater than “X”. Whether it’s 10 seconds or 10 days, I feel like I’ve tried every combination of these settings and I can’t get any of them to work:

What attributes do I need to fill out (nothing I use seems to make sense) and what value template should I be using?


I’m nowhere near as good on the backend as some of you but I’m fully capable of copying/pasting yaml if I need to :grinning:

Can you go to Developer Tools / States and copy the state of your input_datetime and paste it here please?

I suspect you will need a value_template to convert the state to a number.

Also I’m not sure what you mean by this:

Do you mean when the current time is 10 seconds grater than the input_datetime?

The intent of the calculation would be to get 10 seconds/days after the timestamp.

Its just a counter to keep track of robot vacuum filters, and other device maintenance cycles but I need something more robust than just a simple timer incase of restarts/power outages.

Ok, try this:

trigger:
  platform: template
  value_template: "{{ states('input_datetime.test_last_timestamp')|as_datetime + timedelta(seconds = 10) > now() }}"

or for 10 days:

trigger:
  platform: template
  value_template: "{{ states('input_datetime.test_last_timestamp')|as_datetime + timedelta(days = 10) > now() }}"

Note that these templates will only be checked every minute, so your 10 second version may be up to 50 seconds late.

How are you setting the input datetime?

If you could add the offset when setting it, e.g.

action:
  - service: input_datetime.set_datetime
    target:
      entity_id: input_datetime.test_last_timestamp
    data:
      datetime: "{{ now() + timedelta(days = 10) }}"

Then you could use a time trigger to trigger at the exact time:

trigger:
  platform: time
  at: input_datetime.test_last_timestamp

10 seconds was only an example that I was using to test. The rest will all be in terms of 10+ days.

I will try this now. Thanks

The date is being set by an input switch. When I tell Alexa to turn on 3rd floor filter reminder. she flips the switch which sets the timestamp that this automation will notify me that 14 days has past since the last timestamp

So Alexa sets a switch that then triggers an automation to set the input_datetime?

the switch triggers an automation to set the date time helper. then another automation counts time and alerts me if it hasn’t been updated.

I may have made this more complicated than it needed to be. I came from webcore and this was all done with virtual switches.

At the end of the day this is what I want:
A way to trigger the date stamp with my voice
At noon each day, if datestamp is older than 14 days, notify me (so i’ll get a message each day until I do it)

Right. Then change that to include the offset, like this:

action:
  - service: input_datetime.set_datetime
    target:
      entity_id: input_datetime.test_last_timestamp
    data:
      datetime: "{{ now() + timedelta(days = 10) }}"

Then you can use an exact and simple trigger:

trigger:
  platform: time
  at: input_datetime.test_last_timestamp

I could suggest a simpler method than using a switch, but having the switch has its advantages. e.g. You can tell if the reminder has be set.

I went with option 2 because that makes more sense and removes a step. I ran a test in 10 seconds and it worked. So with that, I’m going to try tying everything else together that is on a timeline of days/weeks.

Thanks you for the help!

1 Like

Unintended funny consequence:
2022-01-21 13_48_54-Greenshot
The way I had these labeled no longer makes sense. Purely cosmetic and easy to fix; just something funny that I didn’t think about.