Movement last x minutes template for motion sensor doesnt work

- platform: template
  sensors:
    bathroom_motion_last10:
      value_template: >- 
       {{ (as_timestamp(now())- as_timestamp(states.binary_sensor.bathroom_motion.last_changed)) < 600 }}
      friendly_name: Motion in Last 10min
      device_class: motion

This template seems to alway report true/detected even though I have verified thru dev-template that {{ (as_timestamp(now())- as_timestamp(states.binary_sensor.bathroom_motion.last_changed)) < 600 }} is false.

Does anyone have any ideas? Thanks!

1 Like

you need to have the template update peroidically. add the sensor.time component and then add that to your template. It will update on the minute at that point.

Also, read this blurb

Alright! that did the trick! Thanks for the help!

I think we may be trying to do the same thing (see when a motion sensor was activated then create a binary switch to be on for x minutes), so I’d love to see your finished code for this.

Care to share?

Thanks.

P.s. Whenever you find an answer to a question it’s always really helpful to post your solution since people may end up coming here from a search, even years later. :wink:

2 Likes

he added entity_id: sensor.time to what he originally posted. Helps if you read the thread :wink:

Yes, thanks. I found that just a short while ago, and got it working.

P.s. I did read the thread and whilst it mentions sensor.time it doesn’t actually give any specifics as to how or where that should be placed. :wink:

1 Like

It’s in the second link in the post I wrote. Links directly to this:

So… apparently you just skimmed? :wink:

Ok pal, you’re the best. Have an awesome day! :wink:

P.s. As I said, there were no specifics mentioned, just generalisations. :wink:

1 Like

Agree, it would be ideal if TS could post a working solution.
Just in case for the future readers, the bit with good examples is here.

3 Likes

I don’t see how there wasn’t an exact answer. I said:

That’s an exact answer. Period.

This was a rough thread to read through. I have questions, but I’m not about to ask as I’m sure I’ll be derided.

1 Like

This thread is ancient and much of its advice is outdated. If you have questions, please start a new thread as opposed to resurrecting a dead one.

1 Like