Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Assistant - State class support #129

Closed
KNXBroker opened this issue Sep 12, 2021 · 19 comments
Closed

Home Assistant - State class support #129

KNXBroker opened this issue Sep 12, 2021 · 19 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@KNXBroker
Copy link

Is your feature request related to a problem? Please describe.
Since some home assistant releases home assistant supports state_class, which is not support (yet) by EMS-ESP.

Describe the solution you'd like
It would be great if automatic entity creation would support state_class definition. E.g. for temperatures state_class: measurement

Describe alternatives you've considered
Manual definition / creation of home assistant entities.

Additional context
I know that ESP8266 is no longer supported, but I am still using it... In general the feature would be great for both V2 and V3. Is the code definition part of both V2 and V3 the same...? I could support if someone shows me the respective lines. I assume it's only an additional parameter which has to be added to the respective sensors.

@proddy
Copy link
Contributor

proddy commented Sep 13, 2021

I'm not too familiar with the state_class. What are the benefits of adding it to the sensors?

Could you try it yourself manually? Use something like MQTTExplorer and modify the topic homeassistant/sensor/ems-esp/thermostat_hc1_currtemp/config and add "state_class: measurement". No need to change the code. If it does what you hoped we can add it, it's not hard like you said.

Also we need to think about which other sensors need modifying. There can be more than 200+ on a system with solar, mixing and multiple heating circuits.

Lastly, see if you can upgrade to V3 :-)

@KNXBroker
Copy link
Author

KNXBroker commented Sep 13, 2021

Lastly, see if you can upgrade to V3 :-)

It's the external power supply which prevents me upgrading, unfortunately my boiler does not have a service Jack :-(

I'm not too familiar with the state_class. What are the benefits of adding it to the sensors?

state_class: measurement for long time storage and state_class: total_increasing for (gas) energy monitoring.

I found a way to add the attributes by customizing, but the state_class is going to be elementary. Native support by ems-esp would be good. Do you have a 100% sensor list, e.g. in excel format? I could make a validation.

@proddy
Copy link
Contributor

proddy commented Sep 13, 2021

All the device values have a Unit Of Measure which can be:

NONE
DEGREES
PERCENT
LMIN
KWH
WH
HOURS
MINUTES
UA
BAR
KW
W
KB
SECONDS
DBM
NUM
BOOLEAN
LIST
MV

and these are used for rendering and also setting the default icon in HA. I'm guessing all them need the state_class 'measurement' apart from LIST, HOURS and MINUTES?

@KNXBroker
Copy link
Author

Unfortunately decision has to be made on sensor level, see https://developers.home-assistant.io/docs/core/entity/sensor/

Example: A sensor representing a setting (e.g. selected flow Temperatur in degree) is no measurement and may contain no sensor class.

I'm Not Sure about hours and minutes (e.g. operating hours). Could be total_increasing but I have to ask / try.

@proddy
Copy link
Contributor

proddy commented Sep 13, 2021

It says "The state represents a measurement in present time, not a historical aggregation such as statistics or a prediction of the future" so in theory all the device values captured on the EMS fall into this category as they are actual live values, and not calculations.

I can add to the code. But still not sure what the difference will be in HA or what the advantage is?

@KNXBroker
Copy link
Author

state_class:total_increasing enables sensor usage for the new energy dashboard, see https://www.home-assistant.io/blog/. This state class is for increasing energy counters like gas and power.

state_class: measurementenables long time recording. For the time being benefit is limited (e.g. creation of long term statistic graphs), but additional features shall be added.

The state_class is only for sensors, not binary sensors.

@proddy
Copy link
Contributor

proddy commented Sep 13, 2021

Ok I've made the change in V3 and will monitor it for a few hours. if it works I'll backport it to v2.

@KNXBroker
Copy link
Author

KNXBroker commented Sep 14, 2021

Amazing reactivity 😃 One comment, I'm not sure if Wh and KWh are measurements. Unfortunately I have only a very simple boiler without solar, therefore I cannot test this.

If have checked the code (not sure if I missed sensors):

For KWH there are the following sensors, All sensors seems to be state_class:total_increasing

  • boiler: nrgConsTotal
  • V3 only boiler: nrgConsCompTotal
  • boiler: auxElecHeatNrgConsTotal_
  • solar : energyTotal:

For WH there are the following sensors, all sensors seems to be state_class:none

  • WH / Solar: energyLastHour:
  • WH / Solar: energyToday

