barleybobs / homeassistant-ecowater-softener

A Homeassistant custom component to integrate Ecowater water softeners
https://github.com/barleybobs/homeassistant-ecowater-softener
MIT License
31 stars 9 forks source link

Sensor statistics #22

Closed matebenyovszky closed 1 year ago

matebenyovszky commented 1 year ago

Home assistant has a new statistics feature, but the entities should have the right properties. Would you please consider reviewing this? https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics

To opt-in for statistics, the sensor must have state_class set to one of the valid state classes: measurement, total or total_increasing. For certain device classes, the unit of the statistics is normalized to for example make it possible to plot several sensors in a single graph.

matebenyovszky commented 1 year ago

It would e also nice to generate unique_id -s for the sensors :) so they would be presented automatically 😊

This entity ('binary_sensor.ecowater_status') does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.

matebenyovszky commented 1 year ago

OK I realized that I can do this in my sensors:

template:
  - sensor:
      #Weather
      - name: "Weather forecast temperature"
        unit_of_measurement: '°C'
        state: "{{ state_attr('weather.homed168', 'temperature') }}"
      #Ecowater Softener
      - name: "Ecowater - Days until out of salt"
        unique_id: ecowater_days_until_out_of_salt
        state: "{{ state_attr('sensor.ecowater_x', 'days_until_out_of_salt') }}"
        icon: mdi:calendar-end
        device_class: duration
        unit_of_measurement: 'day(s)'
      - name: "Ecowater - Out of salt on"
        unique_id: ecowater_out_of_salt_on
        state: "{{ state_attr('sensor.ecowater_x', 'out_of_salt_on') }}"
        icon: mdi:calendar-today-outline
      - name: "Ecowater - Salt level"
        unique_id: ecowater_salt_level
        state: "{{ state_attr('sensor.ecowater_x', 'salt_level_percentage') }}"
        unit_of_measurement: '%'
        icon: mdi:page-layout-header
        state_class: measurement
      - name: "Ecowater - Water used today"
        unique_id: ecowater_water_used_today
        state: "{{ state_attr('sensor.ecowater_x', 'water_used_today') }}"
        unit_of_measurement: 'l'
        icon: mdi:water-plus-outline
        device_class: water
        state_class: total_increasing
      - name: "Ecowater - Water used per day average"
        unique_id: ecowater_water_per_day
        state: "{{ state_attr('sensor.ecowater_x', 'water_used_per_day_average') }}"
        unit_of_measurement: 'l'
        icon: mdi:water-percent
        device_class: water
        state_class: total
      - name: "Ecowater - water available"
        unique_id: ecowater_water_available
        state: "{{ state_attr('sensor.ecowater_x', 'water_available') }}"
        unit_of_measurement: 'l'
        icon: mdi:waves
        device_class: water
        state_class: total