This has got to be something stupid/simple I am just missing.
This is my template trigger:
- trigger:
- id: "Open"
platform: state
entity_id: binary_sensor.new_front_door_sensor_contact
from: "off"
to: "on"
- id: "Closed"
platform: state
entity_id: binary_sensor.new_front_door_sensor_contact
from: "on"
to: "off"
sensor:
- unique_id: sensor.new_front_door_last_open
device_class: timestamp
state: "{{ now() }}"
attributes:
open_close: "{{ trigger.id }}"
I want it to record the time the door was last opened or closed - which it does.
However, when I reboot HA, it resets that time to that startup for the âClosedâ id. But I have it qualified to only trigger if it goes from âonâ to âoffâ and âoffâ to âonâ. And I can see in the history that it goes âunknowâ during the reboot and then directly to âoffâ (Closed).
I see what youâre trying to do. My contact sensors are Zigbee devices and do the same âunknownâ during a restart.
However, maybe Iâm missing something in your screenshots, but, it looks like your Template Sensor is working, no? Looks like you are comparing the device âlast changedâ to your Template Sensor âlast changedâ, which are not the same; and your template sensor is retaining the information through a restart.
You have a template sensor with a state that records the time and date it last open/closed or closed/open, and then a tile card using that template sensor with the âlast changedâ as part of the attribute content.
While the contact sensor device reports unknown, and upon restart reports it is closed 6 minutes ago (after the restart), your Tile Card utilizing your Template Sensor still shows state changed 8 minutes ago, which I presume is before the restart you did; is this not what you want?
So while the sensor state change says 6 minutes ago, post-restart, your template sensor is still showing 8 minutes ago.
that or I havenât had enough coffee yet this morning heh
EDIT: can you confirm the state (i.e. date/time) of your Template Sensor before and after a restart
OMG. I knew I was doing something stupid!
Yes! I wanted âStateâ, not âLast Changedâ or âLast Updatedâ. Argh
Thank you!
I apparently need A LOT more Coffee!!!