cyberjunky / home-assistant-toon_smartmeter

This component reads and displays sensor values from the meteradapter connected to a rooted Toon thermostat.
MIT License
27 stars 13 forks source link

Unsupported state class #40

Closed gerritjonker closed 2 years ago

gerritjonker commented 3 years ago

In pull request #37 the state_class total_increasing was removed but I have the following error:

Unsupported state class The state class of this entity, is not supported. Statistics can not be generated until this entity has a supported state class.

I think the state_class measurement should be added.

Value entities - entities not representing a total amount​

Home Assistant tracks the min, max and mean value during the statistics period. The state_class property must be set to measurement, and the device_class must not be either of energy, gas, or monetary

https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes

Ysbrand commented 3 years ago

I see the same issue for the following sensors:

sensor.toon_p1_power_use_low    De state class "" van deze entiteit wordt niet ondersteund.
sensor.toon_p1_power_use_high   De state class "" van deze entiteit wordt niet ondersteund.
sensor.toon_p1_power_prod_low   De state class "" van deze entiteit wordt niet ondersteund.
sensor.toon_p1_power_prod_high  De state class "" van deze entiteit wordt niet ondersteund.
The state class of this entity, is not supported.
Statistics can not be generated until this entity has a supported state class.

If this state class was provided by an integration, this is a bug. Please report an issue.
The different state classes and when to use which can be found in the developer documentation.

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

I've modified the following: Added STATE_CLASS_MEASUREMENT in the folowing sections:

