Hello,
I am struggling getting the last valid value from a sensor. What I mean is:
I’ve a sensor giving me the residual capacity of my printer toner
The sensor return: the value when printer is ON, unknown when is OFF
Then I would like to keep the last value got from the sensor when the printer is OFF
Do you have any suggestion?
Thanks in advance
Alessandro
123
(Taras)
February 14, 2021, 3:19pm
2
Replace sensor.actual_toner_capacity
with the name of your sensor (that reports residual toner capacity).
- platform: template
sensors:
toner_capacity:
value_template: >-
{% set tc = states('sensor.actual_toner_capacity') %}
{{ tc if tc != 'unknown' else states('sensor.toner_capacity') }}
If the sensor reports a value that is not unknown
, it becomes the new value for sensor.toner_capacity
.
If the sensor reports a value that is unknown
, then sensor.toner_capacity
retains its existing value.
6 Likes
SOLVED! Thank You Taras
Alessandro
123
(Taras)
February 14, 2021, 9:44pm
4
Alessandro_Bacioccol:
SOLVED! Thank You Taras
You’re welcome!
Please consider marking my post with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. Effectively, it indicates your question is resolved and helps users find answers to similar questions.