Hi all,
I have a bunch of hygrometers I would like them all to extend them with template sensors (e.g. calculating the absolute humidity by taking in the relative humidity and temperature). I got this working so far with template sensors, but it’s a bit ugly I have to add such template sensor including all the code for calculation for each hygrometer.
But I noticed Blueprints and tried them. Documentation for Blueprints in combination with Templates is pretty basic (if at all) but got a Blueprint running for just adding an offset to a sensor value.
Problem now is that the unit of measurement from the used sensor is not used for the output of the blueprint. I tried to add the unit_of_measurement in the sensor section of the blueprint, but this does not work. Same applies to the icon.
I also tried to define it in the template, but this causes an error. See the following example:
Blueprint (value_correction.yaml):
blueprint:
name: Corrects a given sensor value by given offset
description: Creates a sensor which holds the corrected value of a reference sensor
domain: template
input:
reference_entity:
name: Sensor to be corrected
description: The sensor which needs to have its value corrected
selector:
entity:
domain: sensor
offset:
name: Numerical offset
description: Numerical offset added to the sensors value
variables:
reference_entity: !input reference_entity
offset: !input offset
sensor:
# this has no effect
unit_of_measurement: "%"
icon: mdi:water-percent
state: >
{% set h = states(reference_entity) | float %}
{% set o = offset | float %}
{{ h + o }}
availability: "{{ states(reference_entity) not in ('unknown', 'unavailable') }}"
configuration.yaml
template:
name: BLA
unique_id: bla
# here it causes an error
# unit_of_measurement: "%"
# icon: mdi:water-percent
use_blueprint:
path: homeassistant/value_correction.yaml # relative to config/blueprints/template/
input:
reference_entity: sensor.rel_humidity
offset: -4.5
Has anybody an idea of what I’m doing wrong? I would like to keep the unit out of the blueprint to keep it as versatile as possible.