Hi,
I am combining some humidity and temperature sensor entities together, so that their values become attributes of one single sensor. The config looks like this:
- trigger:
- platform: state
entity_id:
- sensor.rht_sensor_temperature_kitchen
- sensor.rht_sensor_humidity_kitchen
- binary_sensor.rht_sensor_problem_kitchen
sensor:
- name: "RHT Sensor Combined (Kitchen)"
unique_id: rht_sensor_combined_kitchen
unit_of_measurement: "°C"
state_class: measurement
device_class: temperature
state: "{{ states('sensor.rht_sensor_temperature_kitchen') }}"
availability: "{{ states('sensor.rht_sensor_temperature_kitchen') not in ['unavailable', 'unknown', '', None] }}"
attributes:
temperature: "{{ states('sensor.rht_sensor_temperature_kitchen') }}"
humidity: "{{ states('sensor.rht_sensor_humidity_kitchen') }}"
status: >-
{% if is_state('binary_sensor.rht_sensor_problem_kitchen','on') %} DOWN
{% else %} OK
{% endif %}
You can see there is also a binary sensor which just indicates whether the sensor is still alive or not.
The problem is that when the sensor dies, the values of the source sensors change to “unavailable”, and therefore so does the combined sensor. This is fine, but when this happens, the attributes of the combined sensor are simply missing. See this screenshot, which shows the result for a working sensor and a broken sensor:
I would like the attributes to still be present (and show something like NaN, NaN, and DOWN for the humidity, temperature, and status).
Can this be done?