I am trying to create a template sensor that reports a bool if a timestamp state from another sensor is within 5 minutes of the current time. False if it is outside of that.
Essentially I just want the new sensor to say true if there’s been activity in the last 5 mins.
I have no idea how to handle timestamps within a template, can someone please help?
2022-10-15T23:24:29+00:00
Is an example of the state from the sensor I am utilising.
@@ The examples in this section will work as long as you pick an entity_id that includes an attribute that contains a time value. You can simply just pick any automation or script that has run recently:
That’s awesome! Thanks. Definitely going to read that post in detail.
I have added it to my configuration.yaml, but I get an error on checking.
# Sensor to detect if desktop PC in use last 5 mins
binary_sensor:
- platform: template
sensors:
Desktop_Active:
friendly_name: "Adams PC In-Use"
value_template: "{{as_timestamp(now()) + 300 > as_timestamp(states.sensor.adams_desktop_lastactive.last_changed) }}"