home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71k stars 29.64k forks source link

Can't send commands to the mower #115480

Open gimmel opened 4 months ago

gimmel commented 4 months ago

The problem

I used the Husqvarna HACS integration before and switched to the core implementation now.

I can see all sensors and diagnose data, but I can’t start and stop the mower. That makes it quite unusable for me. After pressing „Mähen beginnen“ (don’t know the english original text, „Start mowing“ perhaps) after some time I get an overlay with „Fehler beim Aufrufen des Diensts lawn_mower/start_mowing. Command couldn't be sent to the command queue: Error from API: 404: Not Found“ Doesn't matter if I use the integration UI or the services.

I already deleted the old app on Husqvarna developer page, generated a new one, deleted the integration from Homeassistant and added it again, nothing helps.

What version of Home Assistant Core has the issue?

core-2024.4.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

husqvarna_automower

Link to integration documentation on our website

https://www.home-assistant.io/integrations/husqvarna_automower

Diagnostics information

The error log says this:

2024-04-12 17:28:43.441 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140480677314880] Command couldn't be sent to the command queue: Error from API: 404: Not Found
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aioautomower/auth.py", line 148, in _raise_for_status
    resp.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1070, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 404, message='Not Found', url=URL('https://api.amc.husqvarna.dev/v1/mowers/23277a77-6145-449c-aaf1-4eb11e64561d/actions')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/husqvarna_automower/lawn_mower.py", line 86, in async_start_mowing
    await self.coordinator.api.resume_schedule(self.mower_id)
  File "/usr/local/lib/python3.12/site-packages/aioautomower/session.py", line 164, in resume_schedule
    await self.auth.post_json(url, json=body)
  File "/usr/local/lib/python3.12/site-packages/aioautomower/auth.py", line 93, in post_json
    resp = await self.post(url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioautomower/auth.py", line 89, in post
    return await AbstractAuth._raise_for_status(resp)
           ^^^^^^^^^^^^^^^^^^^a^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aioautomower/auth.py", line 157, in _raise_for_status
    raise ApiException(": ".join(detail)) from err
aioautomower.exceptions.ApiException: Error from API: 404: Not Found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/husqvarna_automower/lawn_mower.py", line 88, in async_start_mowing
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Command couldn't be sent to the command queue: Error from API: 404: Not Found

And I have noticed that the schedule button often jumps back to on automatically after setting it to off. I found this in the log, without pressing the schedule button at all. Because this is the reason?

2024-04-12 17:28:36.795 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': '73f3239a-47a6-46ee-8f61-01cb2c737256'}}
2024-04-12 17:30:58.368 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/23277a77-6145-449c-aaf1-4eb11e64561d/actions None
2024-04-12 17:30:58.368 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ResumeSchedule'}}
2024-04-12 17:31:08.921 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': 'de561aac-e4c6-4070-bfe4-8721ea63bfaa'}}
2024-04-12 17:31:22.392 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/23277a77-6145-449c-aaf1-4eb11e64561d/actions None
2024-04-12 17:31:22.392 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ResumeSchedule'}}
2024-04-12 17:31:31.354 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': 'e897d269-5be4-40b9-8e69-68d40e571613'}}
2024-04-12 17:31:37.668 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/23277a77-6145-449c-aaf1-4eb11e64561d/actions None
2024-04-12 17:31:37.668 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ParkUntilNextSchedule'}}
2024-04-12 17:31:48.020 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': '4ea33eae-b61d-44a5-a3e7-36fc5faee152'}}
2024-04-12 17:31:54.085 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/23277a77-6145-449c-aaf1-4eb11e64561d/actions None
2024-04-12 17:31:54.085 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ResumeSchedule'}}
2024-04-12 17:32:02.992 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': '7d4cd734-2dd6-43b0-b647-57d180b7852b'}}

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 4 months ago

Hey there @thomas55555, mind taking a look at this issue as it has been labeled with an integration (husqvarna_automower) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `husqvarna_automower` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign husqvarna_automower` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


husqvarna_automower documentation husqvarna_automower source (message by IssueLinks)

gimmel commented 4 months ago

Is it possible to install the old HACS version again?

Thomas55555 commented 4 months ago

Yes, that's possible, but we don't give support for custom components and we not recommend them.

To your bugs: The flipping switch should be gone in ha 2024.5.0. But there shouldn't be commands send automatically. Can you try again after upgrading to ha 2024.5.0 (after released) and send the debug log including the error message, if it happens again?

Thomas55555 commented 4 months ago

Also the device and config entry diagnostics would be helpful.

JohKa commented 4 months ago

As mentioned in #116280 the flipping problem still exists in 2024.5.0 but I'm able now to send commands like setting the light.

gimmel commented 4 months ago

Thanks Thomas, I updated HA to version 2024.5.0 now, but I still can’t start the mower. If I press „Start mowing“, nothing happens at first, but then the schedule button activates automatically and some time later I get „Fehler beim Aufrufen des Diensts lawn_mower/start_mowing. Command couldn't be sent to the command queue: Error from API: 404: Not Found“.

https://github.com/home-assistant/core/assets/135626/8a713a7d-7bd7-4aad-bd69-1f9dd5efaf07

home-assistant_husqvarna_automower_2024-05-03T09-39-49.719Z.log

husqvarna_automower-4c3c56dee42c2ece46582f70a90186c5-Sprout-8aa689a45e73ba81655d5b2aab061b6a.json

Thomas55555 commented 4 months ago

For me the first part looks alright. If you click "Mähen beginnen", then the same command will be sent, like when you click "Zeitplan aktivieren". The command is called "ResumeSchedule", like mentions in the docs. This is because the API can't force the mower to just start, expect if we would force it to mow for a given duration. As the entity model of HA and the API of Husqvarna don't fit 100%, it unfortunately like this. Regarding the 404 error: I'm not sure, where this is coming from. Maybe, the config entry diagnostics could be helpful. You send the device diagnostics.

jasoncross commented 4 months ago

I'm still getting the issue where enable schedule turns itself back on right after turning it off. Running 2024.5.0. Logs attached.

home-assistant_husqvarna_automower_2024-05-03T13-47-48.367Z.log

Thomas55555 commented 4 months ago

I'm still getting the issue where enable schedule turns itself back on right after turning it off. Running 2024.5.0. Logs attached.

home-assistant_husqvarna_automower_2024-05-03T13-47-48.367Z.log

But as I can see in the logs, the mower received the command ParkUntilFurtherNotice and then started to go home. After the mower went home, was the switch in the right position?

jasoncross commented 4 months ago

Maybe it would help to understand better what the Enable Schedule switch is equivalent to with the Automower? Is it Parked? When flipped do I also need to tell it to return to dock? If flipped and returning to dock and I want to cancel, do I just flip it again or need to tell it to start mowing too?

gimmel commented 4 months ago

I think we have a big misunderstanding here. I thought the service "lawn_mower.start_moving" would start the mowing process. But apparently the Husqvarna mower can only follow the schedule and the integration can only switch the schedule on and off. Could it be that the play and pause buttons only switch on and off the schedule? So perhaps the integration works as expected and my expectations are wrong?

In the Husqvarna app, I press the play button and then tap "Schedule off - 3 hours" to start the mower directly. But it also took me a long time to understand Husqvarna's operating strategy in the app. Husqvarna has a strange usage strategy ;-)

Thomas55555 commented 3 months ago

So Here the explanation: If you turn the schedule on, the command resume schedule is sent to the mower. It's the same command like you send with the start button. After turning this on the switch should flip instantly and stay there If you turn the schedule off, the command park until further notice is sent. If the mower is already in the dock, than the switch should instantly flip to off and stay there. If the mower is not in the dock, and you turn the schedule off, then the switch should also go off instantly, but flips back to on after a while. When the mower arrived in the dock, then the switch should go off again. Is the problem with sending commands not possible finally solved?

davidm-glitch commented 3 months ago

Does that mean, that there is no way to start the mower manually from HA?

gimmel commented 3 months ago

Is the problem with sending commands not possible finally solved?

That’s hard to say, because we don’t exactly know what the intended functionality is. If I understand you right, the button „Start mowing“ does not start mowing, but just activates the schedule? And all buttons (play, pause) have just the function to start and pause the schedule? Is that right?

Thomas55555 commented 3 months ago

'Start mowing' and the play button is the same. No idea, why HA makes two buttons there. Enable schedule is also the same. Pause just pauses the mower. Example: mower is mowing and you press pause, than the mower makes a break. If you click on the dock button, then the mower parks until the next schedule.

gimmel commented 3 months ago

I think that is the main problem. People expect the mower to start mowing if they press „start mowing“. But what it does is „enable schedule“.

But there is an Husqvarna API command for „Start“. That should be used instead of „ResumeSchedule“.

Button Start Mowing/Play -> API Start Button Pause -> API Pause Button Dock -> API ParkUntilNextSchedule or ParkUntilFurtherNotice (depending on Enable Schedule) Switch Enable Schedule -> API ParkUntilFurtherNotice/ResumeSchedule

That is the only way we can actively control the mower.

What "start moving" is doing now:

Husqvarna ResumeSchedule

What "start moving" should do:

Husqvarna Start
Thomas55555 commented 3 months ago

But there is always a duration required for start. So if this time is over, the people wonder, why it stopped.

Thomas55555 commented 3 months ago

There is also another way, how you can actively control the mower: when you have a schedule enabled 24/7. And than say: Resume schedule, then the mower starts. And if you disable the schedule, the mower parks until further notice....

gimmel commented 3 months ago

There is also another way, how you can actively control the mower: when you have a schedule enabled 24/7. And than say: Resume schedule, then the mower starts. And if you disable the schedule, the mower parks until further notice....

Yes, but who wants a workaround to make a new integration work like expected? Schedule and manual control are different things and should be treated as that. The mower documentation clearly says what the functions should do. It says "Start or resume a mowing task", not „Enable schedule“.

But there is always a duration required for start. So if this time is over, the people wonder, why it stopped.

You could define an input field for that or simply set the value to 24 hours.

Thomas55555 commented 3 months ago

You are right it's not 100% correct. But for me it seems better to return the schedule. Maybe another user wants to start the mower for 25h or forever, than her would open an issue for that. To be 100% correct, than the lawn mower entity should only have the pause button. The other commands have to be done over buttons and services. Btw. I've opened a pull request for the star for command as a service. If everything works, then it will be in the next release.

jasoncross commented 3 months ago

My problem is that I can't get the mower to resume mowing.

I have an automation that parks the mower at its base when rain starts and resumes mowing 3 hours after rain ends.

When rain starts, I turn off the "Enable Schedule" switch. This sends it home.

When rain ends, I have tried both turning back on Enable Schedule as well as Starting the mower, but no matter what it stays parked until further notice

Logs attached.

home-assistant_husqvarna_automower_2024-05-14T16-51-23.360Z.log .

gimmel commented 3 months ago

You are right it's not 100% correct. But for me it seems better to return the schedule.

Come on, your integration is now an official part of Homeassistant and uses the internal mower implementation. Imagine if every integration used the light implementation differently, or switches or media players. You would have to search for a long time to find out how this one integration works. That's why there are global integrations like mowers and lights: you only control one device abstraction and this then controls the device via an integration. This is one of the many advantages of Homeassistant. For example, I can replace my mower with another model and everything continues to work as before. However, this does not work if each integration follows a different strategy.

To be 100% correct, than the lawn mower entity should only have the pause button.

No, the other way around: the mower abstraction has this buttons with a reason. You need them for automations, you need them to control the mower. If you just want to use the Husqvarna schedule, you don’t need a Homeassistant integration at all.

Maybe another user wants to start the mower for 25h or forever.

The play button should simply start the mower - without a time limit. That's what the dock button is made for. This can all be controlled wonderfully via automations. If a user wants to run the mower for 25 hours, his automation sends a play and 25 hours later a dock. Why not setting the Husqvarna API Start duration to 20 years? It’s an unsigned int64. You can set it even to 18,446,744,073,709,551,615 minutes. These are 35 Trillion years. The sun will have gone out by then. And Husqvarna, too. 😉

gimmel commented 3 months ago

When rain starts, I turn off the "Enable Schedule" switch. This sends it home.

When rain ends, I have tried both turning back on Enable Schedule as well as Starting the mower, but no matter what it stays parked until further notice

I think your schedule is over after 3 hours. This integration can’t start your mower. It only enables and disables the schedule.

coachdesign commented 3 months ago

My problem is that I can't get the mower to resume mowing.

I have an automation that parks the mower at its base when rain starts and resumes mowing 3 hours after rain ends.

When rain starts, I turn off the "Enable Schedule" switch. This sends it home.

When rain ends, I have tried both turning back on Enable Schedule as well as Starting the mower, but no matter what it stays parked until further notice

Logs attached.

home-assistant_husqvarna_automower_2024-05-14T16-51-23.360Z.log .

with the old unofficial version, I had about the same automaticity, depending on how much it rained I sent a "return to base" command for N minutes. with this new official version it is no longer possible to do so.

I think your schedule is over after 3 hours. This integration can’t start your mower. It only enables and disables the schedule.

logically I also tried to set "disable schedule" and after N hours "enable schedule", but it doesn't work, how can you reproduce this automation?

jasoncross commented 3 months ago

When rain starts, I turn off the "Enable Schedule" switch. This sends it home. When rain ends, I have tried both turning back on Enable Schedule as well as Starting the mower, but no matter what it stays parked until further notice

I think your schedule is over after 3 hours. This integration can’t start your mower. It only enables and disables the schedule.

My schedule in the app is set to 24x7 effectively.

Someguitarist commented 1 month ago

+1 to returning it to the way the old HACS integration worked. Sending the automower to the base and starting again used to work great, doesn't work now. Pausing for rain and starting after a set time doesn't work now either.

I get wanting the simplicity of just enabling and disabling the schedule, but for the most part you've got slightly more advanced users who want some additional control over things.

While I'm glad this is officially integrated into HA and I'm incredibly grateful for your work, making a lot of changes to how it functions at the same time it was integrated into HA wasn't quite the best choice.

Anyways, hope you can return it to the previous way it worked. At the moment I'll be rolling back to the HACS integration, unfortunately.

gimmel commented 1 month ago

+1 to make the integration work like described in the Lawn mower documentation: https://www.home-assistant.io/integrations/lawn_mower/ which seems to be the behavior of the old HACS implementation.

Homeassistant Lawn mower documentation

START_MOWING: Start or resume a mowing task. PAUSE: Pause a mowing task. DOCK: Tell the lawn_mower to return to dock.

That should be completely independent from the schedule of the Husqvarna app, which is another way to start the mower that has nothing to do with the HomeAssistant implementation. (I would like to have the possibilty to set the Husqvarna schedule to twice a week and additionally activate the mower Immediately via a HomeAssistant button if necessary.)

The Husqvarna API has commands for exactly that:

Husqvarna Automower® Connect API

Start - Start the mower for a period of minutes (could be set to a high value, because START_MOVING contains no stop) Pause - Pause the mower ParkUntilNextSchedule or ParkUntilFurtherNotice (should depend on schedule on/off setting)

The schedule can be activated again if switch changes from off to on: ResumeSchedule - Removes any override on the Planner and let the mower resume to the schedule set by the Calendar

sinumsen commented 3 weeks ago

Already told my wife and neighbors how smart I will be with my new 450x Nero with satellite positioning - and all words spread to them with my really pro attitude... Now I just feel like a stupid nerd that can flash them with some home assistant stuff that can only do... well nothing...

I can use my Husquarna app of course, but that's not why we are in here... And like @gimmel has already argumentet, not the functionality as it is now, we wold expect from an integration to HA

@Thomas55555 is there any news on the ability to start the mower as I read in your post above?

ftbboy2115 commented 3 weeks ago

@Thomas55555 I too am hoping for the functionality that @gimmel has described.

Thomas55555 commented 3 weeks ago

Already told my wife and neighbors how smart I will be with my new 450x Nero with satellite positioning - and all words spread to them with my really pro attitude... Now I just feel like a stupid nerd that can flash them with some home assistant stuff that can only do... well nothing...

I can use my Husquarna app of course, but that's not why we are in here... And like @gimmel has already argumentet, not the functionality as it is now, we wold expect from an integration to HA

@Thomas55555 is there any news on the ability to start the mower as I read in your post above?

Yes, since HA 2024.7.0 It's described here: https://www.home-assistant.io/integrations/husqvarna_automower/#actions The action (formerly known as service) is called override schedule. You can just make a button which triggers the action.

martamoonpie commented 3 weeks ago

Already told my wife and neighbors how smart I will be with my new 450x Nero with satellite positioning - and all words spread to them with my really pro attitude... Now I just feel like a stupid nerd that can flash them with some home assistant stuff that can only do... well nothing... I can use my Husquarna app of course, but that's not why we are in here... And like @gimmel has already argumentet, not the functionality as it is now, we wold expect from an integration to HA @Thomas55555 is there any news on the ability to start the mower as I read in your post above?

Yes, since HA 2024.7.0 It's described here: https://www.home-assistant.io/integrations/husqvarna_automower/#actions The action (formerly known as service) is called override schedule. You can just make a button which triggers the action.

But that's not what we want. With the integration I had before it was an official integration, home assistant controlled my mower completely based on things that I wanted. Odd days only because the hose is out watering my veggies on even days. If it rained 5 inches (which it did today), I don't want the mower to run because of standing water. I have sensors that controlled all of this and it was perfect. I want to be able to tell the mower when to start and when to stop. I don't want to have to tell it how long to do so each time. I don't want to override the schedule. Why can't it just work the way it did before? It's useless to me the way it is now. I've also noticed it is sooooo slow at updating status. It used to be nearly instantaneous. Now it's upwards of 10 minutes.

Thomas55555 commented 3 weeks ago

Already told my wife and neighbors how smart I will be with my new 450x Nero with satellite positioning - and all words spread to them with my really pro attitude... Now I just feel like a stupid nerd that can flash them with some home assistant stuff that can only do... well nothing... I can use my Husquarna app of course, but that's not why we are in here... And like @gimmel has already argumentet, not the functionality as it is now, we wold expect from an integration to HA @Thomas55555 is there any news on the ability to start the mower as I read in your post above?

Yes, since HA 2024.7.0 It's described here: https://www.home-assistant.io/integrations/husqvarna_automower/#actions The action (formerly known as service) is called override schedule. You can just make a button which triggers the action.

But that's not what we want. With the integration I had before it was an official integration, home assistant controlled my mower completely based on things that I wanted. Odd days only because the hose is out watering my veggies on even days. If it rained 5 inches (which it did today), I don't want the mower to run because of standing water. I have sensors that controlled all of this and it was perfect. I want to be able to tell the mower when to start and when to stop. I don't want to have to tell it how long to do so each time. I don't want to override the schedule. Why can't it just work the way it did before? It's useless to me the way it is now. I've also noticed it is sooooo slow at updating status. It used to be nearly instantaneous. Now it's upwards of 10 minutes.

But that's what @sinumsen asked.

Sorry, I don't understand what you want. The function is the same like it was it in the custom component. It just changed from vacuum to lawn mower.