I’m stuck a bit with stupid problem, maybe somebody here can help. Simple device built with ESP8266, two temperature sensors DS18B20 connected. Everything works well, my code:
sensor:
- platform: dallas
address: 0x7F000001509C8228
name: "Sonda 1"
id: sonda_1
- platform: dallas
address: 0x1c0000031edd2a29
name: "Sonda 2"
id: sonda_2
dallas:
- pin: D0
update_interval: 10s
display:
[...]
lambda: |-
if (id(sonda_1).has_state()) {
it.printf(1, 24, id(MSS_20), "%.1f °", id(sonda_1).state);
} else it.print(1, 24, id(MSS_20), "NA");
if (id(sonda_2).has_state()) {
it.printf(75, 24, id(MSS_20), "%.1f °", id(sonda_2).state);
} else it.print(75, 24, id(MSS_20), "NA");
Idea was simple: if sensor exists and is readable - sensor value is displayed, if not - displayed is “NA”. Unfortunately it doesn’t work as expected, because these sensors have always value, even if they are not connected. If sensor is not connected from the beginning - value is “nan” and it would be simple, I can detect this “nan” in if command. But when working sensor will be disconnected, situation is worse: still last measured value is frozen.
So, my question: how to verify such value or how to detect if sensor is present?