I have a sensor.work_travel_time setup using Waze and I would like to setup an alert when the travel time is greater than 20 minutes so that I can make it to work early. So I need to be alerted with about 20 minutes of notice meaning that the alert needs to be 20 minutes greater than the travel time and I need to be at work at 8:00. So if all of the sudden the travel time is 30 minutes I need to be alerted at 7:10.
How would I make an automation using those requirements?
I was thinking of creating a new Leave announcement time sensor that uses sensor.work_travel_time but adds 20 minutes. Then if that sensor is greater than 40 then it triggers an automation at 8:00 minus the Leave sensor time.
How would I create that automation? I get stuck trying to figure out how to make the Leave announcement time sensor and how to make the trigger for the automation greater than 40. Do I need to add an input boolean?
Thanks, that’s something I can base the final alert on. I need to think about a condition for between which times to announce the alert. Since I am adding 20 minutes to drive time and normal drive time is about 17-19 minutes then latest I can get the announcement and be on time is about 7:20. So the earliest I want the announcement is what I need to figure out next. I think I will have to add a Choose in order to make the announcement in the bedroom between certain times and the kitchen after a certain time.
I also need to add the travel time as part of the announcement but I have figured out how to do that.
I will use Time Pattern of /5 minutes for the Trigger and a condition of Time between 6:30 and 7:30 so that it will nag every 5 minutes between those times if both conditions are met.
How do I make a Leave Sensor that does a calculation of Leave Time = 8:00-Travel Time? The following doesn’t work
{% set travel_time_in_minute = states("sensor.work_travel_time")|int %}
{% set target_time = now().replace(hour=8).replace(minute=0).replace(second=0) %}
{{ as_timestamp(target_time) - (travel_time_in_minute)*60}}
I want to use the Leave Sensor as part of the alert and maybe as part of the condition
I get TypeError: unsupported operand type(s) for -: 'float' and 'str' on both of those. I searched Google for a possible fix but I can’t find one. Any ideas what I can add or change to remove the error?
Thanks. I see now that koying had it correct but I was just changing what I thought was the only difference instead of the whole line.
So what I learned is that I always need to place the whole calculation within parentheses even if there is a conversion after the calculation. I hope I can remember that or at least remember to be come back here to find that information. Is the need for parentheses documented somewhere so I can maybe reference that also?
This is as close as a jinja2 reference you can get, I guess.
Not sure if everything is implemented in HA,.but I’m sure HA added multiple functions/filters