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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Daikin integration power sensors #51905

Merged
merged 3 commits into from
Jun 30, 2021

Conversation

mlemainque
Copy link
Contributor

@mlemainque mlemainque commented Jun 15, 2021

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @fredrike, mind taking a look at this pull request as its been labeled with an integration (daikin) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@mlemainque
Copy link
Contributor Author

Hi @fredrike !
Does this look OK to you? It should fix many issues people are having with latest releases

@fredrike
Copy link
Contributor

fredrike commented Jun 22, 2021

Looks good to me!

But it is a breaking change as sensor ids change?

@fredrike
Copy link
Contributor

@mlemainque should we release a maintainment version of pydaikin without your changes that potentially get merged in HA before this breaking change?
I totally missed your changes when I pushed for a new version of pydaikin. Your changes would actually require a minor change in the lib.

@mlemainque
Copy link
Contributor Author

Well I noticed the sensor ids have changed but the only consequence is that the history of data is lost and the widget configuration requires an update. Is it that bad?

@fredrike
Copy link
Contributor

fredrike commented Jun 22, 2021

Well I noticed the sensor ids have changed but the only consequence is that the history of data is lost and the widget configuration requires an update. Is it that bad?

It usually requires a larger release (2021.7?) with breaking changes.. But July is coming so it might not be so bad.

@mlemainque
Copy link
Contributor Author

Do you know if it is possible to detect if there is already a sensor in HA with the previous type energy and somehow rename it and convert its type to power in order to have a smooth transition?

@fredrike
Copy link
Contributor

No, I don't think that is how it is intended to work..

@mlemainque
Copy link
Contributor Author

I agree that this should be in the next major release then.

Correct me if I'm wrong: if we merge into dev it won't be released in 2021.6.x but in the next 2021.7.0 (planned on 30th of June), dev is always the place for next major releases and rc is where we push minor releases

Dev automation moved this from Needs review to Reviewer approved Jun 23, 2021
Copy link
Contributor

@dgomes dgomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I wonder how this changed from energy to power ?

@mlemainque
Copy link
Contributor Author

LGTM, but I wonder how this changed from energy to power ?

It is related to sensors updated hourly with the consumption of the last hour. Thus in this special case, energy and power is exactly the same value as 1 kWh = 1 kW x 1 h...
But I realised it was a non-sense to use "energy" unit kWh as HA only reports instant values. Energy class should be used if we were monitoring the total sum of power*hours since its begining, which is not the case. So it should use power unit kW.

@dgomes
Copy link
Contributor

dgomes commented Jun 24, 2021

This makes no sense... Power is always an instantaneous value... are you saying that the HVAC system maintains a constant power value for a full hour ? (that's not how most HVAC devices work)

If it's really energy used in the last hour, then the integration should sum all the values and keep track of that sum (quite useful I must say)

@fredrike
Copy link
Contributor

Perhaps it reports the average power over the last hour..

@mlemainque
Copy link
Contributor Author

Each daikin AC reports the energy consumed each hour by cool/heat modes on a hourly basis. So there is always one hour lag.

In my opinion the sum of the energy is not useful at all for the user. The user wants (at least I want) to know how much energy has been consumed within a given interval of time, not since its birth. The best way to give this information to the user without choosing one interval of time (it could be hourly, daily, weekly, monthly, etc.) is to give an instant power in kW.

Note that the total sensor is based on a totally different behavior: the AC also report the energy consumed by all AC and all modes together on a live basis (everytime 100 Wh are consumed). In this case it is more a instant value then

@dgomes
Copy link
Contributor

dgomes commented Jun 24, 2021

But what does Daikin device provide ? kW or kWh ?

power and energy are completely different things... and you cannot take a random kW value and multiply it by 1h to get Energy (expressed in kWh) to do this conversion you must integrate the values (it's not an average)

I'm fine with any solution as long as it does not deviate from what the physical device actually provides.

@mlemainque
Copy link
Contributor Author

mlemainque commented Jun 24, 2021

Well the daikin API provides numbers without specifying the unit. The content looks like 0/0/0/0/1/1/3/3/... with 24 values, one for each hour of the day. Those values represent the number of times 100Wh had been consumed within each hour. And those values are updated only once an hour at the end of each hour. From a physical point of view those values can be interpreted as both an average power over the hour (in kW) OR the energy consumed (in kWh) over the hour; both are true

The daikin official app has a completely different way of displaying these data as HA does: in the app they show the history of the data as an histogram, so in this case it makes sense to use kWh as it is not an instant display. In HA you can only set the current value of one sensor

@dgomes
Copy link
Contributor

dgomes commented Jun 24, 2021

So the values are Energy 100 kWh per unit

It is basically a "utility_meter" which resets every-hour, and IMHO it would make sense to provide an histogram similar to what daikin provides.

@mlemainque
Copy link
Contributor Author

Below is an example of what we have today with the version prior to 2021.6. It is exactly the same thing as what is displayed in the daikin official app except it is shifted of one hour. To avoid this shift we should be able to set the value of the sensor one hour in the past, which I don't think is possible with HA.

The new version is fixing some glitches such as the one which happened at midnight on the screenshot, and changes the unit from kWh to kW. If you think we should keep kWh I'm okay with that, it will avoid loosing historical data

image

@dgomes
Copy link
Contributor

dgomes commented Jun 24, 2021

I think you should not change from kWh to kW because it simply is not a power measurement.

I do think we should debate in https://github.com/home-assistant/architecture for the need to write past values as your use case clear requires that.

@mlemainque
Copy link
Contributor Author

This PR now only fixes the wrong attribute name causing all the issues (it has been renamed from "energy" to "power" within pydaikin) and adds the new compressor frequency sensor

@mlemainque
Copy link
Contributor Author

I think you should not change from kWh to kW because it simply is not a power measurement.

I do think we should debate in https://github.com/home-assistant/architecture for the need to write past values as your use case clear requires that.

Discussion opened here: home-assistant/architecture#580

if self._device_attribute == ATTR_COOL_ENERGY:
return round(self._api.device.last_hour_cool_energy_consumption, 3)
return round(self._api.device.last_hour_cool_power_consumption, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be reverted back to energy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the description

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the pydaikin API

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could push a new pydaikin versioniif you like..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlemainque are you preparing code for the pydaikin lib or should I?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary @dgomes? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlemainque is this enough?

diff --git a/pydaikin/daikin_base.py b/pydaikin/daikin_base.py
index 404721c..cb868f1 100644
--- a/pydaikin/daikin_base.py
+++ b/pydaikin/daikin_base.py
@@ -208,9 +208,9 @@ class Appliance(DaikinPowerMixin):  # pylint: disable=too-many-public-methods
             )
             data.append(('cool_today', self.energy_consumption(ATTR_COOL, TIME_TODAY)))
             data.append(('heat_today', self.energy_consumption(ATTR_HEAT, TIME_TODAY)))
-            data.append(('total_power', self.current_total_power_consumption))
-            data.append(('cool_power', self.last_hour_cool_power_consumption))
-            data.append(('heat_power', self.last_hour_heat_power_consumption))
+            data.append(('total_power', self.current_total_energy_consumption))
+            data.append(('cool_power', self.last_hour_cool_energy_consumption))
+            data.append(('heat_power', self.last_hour_heat_energy_consumption))
         if file.tell() == 0:
             file.write(','.join(k for k, _ in data))
             file.write('\n')
@@ -238,9 +238,9 @@ class Appliance(DaikinPowerMixin):  # pylint: disable=too-many-public-methods
             data.append(
                 f'heat_today={self.energy_consumption(ATTR_HEAT, TIME_TODAY):.01f}kWh'
             )
-            data.append(f'total_power={self.current_total_power_consumption:.02f}kW')
-            data.append(f'cool_power={self.last_hour_cool_power_consumption:.01f}kW')
-            data.append(f'heat_power={self.last_hour_heat_power_consumption:.01f}kW')
+            data.append(f'total_power={self.current_total_energy_consumption:.02f}kW')
+            data.append(f'cool_power={self.last_hour_cool_energy_consumption:.01f}kW')
+            data.append(f'heat_power={self.last_hour_heat_energy_consumption:.01f}kW')
         print('  '.join(data))
 
     def represent(self, key):
@@ -349,28 +349,28 @@ class Appliance(DaikinPowerMixin):  # pylint: disable=too-many-public-methods
         return self._parse_number('shum')
 
     @property
-    def current_total_power_consumption(self):
+    def current_total_energy_consumption(self):
         """Return the current total power consumption in kW."""
         # We tolerate a 50% delay in consumption measure
-        return self.current_power_consumption(
+        return self.current_energy_consumption(
             mode=ATTR_TOTAL, exp_diff_time_margin_factor=0.5
         )
 
     @property
-    def last_hour_cool_power_consumption(self):
+    def last_hour_cool_energy_consumption(self):
         """Return the last hour cool power consumption of a given mode in kW."""
         # We tolerate a 5 minutes delay in consumption measure
-        return self.current_power_consumption(
+        return self.current_energy_consumption(
             mode=ATTR_COOL,
             exp_diff_time_value=timedelta(minutes=60),
             exp_diff_time_margin_factor=timedelta(minutes=5),
         )

 
     @property
-    def last_hour_heat_power_consumption(self):
+    def last_hour_heat_energy_consumption(self):
         """Return the last hour heat power consumption of a given mode in kW."""
         # We tolerate a 5 minutes margin in consumption measure
-        return self.current_power_consumption(
+        return self.current_energy_consumption(
             mode=ATTR_HEAT,
             exp_diff_time_value=timedelta(minutes=60),
             exp_diff_time_margin_factor=timedelta(minutes=5),
diff --git a/pydaikin/power.py b/pydaikin/power.py
index 08ce689..522543c 100644
--- a/pydaikin/power.py
+++ b/pydaikin/power.py
@@ -149,7 +149,7 @@ class DaikinPowerMixin:
         _LOGGER.error('Impossible energy consumption measure of %s', mode)
         return None
 
-    def current_power_consumption(  # pylint: disable=too-many-branches
+    def current_energy_consumption(  # pylint: disable=too-many-branches
         self,
         mode=ATTR_TOTAL,
         exp_diff_time_value=None,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fredrike
Copy link
Contributor

fredrike commented Jun 24, 2021

@fredrike fredrike mentioned this pull request Jun 24, 2021
@mlemainque mlemainque force-pushed the feat/new-pydaikin-sensors branch 2 times, most recently from 692f7a7 to 271ee01 Compare June 24, 2021 20:26
@dgomes dgomes added this to the 2021.6.7 milestone Jun 24, 2021
@dgomes
Copy link
Contributor

dgomes commented Jun 24, 2021

Since the integration is broken I tagged it for .7 release, but expect an extra pair of eyes reviewing this.

Copy link
Contributor

@fredrike fredrike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks great!

@mlemainque
Copy link
Contributor Author

mlemainque commented Jun 26, 2021

I've tested this new version, everything seems to go as expected. Below are examples of what is measured.

  • There is no lag with the compressor frequency. Note that even though the frequency is constant, I don't think it means the power consumption will be constant as well. Sometimes the indoor AC stops but not the outside compressor.

image

  • The total power consumption is updated as soon as 100 Wh have been consumed

image

  • The cool energy consumption is updated hourly

image

@mlemainque mlemainque changed the title Update Daikin integration power sensors Fix Daikin integration power sensors Jun 26, 2021
@dgomes
Copy link
Contributor

dgomes commented Jun 26, 2021

not sure about the middle graph

how come that is Watts (Power) but you update based on WattsHour (Energy) ?

@mlemainque
Copy link
Contributor Author

mlemainque commented Jun 29, 2021

not sure about the middle graph

how come that is Watts (Power) but you update based on WattsHour (Energy) ?

Simply with Power (W) = Delta Energy (Wh) / Delta Time (h)

The power is updated by pydaikin everytime 100 Wh are consumed so the delta energy is constant but not delta time. That way the power is more accurate and is updated faster than it used to be with older versions of pydaikin which were instead measuring the delta energy over a constant delta time (half an hour).

@dgomes
Copy link
Contributor

dgomes commented Jun 30, 2021

It is by no way more accurate...

lets say you have the 100Wh update spaced 1h apart, that does not mean that there was a steady consumption of 100W during an hour.... you could have 200W during 30min and 0W the next 30min....

and it could be even worst! a small peak of 1000W and then nothing (usual behaviour in these devices)

My point: don't extrapolate... use directly what the device exposes or what can be actually measured

@mlemainque
Copy link
Contributor Author

mlemainque commented Jun 30, 2021

lets say you have the 100Wh update spaced 1h apart, that does not mean that there was a steady consumption of 100W during an hour.... you could have 200W during 30min and 0W the next 30min....

and it could be even worst! a small peak of 1000W and then nothing (usual behaviour in these devices)

You're right this is one limitation, this is an estimation of the power based on the energy consumption.

I get your point, you would like to have access to the raw data without any transformation to be as close to what returns the AC as possible. My opinion is that the end-user is more interested in the instant power (would it be an estimation) than the energy consumption as it is easier to interpret.

Anyway I don't think this is the place to discuss about that. This PR is about fixing the current behavior of the integration and we're currently discussing about something that is in HA for almost a year. Should not we open a thread in pydaikin repository instead?

@frenck
Copy link
Member

frenck commented Jun 30, 2021

I think other than the above discussion, from the HA perspective, this PR looks good. Is it OK to go?

@dgomes
Copy link
Contributor

dgomes commented Jun 30, 2021

I approved :)

@frenck frenck merged commit a7ece4e into home-assistant:dev Jun 30, 2021
Dev automation moved this from Reviewer approved to Done Jun 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2021
@mlemainque mlemainque deleted the feat/new-pydaikin-sensors branch September 10, 2022 09:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

Daikin temperature sensor no longer update
5 participants