This is a Zigbee temp sensor connected to my HA server.
Sometimes this sensor is unavailable.
Is it possible with a if unavailable, get values from another sensor in home assistant?
- platform: homeassistant # outside temperature
id: temperature_outside_1
if temperature_outside_1 is unavailable
use temperature_outside_2
entity_id: sensor.ute_temperature
accuracy_decimals: 0
internal: true
Add 2 homeassistant sensors in your esphome, one for temperature_outside_1 and another one for temperature_outside_2. Create a template sensor, use the lambda to select the sensor value based on its state.
Thank you.
It works like I hoped.
Is it easy to do the same if the value is older than 3 hours? Sometimes it takes a while before it is discovered af unavailable.
Believe that you can use a combination of sensors and sensor filters to achieve that. Personally I prefer a customer lambda expression which could be something like this:
What it does is: it stores the current tick count in a static var. Upon updating the sensor it checks if the state of temperature 1 is NAN, if so will immediately return temperature 2 value. Otherwise, when value is different than the stored value (initially set to NAN) then it stores the new value and updates the tick count. When last change was more than 3 hours ago, will also return temperature 2 value but when less than 3 hours, will return temperature 1 (= last known value).
Disclaimer: haven’t tried/tested this, it should work in theory… Let us know if this works.