I have some sensors defined as below. My question is, why after a restart do they revert to a state of ‘unknown’ even if they had a value before the restart?
Err, yes but only the power and the power state. There is no way I am aware of to retain the firmware version. In fact to get it you have to publish to its topic.
state_topic: "stat/sonoff03/STATUS2"
value_template: >
{% if value_json.StatusFWR.Version != 'unknown' %}
It is based on the assumption that the state_topic’s message contains this JSON element: "Version": "unknown"
Maybe I’ve misunderstood how this works but wouldn’t this topic message contain "Version": "" when there’s no version information available? Faced with no available value, Home Assistant considers the value to be unknown.
The process is that the automation publishes to a topic with a payload that causes the Sonoff to respond with JSON which includes the element "Version": "firmware" where firmware is always a number such as 6.2.1
The sensor detects this and updates accordingly.
So you are absolutely right in that Version can never in fact be “unknown” so will never get to the else.
Thanks. I can’t believe how off my thought process was.