Help needed with time templating

I suppose it would be easier to just compare the minutes, that probably can be done by extracting the minutes part of the srtring than turning it into integers and doing the math. Hower this will fail if the bus leaves lets say 12:05 and it is 11:59 …

still puzzled by why {{as_timestamp( strptime( now().strftime("%H:%M"), "%H:%M" ) )}} comes up empty.

Maybe this has to do with some kind of locale setting or the platform. I’m using hassbian on a raspberry pi. This is my locale:

locale
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

That I’m not sure of, I’m running a manual install on my OS X server so no experience with the rpi. If you break it apart does any part of the nesting resolve in the template viewer?

All but the as_timestamp is working…

I’m getting closer, but I still can’t get it to trigger when used as a trigger with an automation.

Here’s how I got the two times to evaluate correctly.

First made a sensor to calculate the time to leave. This returns todays date appended to the time to leave accounting for traffic.

sensors:
  -platform: template
   sensors:
     go_get_kids:
       value_template: '{{now().strftime("%Y") }}-{{now().strftime("%m") }}-{{now().strftime("%d") }} {{strptime("17:00", "%H:%M") -strptime(states.sensor.dad_work_to_daycare.state, "%M") }}'

This allows me to create a template that I can evaluate the “leave time” against now.

{{ as_timestamp(states.sensor.go_get_kids.state) | timestamp_custom("%H:%M") == as_timestamp(now()) | timestamp_custom("%H:%M") }}

The problem I am having is getting an automation from here to evaluate true. I have tried simply setting {{ as_timestamp(states.sensor.go_get_kids.state) | timestamp_custom("%H:%M") == as_timestamp(now()) | timestamp_custom("%H:%M") }} as a template trigger like this:

automation:
  trigger:
    platform: template
    value_template: '{{ as_timestamp(states.sensor.go_get_kids.state) | timestamp_custom("%H:%M")  == as_timestamp(now()) | timestamp_custom("%H:%M") }}'

but that doens’t work.

I then tried to create a binary sensor but that failed as well. If anyone can figure that out, we can piece together the other pieces to make this type of time templating possible.

You might try to create a new sensor to include the date on top of your bus sensor.
something like this:
{{now().strftime("%Y") }}-{{now().strftime("%m") }}-{{now().strftime("%d") }} {{ states.sensor.bus.state }}

Then try to work through how to alert based off of that. That’s where I am failing so I don’t have any recommendations there unfortunately.

Did you ever find a solution for this?
I have a similar problem.

I just gave up… sorry

1 Like

I ended up utilizing a different approach based off of a solution provided here:

Maybe you could try going that route as I gave up trying to utilize this method just as @snizzleorg did…