I have PIR sensor in my living room which sends movement detection status via MQTT. Now I am trying to show the time when the presence has been detected the last time by using the template sensor. My template sensor currently looks like this:
When PIR sensor is in the ‘on’ state, the state of livingroom_lastmove sensor is shown correctly but as soon as PIR changes to ‘off’ I lose the state of livingroom_lastmove.
How should I configure this in order to preserve the template sensor state?
I don’t currently have the time to confirm it but I believe you are correct. I have a foggy recollection of attempting something similar with a template sensor and encountered a problem.
In your case all you need to do is change the template. It appears all you want this Template Sensor to report is the last time motion was detected in the living room. That information is stored in the binary_sensor’s last_changed property.