astrandb / miele

A modern integration for Miele devices in Home Assistant
MIT License
190 stars 29 forks source link

Dishwasher "action" buttons #541

Open kinnkler opened 1 week ago

kinnkler commented 1 week ago

Feature request

I have to say, I'm really happy with this Home Assistant integration. The only thing I would like to see is the “Pause” action for the dishwasher. I have implemented it myself (see below), but would be happy if it were also in the official release. I have also noticed that the “action buttons” are not updated correctly. If I pause the dishwasher via the Miele app, actions 1 and 2 (Start and Stop) should be activated according to the API. Unfortunately, the buttons are not active in HomeKit. However, as soon as I open the door and an event is triggered, they are updated. Since an event is also communicated when switching to pause, the action buttons should actually be updated when the event arrives. And another general question: How often are the sensors queried by Miele? Every 60 seconds?

description=MieleButtonDescription(
            key="pause",
            translation_key="pause",
            press_data={PROCESS_ACTION: ACT_PAUSE},
        )

And some other additions in const.py and translation.

What version of the integration are you using?

2024.8.1

Anything in the logs that might be useful for us?

No response

Additional information

No response

astrandb commented 1 week ago

Please fetch a diagnostic download from the device's page in HA, before and after creating the PAUSE event. You can drag the files into a reply in this issue.

The Miele API is pushing status changes when they happen (usually within a second) and the result will be reflected in HA immediately. As a fallback the integration will make a poll for status every minute.

astrandb commented 1 week ago

I have added the Pause button to applicable devices according to the API documentation. However, the function is not 100% stable. At one point when I pushed Pause the pause state was accepted by the machine but it was not correctly reflected in the API nor in the app. I had to resume (i.e. stop/start) on the washing machine to continue. When I am trying again, everything works as expected. The integration just acts on data reported in the API so the problem is at Miele API servers.

There are a few other minor issues that I will look into before releasing a new version.

kinnkler commented 1 week ago

Thank you for adding the pause button. I have now analyzed the sync of the “action buttons” again while controlling the dishwasher with the app. When I start the dishwasher, the Pause and Stop buttons become clickable as desired. Dishwasher Running:

Buttons_Running

dishwasher_running.json

If I then press Pause in the app, the event is immediately registered in Home Assistant and displayed in the log book. However, the buttons do not change. I then tested this via the manual Swagger UI API from Miele and there the action buttons 1 and 2 (Start and Stop) are reported correctly. However, according to the diagnostics file, Home Assistant still has “processAction” 2 and 3. After pressing "pause" in the Miele-app: dishwasher_pause.json Bildschirmfoto 2024-09-04 um 05 05 18

Bildschirmfoto 2024-09-04 um 05 00 06

This seems to be where the error is that after the event “Dishwasher status changes to pause” (which is displayed in the log) the processAction is not updated correctly. Even if I wait 10 minutes in the pause state, the buttons are not updated. Would it also make sense to make the API call GET /devices/actions every 60 seconds? After 10 Minutes:pause_10m.json

I then noticed that when I open the door of the dishwasher manually the buttons are updated correctly. After opening door manually: Bildschirmfoto 2024-09-04 um 05 02 15 door open.json

Opening the door is also displayed as an event in the logbook. Are the processActions only requested when an event occurs? Is there not a risk that the states will never be adjusted if a event is missed? Is there perhaps a problem that Home Assistant requests processAction too quickly after an event and the API has not yet updated it after pressing pause in the Miele-App? This would then explain that if I trigger another event afterwards, the buttons are then correctly updated. I have tested the whole thing several times and always had the same phenomenon. The funny thing is that when I press Stop in the APP, everything is updated correctly in Home-Assitstant.

astrandb commented 1 week ago

Many thanks for your detailed analysis. There is an obvious descrepancy where data from Swagger shows one set of processActions and the integration has caught something else.

It is unclear to me why this can happen. If you are interested in helping with further debugging you can try to capture the data stream from the API and perhaps see what is happening.

Pick up your active bearer token from Swagger. It will be valid for at least one hour if I remember correctly.

From a Linux prompt you can enter:

 curl -X 'GET' 'https://api.mcs3.miele.com/v1/devices/all/events' -H 'accept: text/event-stream' -H 'Authorization: Bearer YOUR_TOKEN'

You should then see all pushed data from the API as it arrives.

astrandb commented 1 week ago

I have looked into the raw data that the API returns when using the Pause action. I can see that the event stream we are subscribing to is not reflecting correct processAction data after a Pause action. Sometimes it works, though. Resubscribing the stream will return correct values immediately.

I have reported the behaviour to Miele developers but my experiance is that it can take some time to get a response. Your suggested workaround to poll the actions endpoint every minute could be a way to mitigate the problem, but it can have side effects on rate limiting since this endpoint needs a separate poll on each device in the account. Let us wait for the response from Miele developers before we introduce code changes in this area.

kinnkler commented 1 week ago

I have looked into the raw data that the API returns when using the Pause action. I can see that the event stream we are subscribing to is not reflecting correct processAction data after a Pause action. Sometimes it works, though. Resubscribing the stream will return correct values immediately.

I have reported the behaviour to Miele developers but my experiance is that it can take some time to get a response. Your suggested workaround to poll the actions endpoint every minute could be a way to mitigate the problem, but it can have side effects on rate limiting since this endpoint needs a separate poll on each device in the account. Let us wait for the response from Miele developers before we introduce code changes in this area.

Thank you for your feedback. I have now also tested it with the API event-stream and had the same behavior as you.

As soon as you press pause via the Miele app, an event appears but the progressActions are incorrect. With a GET devices/{deviceID}/actions request, however, they are correct. So the Miele API is actually wrong for a pause event. Many thanks for reporting this to Miele. Do you have the feeling it would be speeded up if I also write Miele? A temporary solution would be to manually request the API call “actions” after an event with the status “Pause”. This way you avoid the rate limit of the API.

Bildschirmfoto 2024-09-08 um 02 04 13

astrandb commented 1 week ago

Do you have the feeling it would be speeded up if I also write Miele?

No I dont think it is needed. I got a confirmation from my contact that they have put my report in the hands of right people.

astrandb commented 4 days ago

I have got response from Miele. They cannot reproduce the issue with one of their dishwashers. They need the matNumber of the IDENT object to dig in their logs. You can send it to me at ake@strandberg.eu and I will forward it to the right person.