Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 105741

Putting sensors in separate YAML file leads to errors - template issue

$
0
0

I recently moved my sensors from configuration.yaml to a separate sensors.yaml because my config was getting crowded. I import sensors.yaml into my configuration.yaml.

Here’s an example of my old sensor configuration (converting m³ to liters):

- platform: template
  sensors:
    wasserverbrauch_haus_tag_in_liter:
      friendly_name: "Wasserverbrauch Haus Tag in Liter"
      unit_of_measurement: 'L'
      value_template: "{{ states('sensor.wasserverbrauch_haus_tag') | float * 1000 | round(0) }}"
    
    wasserverbrauch_haus_monat_in_liter:
      friendly_name: "Wasserverbrauch Haus Monat in Liter"
      unit_of_measurement: 'L'
      value_template: "{{ states('sensor.wasserverbrauch_haus_monat') | float * 1000 | round(0) }}"
    # Similar definitions for other sensors...

After establishing my sensors.yaml I received the error that my entities (water) don’t have a state class anymore. So I added device_class and state_class accordingly:

device_class: water
state_class: measurement

However, that led to another error saying my config was invalid. I was advised to change the structure like this:

template:
  - sensor:
      - name: "Wasserverbrauch Haus Tag in Liter"
        unit_of_measurement: 'L'
        device_class: water
        state_class: measurement
        state: "{{ states('sensor.wasserverbrauch_haus_tag') | float * 1000 | round(0) }}"

But I still receive an error, likely due to the template structure.

How can I properly configure my water sensors and retain the historical data?

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 105741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>