StyraHem / ShellyForHASS

Shelly smart home platform for Home Assistant
MIT License
619 stars 111 forks source link

[FR] Shelly integration doesn't support statistics #586

Open bigboban opened 2 years ago

bigboban commented 2 years ago

Is your feature request related to a problem? Please describe.

Few weeks ago HA introduced statistics card: https://www.home-assistant.io/lovelace/statistics-graph/. But it displays only "supported" entities. Temperature sensor on Shelly is not listed and i think problem is there: https://www.home-assistant.io/more-info/statistics/.

Describe the solution you'd like

Please implement statistics support for temperature entities.

Describe alternatives you've considered

Additional context

Tuxie commented 2 years ago

I have this in my configuration.yaml as a workaround for this:

homeassistant:
  customize_glob:
    "sensor.shelly_*_total_consumption":
      last_reset: "1970-01-01T00:00:00+00:00"
      state_class: total_increasing
      device_class: energy

But there is still a bug where it sometimes reports 0 for a measurement or two and then back to whatever it was before, causing the energy integration to believe that it used hundreds (the correct total value) of kWh during that moment, so I also need to find some way to filter out those wrong measurements where kWh=0.

Wassini commented 2 years ago

I have also added current consumption and temperature:

homeassistant:
   customize_glob:
     sensor.shelly_*_total_consumption:
       last_reset: '1970-01-01T00:00:00+00:00'
       state_class: total_increasing
       device_class: energy
     sensor.shelly_*_current_consumption:
       state_class: measurement
       device_class: power
     sensor.shelly_*_temperature:
       device_class: temperature
       state_class: measurement
bcutter commented 2 years ago

I have also added current consumption and temperature:

homeassistant:

   customize_glob:

     sensor.shelly_*_total_consumption:

       last_reset: '1970-01-01T00:00:00+00:00'

       state_class: total_increasing

       device_class: energy

     sensor.shelly_*_current_consumption:

       state_class: measurement

       device_class: power

     sensor.shelly_*_temperature:

       device_class: temperature

       state_class: measurement

Wow, didn't know this is possible. It's like a template which customizes all entities matching the entity ID right? Quite powerful, thanks 👍🏼

skynan22 commented 2 years ago

I added the sensors above as described - it works fro me too. Is there an example available how to add binary sensor attribute(s)?

homeassistant: customize_glob: sensor.shelly_shplgs_total_consumption: last_reset: '1970-01-01T00:00:00+00:00' state_class: total_increasing device_class: energy sensor.shelly_shplgs_current_consumption: state_class: measurement device_class: energy binary_sensor.shelly_shplgs_over_power: state_class: ??? device_class: ??? binary_sensor.shelly_shplgs_over_temp: state_class: ??? device_class: ??? sensor.shelly_shplgs*_device_temp: device_class: temperature state_class: measurement

bcutter commented 2 years ago

I have also added current consumption and temperature:

homeassistant:
   customize_glob:
     sensor.shelly_*_total_consumption:
       last_reset: '1970-01-01T00:00:00+00:00'
       state_class: total_increasing
       device_class: energy
     sensor.shelly_*_current_consumption:
       state_class: measurement
       device_class: power
     sensor.shelly_*_temperature:
       device_class: temperature
       state_class: measurement

@Wassini Can you please explain what this does? What is customize_glob? Is this within customize.yaml? It's interesting to know customization is possible "globally" by using wildcards - but I don't get your syntax.

Wassini commented 2 years ago

There are 3 ways to customize: customize, customize_domain and customize_glob: https://www.home-assistant.io/docs/configuration/basic/

_glob uses wildcard to pick the entities.

My syntax just tells that all sensors that can be found with "sensor.shelly_*_total_consumption" is 'reclassified" as an energy device.