StyraHem / ShellyForHASS

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

[BUG] Shelly em entity not showing in energy config #571

Open blair287 opened 3 years ago

blair287 commented 3 years ago

Environment

Describe the bug

Home assistant said to give this link to Dev for integration.

https://developers.home-assistant.io/docs/core/entity/sensor#long-term-statistics

Shelly em total consumption entity won't show in the options for the new energy option in HA.

Steps to Reproduce

Expected behavior

Screenshots

Traceback/Error logs

Additional context

scooper1 commented 3 years ago

The core Shelly integration works ok I ended up deleting this hacs version to use the core one

The integration has to be updated to show a reset time for power

wltng commented 3 years ago

The same goes for the temperature/humidity sensors in combination with the new statistics graph card. The are missing the state_class: measurement.

blair287 commented 3 years ago

The core Shelly integration works ok I ended up deleting this hacs version to use the core one

The integration has to be updated to show a reset time for power

The default Shelly integration doesn't allow decimal or other readings from the Shelly em

scooper1 commented 3 years ago

What reading is missing you have to enable some of them as not enabled by default . This hacs version is good but needs updating to work fully with 2021.8

Naesstrom commented 3 years ago

I made a little workaround to get my new 2.5 working with the energy settings, should be doable for any of them.

I'm using a package but you can do the same in the configuration.yaml if you want to. The trick is to add a customize to add the last reset, device class and state class.

homeassistant:
  customize:
    sensor.shelly_shsw_25_1_total_consumption:
      last_reset: "2021-07-30T00:00:00+00:00"
      device_class: energy
      state_class: measurement
    sensor.shelly_shsw_25_2_total_consumption:
      last_reset: "2021-07-30T00:00:00+00:00"
      device_class: energy
      state_class: measurement

Not sure what's better to use, the total consumption or current consumption but the process is the same on whatever sensor you want to add! :D

robinsmidsrod commented 3 years ago

I decided to use this template code in the developer panel to generate the list of all my shelly4hass customizations:

{% for state in states.sensor -%}
{% if state.entity_id is match("^sensor\.shelly_.+_total_consumption$", ignorecase=False) -%}
{{ state.entity_id }}:
  last_reset: "1970-01-01T00:00:00+00:00"
  device_class: energy
  state_class: measurement
{% endif -%}
{% endfor %}

Then it was just a matter of copy/paste into the customize location mentioned above. Worked like a charm!

Obviously it would be better if the shelly4hass integration supported this, but this is a useful workaround for now.

m-reuter commented 3 years ago

After the recent HA update to 2021.9 the last_reset is not necessary any longer. But device_class needs to be energy (currently it is power and that is simply wrong for a total amount) and state_class needs to be total_increasing. If HA detects a decreasing value, it will think that the device has been reset. This makes only sense for total consumption. E.g.:

homeassistant:
  customize:
    sensor.shelly_shplg_s_5b1234_total_consumption:
      device_class: "energy"
      state_class: "total_increasing"

A fix should be easy, just set the correct values in all total_consumption shelly entries.

rajil commented 2 years ago

@m-reuter After a power outage the total consumption is set to 0 (on my shelly PM2). So wouldnt it make more sense to have a state_class: "total".

m-reuter commented 2 years ago

No should be total_increasing . See https://developers.home-assistant.io/blog/2021/08/16/state_class_total/ . If the value shrinks, it will interpret it as an intermediate reset to zero, which is what we want.

wklholm commented 2 years ago

Will this feature be implementet into shelly for hass or should i migrate to the native shelly integration? It would be really nice to be able to add all my plygs to the energy dashboard.