from homeassistant.components.sensor import (
    PLATFORM_SCHEMA,
    STATE_CLASS_TOTAL_INCREASING,
    STATE_CLASS_MEASUREMENT,
    SensorEntity,
    SensorEntityDescription,
)
    SensorEntityDescription(
        key="elecusageflowlow",
        name="P1 Power Use Low",
        icon="mdi:flash",
        native_unit_of_measurement=POWER_WATT,
        device_class=DEVICE_CLASS_POWER,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    SensorEntityDescription(
        key="elecusageflowhigh",
        name="P1 Power Use High",
        icon="mdi:flash",
        native_unit_of_measurement=POWER_WATT,
        device_class=DEVICE_CLASS_POWER,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    SensorEntityDescription(
        key="elecprodflowlow",
        name="P1 Power Prod Low",
        icon="mdi:flash",
        native_unit_of_measurement=POWER_WATT,
        device_class=DEVICE_CLASS_POWER,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    SensorEntityDescription(
        key="elecprodflowhigh",
        name="P1 Power Prod High",
        icon="mdi:flash",
        native_unit_of_measurement=POWER_WATT,
        device_class=DEVICE_CLASS_POWER,
        state_class=STATE_CLASS_MEASUREMENT,
    ),

And that seems to make HA happy

cyberjunky commented 3 years ago

@Ysbrand thanks, can you try release 1.0.20?

Ysbrand commented 3 years ago

Thanks Ron, looks ok as far as I can determine.

screenagerbe commented 2 years ago

I encounter this error with release 1.0.20: Logger: homeassistant.components.sensor.recorder Source: components/sensor/recorder.py:314 Integration: Sensor (documentation, issues) First occurred: November 29, 2021, 19:15:10 (1 occurrences) Last logged: November 29, 2021, 19:15:10 Entity sensor.toon_gas_used_last_hour from integration toon_smartmeter has state class total_increasing, but its state is not strictly increasing. Triggered by state 1.375 with last_updated set to 2021-11-29T18:12:00.213004+00:00. Please report it to the custom component author.

Don't really know how to get this fixed (yet)

Ysbrand commented 2 years ago

Well, I did see this occurring once in my logs today as well, and I would say that total increasing is indeed not correct as this number will go up and down during the day.

cyberjunky commented 2 years ago

Closed for now, reopen if still an issue

freddieleeman commented 2 years ago

In my log today, so apparently still an issue.

Entity sensor.toon_gas_used_last_hour from integration toon_smartmeter has state class total_increasing, but its state is not strictly increasing. Triggered by state 1.586 with last_updated set to 2022-02-01T10:02:24.952853+00:00. Please report it to the custom component author.
djansen1987 commented 2 years ago

In my log today, so apparently still an issue.

Entity sensor.toon_gas_used_last_hour from integration toon_smartmeter has state class total_increasing, but its state is not strictly increasing. Triggered by state 1.586 with last_updated set to 2022-02-01T10:02:24.952853+00:00. Please report it to the custom component author.

Which version are you running of the component and HA ? Don't see the error in my setup. I am running 1.0.20

freddieleeman commented 2 years ago

HA 2021.12.10 / Toon Smartmeter 1.0.20

djansen1987 commented 2 years ago

could it be that you have set a manual customization for the state class in your configuration.yaml of customization.yaml ?

https://www.home-assistant.io/docs/configuration/customizing-devices/#unit_of_measurement

djansen1987 commented 2 years ago
homeassistant:
  customize_glob:
    sensor.*_total:
      last_reset: '1970-01-01T00:00:00+00:00'
      state_class: total_increasing
freddieleeman commented 2 years ago

I am unable to find any customization on the sensor. Here are the sensor attributes:

state_class: total_increasing unit_of_measurement: m³ device_class: gas icon: mdi:gas-cylinder friendly_name: Toon Gas Used Last Hour

djansen1987 commented 2 years ago

Mine is exactly the same, where do you see the error ?

state_class: total_increasing unit_of_measurement: m³ device_class: gas icon: mdi:gas-cylinder friendly_name: Toon Gas Used Last Hour

freddieleeman commented 2 years ago

a last hour sensor should not have a total_increasing state_class value.

/config/logs

Logger: homeassistant.components.sensor.recorder
Source: components/sensor/recorder.py:319
Integration: Sensor (documentation, issues)
First occurred: 11:05:10 AM (1 occurrences)
Last logged: 11:05:10 AM

Entity sensor.toon_gas_used_last_hour from integration toon_smartmeter has state class total_increasing, but its state is not strictly increasing. Triggered by state 1.586 with last_updated set to 2022-02-01T10:02:24.952853+00:00. Please report it to the custom component author.
djansen1987 commented 2 years ago

i see, makes sense but strange i don't get the warning. This is all i can do for now, maybe @cyberjunky knows the answer to this one

freddieleeman commented 2 years ago

Issue here: https://github.com/cyberjunky/home-assistant-toon_smartmeter/blob/d3a646b40bfd6b0c600e1f63b3949a2e020f60c3/custom_components/toon_smartmeter/sensor.py#L72

cyberjunky commented 2 years ago

Can you try version 1.0.21?

freddieleeman commented 2 years ago

Looks good

state_class: measurement
unit_of_measurement: m³
device_class: gas
icon: mdi:gas-cylinder
friendly_name: Toon Gas Used Last Hour
Dutchy-79 commented 2 years ago

Last reset missing The following entities have state class 'measurement' but 'last_reset' is missing: sensor.toon_gas_used_last_hour

installed version 1.0.21

state_class: measurement unit_of_measurement: m³ device_class: gas icon: mdi:gas-cylinder friendly_name: Toon Gas Used Last Hour

add: Customize is also no longer in the UI so I don't know how to add last reset now.

cyberjunky commented 2 years ago

Last_reset? I thought his was legacy for a long time, HA is getting annoying again.. Which version of HA do you run?

gerritjonker commented 2 years ago

Since the last update of smartmeter (1.0.21) I don't see any error message.

Running the latest supervisor-2022.01.1

Dutchy-79 commented 2 years ago

Since the last update of smartmeter (1.0.21) I don't see any error message.

Running the latest supervisor-2022.01.1

Maybe you already have the last_reset?

Screenshot_20220203-173846_Home Assistant

gerritjonker commented 2 years ago

No I don't. Like Ron said: it is deprecated. Are you sure you are running one of the latest versions? In my case it is core-2022.2.0 and supervisor-2022.01.1

Screenshot 2022-02-03 at 17 53 34
Dutchy-79 commented 2 years ago

Then I don't know what is going on with mine, since I updated yesterday energy has not registered any gas.

Only thing is that it says last reset missing.

Dutchy-79 commented 2 years ago

Added a new sensor and that's without error message because it uses total increasing.

Screenshot_20220203-185336_Home Assistant Screenshot_20220203-185320_Home Assistant

Dutchy-79 commented 2 years ago

Screenshot_20220204-084037_Facebook

cyberjunky commented 2 years ago

@Dutchy-79 If i understood your message correctly you fixed it by removing and creating new sensor, did that workaround fixed it for your friend too?

As I said last_reset was removed from HA and my integration long ago, it looks to me a bug in HA to be honest, something with old attrubutes sticking to older devices.

Dutchy-79 commented 2 years ago

Iemand op de Facebook pagina gaf een tijd geleden deze oplossing aan toen het door een eerdere update niet meer werkte, echter daarna kwam jij met de echte fix.

Probeer het volgende eens dmv nieuwe sensoren maken gebaseerd op je toon sensor.

sensor:

Oh, en als het goed is moet na een herstart je sensor.Gasverbruik kunnen selecteren in de configuratie van het energy dashboard.

Dutchy-79 commented 2 years ago

https://m.facebook.com/groups/HomeAssistantNL/permalink/2879872858937993/

cyberjunky commented 2 years ago

Ik heb en wil geen facebook account.

Ik heb nog eens gekeken, ik heb gewoon dit en dat werkt gewoon al een hele tijd en zonder yaml code en met laatste versies... Dat bovenstaande is dus niet nodig, en maakt het alleen maar gecompliceerder. Geen idee wat er aan de hand is, behalve dat er oude code gerunt word (zonder dat men dit door heeft)

image

image

Dutchy-79 commented 2 years ago

Jij kan last hour en gas used cnt kiezen, ik alleen last hour en die doet het juist niet.

cyberjunky commented 2 years ago

Is dit issue nog van toepassing? Ik heb wat tijd om eea op te schonen en te fixen... Ik neem aan dat je gas cnt in je toon_smartmeter config yaml hebt staan?

Dutchy-79 commented 2 years ago

Kan me niet meer herinneren wat er veranderd is maar bij mij werkt het weer.

cyberjunky commented 2 years ago

Thanks!

gerritjonker commented 2 years ago

Geen enkel probleem meer. Thanks.