Bouni / luxtronik

Luxtronik integration for Home Assistant
MIT License
82 stars 14 forks source link

Long term statistics sensors for HA Home Energy management #22

Open WhistleMaster opened 3 years ago

WhistleMaster commented 3 years ago

Hi !

Since 2021.8.0, a new Home Energy management has been added to HA.

Utility Meter can be configured to track consumptions of various utilities (e.g., energy, gas, water, heating).

But, to be able to use an utility meter, the sensor has to integrate long term statistics.

For my luxtronik heatpump, I have the following sensor kwh:

Thanks ! Regards,

WM

WhistleMaster commented 3 years ago

Not the complete implementation for long term statistics, but it's a start :-) #23

WhistleMaster commented 3 years ago

A requirement to opt-in for statistics is that the sensor has state_class set to one of the valid state classes: measurement or total_increasing. In our case, if I'm not wrong, the two sensors should have the measurement class.

Bouni commented 3 years ago

I've not yet read much about the HA energy management. Can only certain measurement units (kWh etc.) be used in the energy dashboard? If so, can we automate that by checking the sensor type and apply the needed state_class?

WhistleMaster commented 3 years ago

I've not yet read much about the HA energy management. Can only certain measurement units (kWh etc.) be used in the energy dashboard?

Indeed, only the energy one can be integrated.

If so, can we automate that by checking the sensor type and apply the needed state_class?

I think so. I've tried to add a new property def state_class(self) and test the type of sensor and if it's CONF_ENERGY, return the measurement class, without success.

WhistleMaster commented 3 years ago

