Last Active within certain time frame to report true

Hi,
Templating noob here.

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.

Try something like this

{{as_timestamp(now()) + 300 > as_timestamp(states.input_boolean.dishwasher_running.last_changed) }}

the +300 is number of seconds in 5mins

Thank you, The sensor I am getting the info from isn’t a bool though. This is the sensor here

try something like this

{{as_timestamp(now()) + 300 > as_timestamp(states.sensor.adams_desktop_lastactive.last_changed) }}

Look for this section a few pages down

@@ 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) }}"

Us the Template section in Developer Tools to test it out rather that straight into yaml files.

First thing I did, it reported true/false correctly. But when I put it into the yaml I got this error.

EDIT: Figured it out, had capital leters in the sensor name when I shouldn’t have