I have a pool temperature sensor (pool_temp) lthat will only read the temperature if the pool pump is running. When the pump is not running, the temperature reflects unknown.
I want to create a custom temperature sensor (current_temperature) to avoid the reading of unknown
I created current_temperature sensor. The idea of the flow is to trigger on a change in pool_temp and pass that value to current_temperature unless the state of pool_temp = unknown.
The question is, how do I pass the value of pool_temp to current_temperature in node red?
It’s because you (generally) can’t change the state of a sensor
And why I asked where it came from.
What you’re trying to do is usually done in HA using something called a template sensor
(you’d create a second sensor based on the first sensor with the values you don’t want filtered out) and you want to do this as a template sensor in HA because it will stay available even if Node Red is down.
I thought about that, so I created the following template sensor, but then realized the actual sensor does not have a ‘last_known_temperature’ entity that I saw:
So, as an alternative, I thought about pushing the temperature from sensor.pool_temp to a new sensor that would always accept the temperature from sensor.pool_temp UNLESS the state = unknown
Exactly. You’re basically going do that same thing in the template sensor. Base it on a trigger (when your source data changes) and evaluate if you need to update the template data… If not, drop the update.
Think of it as I’m going to update myself only if I have a valid state from that…
When I run it through developer and register a temperature from sensor.pool_temp it reports accurate in developer.
However when I actually add the template, sensor.current_pool_temperature reports unknown when sensor.pool_temp is unknown and reports ‘unavailable’ when sensor.pool temp is NOT unknown.
Here is the automation:
alias: Update Current Pool Temp
description: “”
trigger:
- platform: state
entity_id:
- sensor.pool_temp
condition: []
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.current_pool_temperature
mode: single
Ok… Just walking myself through this. I made progress, but the template does not work as intended.
Since the sensor.current_pool_temperature always read ‘unavailable’, I updated the state to ‘99’ in the developer tab.
From what I can tell, when the sensor.pool_temp reads ‘unknown’, the sensor.current_temperature changes to ‘99’.
So for example:
If sensor.pool_temp is 90, then sensor.current_pool_temperature is also 90, however when sensor.pool_temp changes to unknown sensor.current_pool_temperature changes to 99 (which is what I manually entered), but I intend the sensor to read 90 (which was the sensor.pool_temp reading)