sveinse / zaptec

zaptec charger custom component for home assistant
MIT License
11 stars 2 forks source link

Add state_class to sensors #23

Closed Bluhme1 closed 1 year ago

Bluhme1 commented 1 year ago

I am using the Energy Meter custom_component to calculate a price for my charges.

https://github.com/zeronounours/HA-custom-component-energy-meter

Apparently the state_class: total_increasing is needed in the source entity. In my case it is sensor.XXXXXXX_session_total_charge.

I added in myself by adjusting the code in sensor.py in your custom_component, but I will of course have to do it again every time I update the custom_component.

Is there any chance to add the state_class: total_increasing in the sensors where it makes sense?

/Lars. Denmark

sveinse commented 1 year ago

@Bluhme1 Which version of the zaptec-dev integration are you using? The latest zaptec-dev version does have TOTAL, but not TOTAL_INCREASING on "Energy meter".

Bluhme1 commented 1 year ago

I am using c25463d. I am referring to the sensor "total_charge_power_session" Have noticed TOTAL on "energy meter", but apparently the total_charge_power_session" component needs TOTAL_INCREASING to be used in the Energy Meter component that I am using

sveinse commented 1 year ago

@Bluhme1 interesting. I'm using it with the built-in energy panel in HA and I had to change it from TOTAL_INCREASING to TOTAL to avoid complaints from statistics. In the dev docs (https://developers.home-assistant.io/docs/core/entity/sensor?_highlight=total_inc#long-term-statistics):

It's recommended to use state class total without last_reset whenever possible, state class total_increasing or total with last_reset should only be used when state class total without last_reset does not work for the sensor.

I need to investigate what's correct to do here.

sveinse commented 1 year ago

@Bluhme1 I changed the entity to TOTAL_INCREASING and deployed a new version 4dfeb68b84d35e89f6fa47e22263d1b928f8eed0. Please test if this works for you.

Bluhme1 commented 1 year ago

Sorry. We must have misunderstood each other.

I was referring to the "key="total_charge_power_session",

You have added State_class.TOTAL_INCREASING to the key "key="signed_meter_value_kwh",

Concerning the "key="signed_meter_value_kwh", you might be right in your assumption the it should have State_class.TOTAL

sveinse commented 1 year ago

@Bluhme1 Your're right, I misunderstood. I'll add TOTAL_INCREASING to "total_charge_power_session" as well.

BTW: As for TOTAL_INCREASING, I've changed my opinion. I think this is the right one to use: For "signed_meter_value_kwh" we never know what zaptec centrally will do and for the "total_charge_power_session" it will revert to 0 on each charge session.

sveinse commented 1 year ago

I just pushed a new version 485969a90c06edbf9edfa93bca31baab889ce00f with TOTAL_INCREASING on the "total_charge_power_session" as well. Please retest.

sveinse commented 10 months ago

@Bluhme1 I'm getting warning that sensor.sol_session_total_charge (in Zaptec: total_charge_power_session) should not be TOTAL_INCREASING but rather TOTAL. See custom-components/zaptec#86. Isn't this the opposite of the issue you had with this? What should we do here?