I'm not sure, but from others custom components I've seen, they are using async_add_devices instead of add_entities (sensor.py#L67). Could it be a problem here ?

Bouni commented 3 years ago

πŸ€” the async prefix only indicates that they use asynchronous funtions, but I dont know the difference between add_devices vs. add_entities. I think I've read a long time ago that HA changed their terminology about whats a device / entity / integration / component and so on. To be honest, I never really understood whats the right thing to use πŸ˜…

Bouni commented 3 years ago

Maybe a bit offtopic, but anyway: I thought about rewriting this entire thing anyway someday and make it configurable via the UI. This just did not yet happen because I lack the neccessry amount of spare time to do this 😞

andre-richter commented 3 years ago

It is a good time to rewrite. Recently, lots of sensor implementations are refactored using EntityDescription, which alleviates you from lots of boilerplate and makes it kinda convenient: https://github.com/home-assistant/core/pulls?q=is%3Apr+is%3Aclosed+EntityDescription

What’s needed for statistics is mostly covered in https://developers.home-assistant.io/docs/core/entity/sensor/

Please note the rules for the two state classes to be allowed for statistics, e.g. for the measurement class:

The state represents a measurement in present time, not a historical aggregation such as statistics or a prediction of the future.

Kh3nsu commented 3 years ago

Okay so I added the luxtronik sensors the same you also used... But I have no Idea how to make them total_increasing instead of measurement.... Can someone tell me how you did it? I'm lost....

WhistleMaster commented 3 years ago

It's not yet ready in the actual code so the only way at the moment is to create new utility_meter with those sensors:

utility_meter:
  heat_energy:
    source: luxtronik.id_web_wmz_heizung
    cycle: daily

  water_energy:
    source: luxtronik.id_web_wmz_brauchwasser
    cycle: daily
Kh3nsu commented 3 years ago

Okay thank you ^^ So its going to be supported natively by this integration later?

Kh3nsu commented 3 years ago

Why are we resetting the value every day? I mean isn't it a total value which is increasing indefinitely? Why setting it to 0 every day? Doesn't that give the wrong values in the Energy Dashboard? Or do I not fully understand how the dashboard works?

WhistleMaster commented 3 years ago

Yes it is a total value which is increasing but I want to have the calculation done every day, that's why I have the daily cycle setup. The "reset" is done on the new sensors created based on the two others from the luxtronik integration. The one from the integration are not reset, and keep increasing. If you setup a monthly cycle, then you will get the calculation done every month.

Kh3nsu commented 3 years ago

Mhh okay so for the energy dashboard hourly would be the best because its updating every hour as well right? The best would be to just put in the value which is increasing all the time. How can I do that?

WhistleMaster commented 3 years ago

Well that's the point, you can't with the actual integration, it has to be updated to add the long term statistics.

Kh3nsu commented 3 years ago

Oh okay but wasn't that added with the newest version 1.21? Cause it says "Allow long term statistics for use with energy dashboard" or is that something different?

WhistleMaster commented 3 years ago

No I did a quick PR as a start but it far from the complete implementation for those. https://github.com/Bouni/luxtronik/issues/22#issuecomment-908384015

BenPru commented 2 years ago

Maybe a bit offtopic, but anyway: I thought about rewriting this entire thing anyway someday and make it configurable via the UI. This just did not yet happen because I lack the neccessry amount of spare time to do this 😞

@Bouni I have start writing a new gui config based version of your component: https://github.com/BenPru/luxtronik

Kh3nsu commented 2 years ago

Hello,

I just discovered that those values: luxtronik.id_web_wmz_heizung luxtronik.id_web_wmz_brauchwasser are not really the power what the heatpump draws. It is what the heat pump has produced in heat in kW. Because a heat pump does not convert 1 kW of electricity into 1 kW of heat, most of the time it produces more heat for less electricity (1 kW of electricity = 3 kW of electricity). That is rather variable.

My house has consumed 35.4kWh today. However, the heat pump says that it has already consumed 59.3kWh for heating alone and hot water 5.1kWh.

My utility meter:

luxtronik_heat_energy:
  source: luxtronik.waermemenge_kwh_heizung_raw
  cycle: daily

luxtronik_water_energy:
  source: luxtronik.waermemenge_kwh_warmwasser_raw
  cycle: daily

I think we really have to ask Novelan how to calculate the real power draw or can someone enlighten me on this?

WhistleMaster commented 2 years ago

Indeed it is not related to power draw by the heat pump but the energy produced for water and heat.

Kh3nsu commented 2 years ago

Yeah thats actually not very useful for any energy measuring in home Assistant :/

Do you know the correct value I have to use?

WhistleMaster commented 2 years ago

Yeah thats actually not very useful for any energy measuring in home Assistant :/

Well, it depends what you would like to monitor πŸ˜ƒ

Do you know the correct value I have to use?

I'm not sure if there are any other parameters that could fill that requirement unfortunately.

Kh3nsu commented 2 years ago

Ok so I just asked the support... There really is no value :(

dr-waterstorm commented 2 years ago

I just wanted to ask if there is any update on this. Did the support tell you something useful? I've searched on the internet and in the openHAB Forum someone stated that:

electrical power = heating power / COP

https://community.openhab.org/t/luxtronikheatpump-finding-the-currently-drawn-power/121605/12

The COP is stated on the outdoor part of my heatpump (4.5 in my case). Using that value I do come close to the value my energy counter of the house states. But it's not quite accurate (assuming both started at 0. I do not know that.).

Did someone find a way to extract the "real" power consumption of the heatpump?

Kh3nsu commented 2 years ago

Well sadly I did not :/ The support told me that there is no value given by them to extract. So we have to figure it out with some other method.

With the electricalpower= heating/COP

What exactly is COP and is heating the current heating generating value or the total?

dr-waterstorm commented 2 years ago

Too bad :(

COP is the Coefficient of performance For my test I was using both values given by the heatpumpt and divided each by the COP stated on my heat pump. The sum of both gives me veeeery roughly the value that my energy counter states for total consumption.

But actually I'm very new to this topic, so I have no idea if that is the way one should/would do this. I'm just playing around with the values for now. Maybe someone could enlighten us.

Kh3nsu commented 2 years ago

Well I guess the only way to do so is to install something between the heat pump and the main power. Maybe a Shelly?

dr-waterstorm commented 2 years ago

Probably, yes. My guess would be that the COP (and therefore the calculation) depends on external factors such as temperature, so I guess it would be pretty hard to calculate a good value.

Small update: Justed read up on this. The COP on my device is stated as A7/W35 which means for an air temp of 7 degress and a water temp of 35 degrees. So yep, depends on the temperatures. However mine states 4.5 on the device, but when I actually calcuate the COP myself (of course it's not A7W35 all the time ;-) ) using the overall power used vs. the data from the heat pump I get more like ~2.81

Using something like a shelly is probably pretty accurate. However in my case that would require re-wiring (because the heatpump is directly connected and not plugged in to a standard power socket), which I cannot and will not do myself. Too bad :-/

I'll test this calculation for a few days, let's see how "accurate" it is

Bouni commented 2 years ago

Well I guess the only way to do so is to install something between the heat pump and the main power. Maybe a Shelly?

I have a seperate power meter for my heatpump (one of these "smart meters" also known as EHZ in Germany and probably other parts of Europe). With the upcoming EHZ support I will build a ESP / ESPhome based senor for it. In my opinion thats the only way to tell what a heatpump actuall yuses in terms of electic power ...

Kh3nsu commented 2 years ago

We sadly don't have a seperate power meter for our heat pump :/ So I guess this solution is not usable for me.

arrelid commented 1 year ago

Any news on this one? I've got a couple of modbus (energy) sensors that I can add just fine to HA's energy dashboard - one of them being a sensor that measures the energy my pump has consumed.

Then I've got two (Luxtronik) sensors for the energy vs domestic hot water energy produced that I cannot seem to add. Looking at these sensors in the Developer States overview, the only difference I can spot is their domain - luxtronik vs sensor, see below:

id: luxtronik.geothermal_pump_domestic_hot_water_energy_produced
state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
icon: mdi:flash-circle
friendly_name: Geothermal Pump - Domestic Hot Water Energy Produced

id: sensor.geothermal_pump_energy
state_class: total
unit_of_measurement: Wh
device_class: energy
friendly_name: Geothermal pump Power

The first one (luxtronik) cannot be added to the energy dashboard, while as the second one (sensor) can. The energy dashboard should be able to handle both sensor types (increasing, total) and both units of measurement (W, kW).

Clues, anyone?

AJediIAm commented 1 year ago

You should not add the luxtronic sensors to the energy dashboard since it is not electrical energy but thermal energy. Thermal energy / electrical energy = SCOP.

The domain is used to determine if lon term statistics are enabled or not and I think it's good not to enable it. If you really want to have long term statistics, you can create a utility meter sensor with a template.

arrelid commented 1 year ago

You should not add the luxtronic sensors to the energy dashboard since it is not electrical energy but thermal energy. Thermal energy / electrical energy = SCOP.

The domain is used to determine if lon term statistics are enabled or not and I think it's good not to enable it. If you really want to have long term statistics, you can create a utility meter sensor with a template.

I know they're different in nature (no pun intended), but likely a good reminder for other folks - thanks for pointing it out πŸ‘

What I wanted to achieve is something akin to what you describe - will play around with a template instead.

WhistleMaster commented 1 year ago

You can create an utility_meter in HA. As an example:

heat_energy:
  source: sensor.id_web_wmz_heizung
  cycle: daily

water_energy:
  source: sensor.id_web_wmz_brauchwasser
  cycle: daily

You can then use them in the Energy dashboard. As already said, this is the thermal energy not the electrical energy.