Hallo Zusammen,
kann man Macros mehrfach verwenden und wie fühge ich es in .yaml ein?
Anbei ein Beispiel bei dem ich die absolute Luftfeuchtigkeit berechne das Macro absolute_humidity(temp,hum) kommt mehrfach vor. Es funktioiert ist aber nicht schön. ![]()
Danke und viele Grüße
Alfka1974
- unique_id: '1676458785'
unit_of_measurement: g/m³
default_entity_id: sensor.heq0133096_humidity_abs
icon: mdi:water
name: HM-CC-TC HEQ0133096 HUMIDITY_ABS
state: >-
{% macro absolute_humidity(temp,hum) -%}
{% if states(hum)|float==0 or states(temp)=='unknown' -%}
'unknown'
{%- else %}
{{ (states(hum)|float * 6.112 * 2.1674 * e**((states(temp)|float*17.67)/(states(temp)|float+243.5)) / (states(temp)|float+273.15))|round(2) }}
{% endif %}
{%- endmacro %}
{{ absolute_humidity("sensor.heq0133096_temperature", "sensor.heq0133096_humidity") }}
- unique_id: '1676458786'
unit_of_measurement: g/m³
default_entity_id: sensor.hm_cc_tc_jeq0061032_humidity_abs
icon: mdi:water
name: HM-CC-TC JEQ0061032 HUMIDITY_ABS
state: >-
{% macro absolute_humidity(temp,hum) -%}
{% if states(hum)|float==0 or states(temp)=='unknown' -%}
'unknown'
{%- else %}
{{ (states(hum)|float * 6.112 * 2.1674 * e**((states(temp)|float*17.67)/(states(temp)|float+243.5)) / (states(temp)|float+273.15))|round(2) }}
{% endif %}
{%- endmacro %}
{{ absolute_humidity("sensor.hm_cc_tc_jeq0061032_temperature", "sensor.hm_cc_tc_jeq0061032_humidity") }}