Splitting configuration.yaml sensor.yaml (absolute humidity)

Hi all,

i wanted to calculate the absolute humidity of multiple sensors (based on zigbee-flashed LYWSD03MMC), but not use the thermal comfort via HACS.

A quick seach of the internet an the homeassistant community resulted in a neat sensor template.
The strange thing is: Having it in the configuration.yaml everything seems to be fine, splitting it into sensor.yaml results in no entity, but also no error.

There may be a very simple solution; you would be great to share it with me.

Working (sensor in configuration.yaml):


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#sensor: !include sensor.yaml

template:
  - sensor:
    - name: "Absolute Luftfeuchtigkeit TEMP 2"
      unit_of_measurement: "g/m^3"
      state_class: "measurement"
      state: > 
            {{ ( 1000*e**(18.016-(4064.95/(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+236.25)))*100/(461.66*(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+273.15)) * float(states('sensor.temp_2_xiaomi_lywsd03mmc_luftfeuchtigkeit_2'))/100 | float) | round (2) }}
            

Not working (copy/paste from configuration.yaml and sensor.yaml)
configuration.yaml


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensor.yaml         

sensor.yaml

template:
  - sensor:
    - name: "Absolute Luftfeuchtigkeit TEMP 2"
      unit_of_measurement: "g/m^3"
      state_class: "measurement"
      state: > 
            {{ ( 1000*e**(18.016-(4064.95/(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+236.25)))*100/(461.66*(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+273.15)) * float(states('sensor.temp_2_xiaomi_lywsd03mmc_luftfeuchtigkeit_2'))/100 | float) | round (2) }}

Split it into template: !include template.yaml and paste the code there.

No luck, but no error message either (entity not showing). :frowning:

configuration.yaml:


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template: !include template.yaml

template.yaml

template:
  - sensor:
    - name: "Absolute Luftfeuchtigkeit TEMP 2"
      unit_of_measurement: "g/m^3"
      state_class: "measurement"
      state: > 
            {{ ( 1000*e**(18.016-(4064.95/(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+236.25)))*100/(461.66*(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+273.15)) * float(states('sensor.temp_2_xiaomi_lywsd03mmc_luftfeuchtigkeit_2'))/100 | float) | round (2) }}
            

You need to remove template: from the template.yaml. You have already defined that in the configuration.yaml. Make sure you indent correctly.

Thank you so much; this works like a charm!!

- sensor:
    - name: "Absolute Luftfeuchtigkeit TEMP 2"
      unit_of_measurement: "g/m^3"
      state_class: "measurement"
      state: > 
            {{ ( 1000*e**(18.016-(4064.95/(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+236.25)))*100/(461.66*(float(states('sensor.temp_2_xiaomi_lywsd03mmc_temperatur_2'))+273.15)) * float(states('sensor.temp_2_xiaomi_lywsd03mmc_luftfeuchtigkeit_2'))/100 | float) | round (2) }}
            

You are most welcome :slight_smile:

1 Like