rogerdean
(Roger Dean)
September 10, 2025, 8:38am
1
Hi folks. I rely on cloud weather forecast sensors to run my heating. When they become unavailable, I’d like to use their ‘last known good’ data instead. So I think I’m asking -
How do I make a sensor to mirror the latest available data of another sensor?
Make sense? Thanks in advance
There’s an integration in HACS which allows you to save the old value each time a sensor changes:
Home Assistant variables component
1 Like
rogerdean
(Roger Dean)
September 10, 2025, 9:29am
3
Thanks Jack, I’ll try to figure that one out
An imperfect but easy and possibly still effective way (for my use case) might be to make a statistics helper sensor, averaging the source sensor’s output over, say, 48hours. So if the cloud sensor fails for a few hours or even a day, a relatively sane value would still be applied to turn my heaters on and off…
So now I need the sensor syntax - IF sensor A is unavailable, then sensor B
Any cleverer ideas still appreciated!
This would save the last valid value of the sensor:
alias: Test
description: ""
triggers:
- trigger: state
entity_id:
- sensor.yard_motion_sensor_light_level
to: null
conditions:
- condition: not
conditions:
- condition: state
entity_id: sensor.yard_motion_sensor_light_level
state: unavailable
- condition: state
entity_id: sensor.yard_motion_sensor_light_level
state: unknown
actions:
- action: input_number.set_value
metadata: {}
data:
value: "{{ states('sensor.yard_motion_sensor_light_level') }}"
target:
entity_id: input_number.test
mode: single
3 Likes
NathanCu
(Nathan Curtis)
September 10, 2025, 12:07pm
5
Dangit jack too fast.
Gotta use a trigger sensor so it retains state…
Jack’s sensor uses this methodology Weather - Home Assistant
A more concise version:
alias: Test
description: ""
triggers:
- trigger: state
entity_id:
- sensor.yard_motion_sensor_light_level
not_to:
- unknown
- unavailable
actions:
- action: input_number.set_value
metadata: {}
data:
value: "{{ states('sensor.yard_motion_sensor_light_level') }}"
target:
entity_id: input_number.test
mode: single
4 Likes
NathanCu
(Nathan Curtis)
September 10, 2025, 12:18pm
8
edits
I don’t know what you’re talking about (fat thumbs)
parautenbach
(Pieter Rautenbach)
September 10, 2025, 12:28pm
9
Another option is something like this:
template:
- trigger:
- platform: state
entity_id: sensor.some_sensor
sensor:
- name: "Some new sensor"
icon: ...
unit_of_measurement: ...
device_class: ...
state: "{{ trigger.to_state.state if trigger.to_state.state | has_value else trigger.from_state.state }}"
4 Likes
parautenbach
(Pieter Rautenbach)
September 10, 2025, 2:31pm
10
There are more options, out of interest. I think my version is probably the most modern version, but I quite liked Petro’s version here too.
2 Likes
rogerdean
(Roger Dean)
September 10, 2025, 5:25pm
11
Thank you everyone. I’m going to go with the first one I can understand and make work
2 Likes