Retain last state of template binary sensor

By default, the template binary sensor will set its state to “unknown” before immediately setting the intended state. This is extremely annoying as it causes the logbook entry to be have this spam upon restarting Home Assistant:

In the case like I’ve described above, I would like for the last state to persist as to make the logbook entry (which I rely on) actually usable.

I’m replying to myself to clarify WHY I want to do it like this:

In my case, I’d like to keep track of when the certain appliances were turned on. I cannot control it via Home Assistant so a toggle does not make sense and I also want it to show up as a binary sensor of type power in the dashboard. The way the binary sensor currently works is by measuring the voltage and considering it “on” when the voltage is greater than 0.

What I mean to get at is this, the duplicate log entries are just a hindrance for my own ability to keep track of when the devices are on. Not something I rely on, in let’s say an HA automation.

You may ignore this feature request, switching to a template trigger sensor fixed it as that retains the last state.

It is in the docs:

The state, including attributes, of trigger-based sensors and binary sensors is restored when Home Assistant is restarted. The state of other trigger-based template entities is not restored.

Anybody can submit changes to the docs — don’t expect others to do it for you.

1 Like