I assign the value in a python_script depending of many factors.
The problem is when i reboot Home Assistant. The sensor is 1.0 again. Is there any way to get the last known value of this sensor before using the 1.0 value?
I try this:
value_template: "{{ 1.0 if value is none else value }}"
That’s not how template sensors are meant to work. Instead, the value_template should have all the instructions and rules to calculate the sensor value.
There is a potential workaround (i.e. I cannot guarantee that this will always work in the future):
You could create an automation that triggers when HA starts, and in its action use your Python script to update the sensor value.
Hey, I am new to HA, I am trying to do something similar but much more basic.
If the precipitation of the current day is > 90, I am showing that date (rain_last entity).
When the day changes and precipitation is <= 90, I would like to keep the value of the last day it was >90, but it shows empty because I haven’t put anything on the else condition.
I have looked into old_value but that is used automations. Is there anyway i can keep the old values (especially after a reboot) ? Thanks.
My recommendation in this case is to set up an input_datetime entity, and to then implement an automation that regularly checks the precipitation state and updates that input_datetime when precipitation is >90. This entity will restore its value after a reboot.