@proddy
Copy link
Contributor

proddy commented Sep 14, 2021

agree, I'll remove the 'measurement' for Wh, KWh, W and KW

@MichaelDvP
Copy link
Contributor

I think it's a good start but a bit more complicated.

A sensor representing a setting (e.g. selected flow Temperatur in degree) is no measurement and may contain no sensor class.

For that all values with dv.has_cmd should not have the measurement flag, The has_cmd has to be parsed to publish_mqtt_ha_sensor(

state_class:total_increasing is in my understanding all #starts and all upTimes, so DeviceUOM::NUM and DeviceUOM::MINUTES can be flaged this way. Fortunately the settings with minutes like pumpDelay have a command and should be skipped.

The powervalues W and kW are measurements, representing an actual value. Energy kWh is total increasing for the total values, not for today and last_hour, but these are measured in Wh. I'm not sure, but i think energy_last_hour is a measurement, giving on each publish the value of the past 60min (not resetting on every full hour).

@KNXBroker
Copy link
Author

A sensor representing a setting (e.g. selected flow Temperatur in degree) is no measurement and may contain no sensor class.

This was my personal understanding, but I'm not 100% sure. Is a setting a measurement?!

Regarding energy_last_hour, I'm neither sure.

Maybe both a question for Home Assistant Community.

@MichaelDvP
Copy link
Contributor

This was my personal understanding, but I'm not 100% sure.

Oh, i thought it was from the HA spec.

Is a setting a measurement?!

I don't use HA and don't know what this state_class is used for. It was only a hint how we can manage it to exclude the settings.

@proddy
Copy link
Contributor

proddy commented Sep 14, 2021

it does look a little more tricky. I'm still not 100% sure of the value this brings to the end user in HA or what really happens under the sheets within HA.

@KNXBroker
Copy link
Author

For the time being the main advantage is long time storage. In the past this was only possible with external databases like INFLUX / GARFANA. Here an example of my outside temperature.
Unbenannt

Regarding energy_last_hour, this is a measurement (If have asked on Home Assistant discord server).

Regarding settings, I think that's not cleary defined, but after thinking about it once more, why not declaring it as measurement. In the end it's a current value and it (could) make sense to make a long time storage.

@proddy
Copy link
Contributor

proddy commented Sep 16, 2021

right, most people use influx. I thought if you wanted to store more information you just change the 'recorder' and add more days.

As Michael mentioned it's not as easy as stating every type EMS-ESP is either a measurement or a total_increasing. Could you specify which values you are particularly interested in having long-term retention for and we'll start with those? For example the temperatures?

@KNXBroker
Copy link
Author

I thought if you wanted to store more information you just change the 'recorder' and add more days.

My understanding is, that this will kill one-day home assistant recorder database. Long-term storage does some kind if compression, e.g. calculation max, min and mean values per hour.

Thank you for your offer, but there is no pressure including the feature only for me. I did add the state class manually via 'customizing'. I thought it would be a nice improvement for EMS-ESP in general, therefore I have started the discussion. I appreciate open-source products like yours, this was / is my way of participating. If additional requests are coming, the feature can be fully implemented one day.

@proddy
Copy link
Contributor

proddy commented Sep 24, 2021

moving this to EMS-ESP32 for implementation.

@proddy proddy transferred this issue from emsesp/EMS-ESP Sep 24, 2021
@proddy proddy self-assigned this Sep 24, 2021
@proddy proddy added the enhancement New feature or request label Sep 24, 2021
@proddy
Copy link
Contributor

proddy commented Sep 26, 2021

@swa72 mentioned in #128

The stock configuration does not list sensor.solar_energy_today in HA's new energy dashboard. Adding

sensor.solar_energy_today:
  device_class: energy
  state_class: total_increasing

to customize.yaml did the trick for me.

@proddy
Copy link
Contributor

proddy commented Sep 28, 2021

Added to 3.2.2b10

  • WH uses measurement (E.g. solar/energyLastHour, solar/energyTotal)
  • KWH uses total_increasing (E.g. solar/energyTotal, boiler/nrg)
  • KW uses measurement (E.g. boiler/hpPower)
  • W uses measurement (E.g. solar/solarPower)

everything else will not add the state_class attribute in the Home Assistant entity

proddy added a commit to proddy/EMS-ESP32 that referenced this issue Sep 28, 2021
@proddy proddy closed this as completed Sep 28, 2021
@proddy proddy added this to the v3.3 milestone Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants