gvigroux / hon

Support of all Haier, Candy, Hoover appliances integrated in the official hOn mobile app. Direct access to all possible services and parameters
MIT License
118 stars 45 forks source link

Add electricity usage as HA long-term statistics #62

Closed ndom91 closed 1 year ago

ndom91 commented 1 year ago

So first of all, the latest update is great! I finally got all available fields from my washingmachine!

However, when trying to add electricity usage to the built-in HA energy dashboard, the sensor is not available.

They link to a statistics docs page for developers:

Looks like you have to set the sensor state_class to one of measurement, total or total_increasing. I guess this one would be total, right?

Screenshot_2023-03-24-12-26-00-58_c3a231c25ed346e59462e84656a70e50.jpg

Referring to this sensor:

Screenshot_2023-03-24-12-28-30-41_c3a231c25ed346e59462e84656a70e50.jpg

gvigroux commented 1 year ago

I just did it. Can you please test?

ndom91 commented 1 year ago

Hmm so many of the sensors are no longer available anymore now.

I got a second device added for my 1 washing machine with many fewer sensors:

image

This is the previous one:

image

All of these entities are now "no longer provided by the integration" :thinking:

image

I was previously on commit 83f6ea8

gvigroux commented 1 year ago

Can you please try to delete and reinstall the integration ?

ndom91 commented 1 year ago

Deleted and readded the integration. Now I only have the 1 device with the 4 entities:

image

ndom91 commented 1 year ago

2 minutes later the 4 washing machine sensor values updated:

image

gvigroux commented 1 year ago

Are more sensors coming after 1 min ? I don't understand why they are not visible.

I've made some fix elsewhere, can you update and try ? If the same, I need to analyse some logs to understand. Please add this to the configuration.yaml and restart HA

logger:
  logs:
    custom_components.hon: info

After go to the log page '/config/logs' and click to access all logs. Share any of the logs starting with: [custom_components.hon.hon] {"payload":

Thanks!

ndom91 commented 1 year ago

Ah found the issue,

The totalElectricityUsed on hon/sensor.py:129 is a float, not int. Therefore it failed setting up any sensors after that

Got all this after the change:

image

ndom91 commented 1 year ago

In addition, I have htis error message in the logs:

Entity sensor.washing_machine_current_water_used (<class 'custom_components.hon.sensor.HonBaseCurrentWaterUsed'>) is using state class 'measurement' which is impossible considering device class ('volume') it is using; expected None or one of 'total_increasing', 'total'; Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.

ndom91 commented 1 year ago

As well as an issue with the onOffStatus key

image

ndom91 commented 1 year ago

Doesn't look like I have an onOffStatus key. Here's the whole payload:

json payload ```json { "voiceStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "forceDelete": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "dryLevel": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "airWashTime": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "softWarn": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "loosenStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "temp40": { "parNewVal": "15", "lastUpdate": "2023-03-24T11:17:14Z" }, "strongStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "weight": { "parNewVal": "5.00", "lastUpdate": "2023-03-25T12:47:08Z" }, "intelligenceStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "purifiedWashStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "temp": { "parNewVal": "40", "lastUpdate": "2023-03-25T12:41:05Z" }, "voiceModuleVolume": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "washSpeed": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "machMode": { "parNewVal": "2", "lastUpdate": "2023-03-25T12:47:05Z" }, "buzzerDisabledCurrent": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "errors": { "parNewVal": "00", "lastUpdate": "2023-03-24T20:27:12Z" }, "remoteCtrValid": { "parNewVal": "1", "lastUpdate": "2023-03-25T12:47:08Z" }, "autoDetergentStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "soakWashStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "buzzerDisabled": { "parNewVal": "1", "lastUpdate": "2022-11-27T17:16:56Z" }, "haier_DetergentWeight": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "totalWaterUsed": { "parNewVal": "934", "lastUpdate": "2023-03-25T12:47:08Z" }, "message": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "temp0to30": { "parNewVal": "3", "lastUpdate": "2023-03-03T22:42:57Z" }, "spinSpeed": { "parNewVal": "1400", "lastUpdate": "2023-03-25T12:41:05Z" }, "detergentPercent": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "highTransRate": { "parNewVal": "1", "lastUpdate": "2022-11-27T17:15:56Z" }, "currentWaterUsed": { "parNewVal": "15", "lastUpdate": "2023-03-25T12:47:08Z" }, "autoDisinfectantStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "cloudProgSrc": { "parNewVal": "2", "lastUpdate": "2023-03-25T12:47:08Z" }, "prCode": { "parNewVal": "136", "lastUpdate": "2023-03-25T12:41:05Z" }, "dryCleaningNeeded": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "dryProgFlag": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "program19": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program18": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program17": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "programStats": { "parNewVal": "1;;;;;;;1;;;;;f;;;;;;;;;;;;1", "lastUpdate": "2023-03-24T11:17:14Z" }, "program16": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "autoSoftenerStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "program11": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program10": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "totalWashCycle": { "parNewVal": "18", "lastUpdate": "2023-03-24T11:17:14Z" }, "program15": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "detergentBStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "program14": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program13": { "parNewVal": "15", "lastUpdate": "2023-03-24T11:17:14Z" }, "program12": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "laundryCycleStatus": { "parNewVal": "1", "lastUpdate": "2023-03-25T12:47:08Z" }, "standbyTimeExtended": { "parNewVal": "1", "lastUpdate": "2023-03-25T12:47:08Z" }, "actualWeight": { "parNewVal": "5", "lastUpdate": "2023-03-25T12:47:08Z" }, "speedUpStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "operationName": { "parNewVal": "grOnlineWash", "lastUpdate": "2023-03-24T08:34:29Z" }, "program22": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program21": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program20": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "defSetAllowed": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "program25": { "parNewVal": "1", "lastUpdate": "2023-03-03T22:42:57Z" }, "program24": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program23": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "voiceModuleWakeStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "currentWashCycle": { "parNewVal": "18", "lastUpdate": "2023-03-24T11:17:14Z" }, "transMode": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:15:56Z" }, "currentElectricityUsed": { "parNewVal": "0.03", "lastUpdate": "2023-03-25T12:55:08Z" }, "washerDryIntensity": { "parNewVal": "1", "lastUpdate": "2022-11-27T17:16:56Z" }, "steamStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "delayStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "haier_SoftenerWeight": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "debugEnabled": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:15:56Z" }, "dirtyLevel": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "remainingStandbyTime": { "parNewVal": "1426", "lastUpdate": "2023-03-25T12:55:05Z" }, "stdTransRate": { "parNewVal": "1", "lastUpdate": "2022-11-27T17:15:56Z" }, "testCmdReceiveStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "clothesAnionStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "stainType": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "nightWashStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "energySavingStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "remainingRinseIterations": { "parNewVal": "2", "lastUpdate": "2023-03-24T20:27:08Z" }, "voiceModuleDataDef": { "parNewVal": "130", "lastUpdate": "2022-11-27T17:16:56Z" }, "pause": { "parNewVal": "0", "lastUpdate": "2023-03-25T12:47:08Z" }, "doorStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "remainingTimeMM": { "parNewVal": "136", "lastUpdate": "2023-03-25T12:55:08Z" }, "texture": { "parNewVal": "1", "lastUpdate": "2023-03-25T12:41:05Z" }, "program4": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "cloudProgId": { "parNewVal": "255", "lastUpdate": "2023-03-25T12:47:08Z" }, "voiceModuleWakeUp": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "program3": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program6": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program5": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "doorLockStatus": { "parNewVal": "1", "lastUpdate": "2023-03-25T12:47:08Z" }, "program8": { "parNewVal": "1", "lastUpdate": "2022-11-29T15:11:50Z" }, "program7": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "detWarn": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "antiAllergyStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "creaseResistSoakStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "program9": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "lockStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "remainingMainWashTime": { "parNewVal": "96", "lastUpdate": "2023-03-25T12:55:08Z" }, "program2": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "program1": { "parNewVal": "1", "lastUpdate": "2022-11-27T19:08:21Z" }, "permanentPressStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "prPhase": { "parNewVal": "2", "lastUpdate": "2023-03-25T12:47:08Z" }, "highWaterLevelStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "dryStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "dryTime": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "airWashTempLevel": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "voiceModuleOnOffStatus": { "parNewVal": "1", "lastUpdate": "2022-11-27T17:16:56Z" }, "temp60to90": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:54Z" }, "uvSterilizationStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "shoesAnionStatus": { "parNewVal": "0", "lastUpdate": "2022-11-27T17:16:56Z" }, "detergentType": { "parNewVal": "1", "lastUpdate": "2022-11-27T17:16:56Z" }, "totalElectricityUsed": { "parNewVal": "11.91", "lastUpdate": "2023-03-25T12:55:08Z" }, "macAddress": "78-12-34-56-78-90", "category": "CONNECTED", "instantTime": "2023-03-25T12:38:24Z", "timestampEvent": 1679747904848 } ```

EDIT: I copied your code from the binary_sensor.py onOffStatus conditional definition to the sensor.py:601 onOffStatus definition. Basically:

if( "onOffStatus" in self._coordinator.data ):
    self._on = self._coordinator.data["onOffStatus"]["parNewVal"] == "1"
else:
    self._on = self._coordinator.data["category"] == "CONNECTED"
ndom91 commented 1 year ago

In addition, in sensor.py:317 you're defining time only if the device type is WASH_DRYER. Leading to errors for only WASHING_MACHINE type devices when you refer to it again at the bottom of this callback.

image

EDIT: Seems that last self._attr_native_value = time is just a left over. Going to comment it out

ndom91 commented 1 year ago

Ah works! Middle of a run cycle:

image

Although startTime is not right, thats the start time of the homeassistant instance (restarted). Looks like that might just be a side-effect of me redefining it in the middle of a washing cycle.

Anyway, sorry about the "stream of consciousness" bug reporting here :sweat_smile:. But after making all the changes I referenced in this thread, we seem to be up and running again. No more errors being reported :+1:

EDIT: Just reread your message, just wanted to be clear - I did not pull your latest update before making these changes. I was still on 0ed1185. So anyway, sorry if you already got around to these fixes :sweat_smile:

ndom91 commented 1 year ago

And the actual issue raised in this GH issue is also fixed :joy:

image

Remember, the water volume use seems to be wrong type of statistic still though (https://github.com/gvigroux/hon/issues/62#issuecomment-1483816119)

ndom91 commented 1 year ago

Final question - is there any way to also control the devices through the API endpoints used for this integration?

Because logging in via the integration seems to kick me out of the android app, meaning I have to signin freshly again every time I want to start a cycle. Slightly annoying. Would be great if I could stay signed in only via hass and also initiate wash cycles via the integration.

gvigroux commented 1 year ago

Wow :) Can you create a pull request with all the changes? If not I will try and ask you test.

There is a service to start a washing program I think. Did you try?

ndom91 commented 1 year ago

@gvigroux yeah no problem. Here we go :grin: - https://github.com/gvigroux/hon/pull/64.

Looks like the float/int var type for totalElectricityUsed was already fixed, right.

Ah I see there service now! Is there a possibility to set programType instead of manually specifying water temperature, spin cycles, etc.?

EDIT: Yeah looks like you can pass an id theoretically. I often use prCode: 136, for example. And can easily be observed by starting the desired program once from the app and checking the appropriate entity in HA.

https://github.com/gvigroux/hon/blob/f0a944373fa7df8cb543ed4030d7d64eb48d96f0/__init__.py#L183

EDIT 2: I'll post this as a "feature request" and someone can maybe get to it when they have time :wink: :+1:

EDIT 3: Feature request issue is up: https://github.com/gvigroux/hon/issues/65

gvigroux commented 1 year ago

I did the merge :) Thank you!