Hello!
I want to define the used physical temperature sensor(s) of a template sensor just once in the attributes
section to prevent errors when changing the physical sensors. So I created following:
template:
-
sensor:
-
name: radiators_bath_min_temp
unit_of_measurement: °C
device_class: temperature
state_class: measurement
attributes: # This defines the involved sensors.
physical_temp1: sensor.th03_temperature
physical_temp2: sensor.th05_temperature
availability: >-
{{
not is_state(this.attributes.physical_temp1, 'unavailable') and
not is_state(this.attributes.physical_temp2, 'unavailable')
}}
state: >-
{{ [states(this.attributes.physical_temp1)|float,
states(this.attributes.physical_temp2)|float] | min }}
In principle this works fine, but I get an error message in the logs at each HA startup, that physical_temp1
and physical_temp2
are undefined.
I read, that the states section is performed before the attributes section, which would explain this behaviour. But I have also read, that availability section is performed before state section, which would not explain this (in my understanding exactly this case is the reason for the availability section?!).
I also tried to use a default value in the state
state: >-
{{ [states(this.attributes.physical_temp1)|float(0),
states(this.attributes.physical_temp2)|float(0)] | min }}
but this has disadvantages:
- There is still an error message in the logs
- There are several seconds with a wrong value which could trigger automations.
What I would like to have:
- Until
physical_temp1
andphysical_temp2
are undefined, the state ofradiators_bath_min_temp
should be undefined, too. - There should be no error message in the logs at startup.
Any ideas?
2 posts - 2 participants