Husqvarna Automower monitoring

I’ve just installed a Husqvarna Automower robotic lawn mower. And since it’s now taking care of the lawn for me, I have time to work on HA a bit more… and why not add the lawn mower to it? The lawn mower is equipped with a SIM card and GPS unit and periodically uploads status information to a server from where it can be accessed with a mobile app. And of course someone had already implemented a command line interface to query the server and download the status: https://github.com/chrisz/pyhusmow

The pyhusmow script can run as a service which will return the status as a JSON object, which is how I configured it. My HA instance runs on an rPi which I’d like to keep as light as possible, so I set up the pyhusmow script to run as a service on another server I have:

pi@raspen:~ $ curl http://192.168.1.70:1234/status
{"lastErrorCode": 0, "latitude": 57.67328666666667, "cachedSettingsUUID": "281d72d8-1a72-44e9-9724-72deecbdc985", "positions": null, "timeBetweenPositions": 0, "mowerStatus": "OK_CUTTING", "nextStartSource": "NO_SOURCE", "gpsStatus": "USING_GPS_MAP", "lastErrorCodeTimestamp": 0, "batteryPercent": 95, "connected": true, "longitude": 12.433148333333333, "operatingMode": "AUTO", "nextStartTimestamp": 0, "secondsOld": -1474622005819, "gsmRssi": 0, "valid": true, "hostMessage": 0, "hdop": 0.0, "debugInfo": null, "configChangeCounter": 74, "storedTimestamp": 1476098103941}

I then wrote a small script that calls this service and returns one specific field:

pi@raspen:~ $ more bin/get_mower_status
#!/usr/bin/python3
import requests
import sys
try:
  field = sys.argv[1]
except:
  field = "mowerStatus"
status=requests.get("http://192.168.1.70:1234/status").json()[field]
print(status)

I call this service from a couple of command_line sensors to get the current status and battery charge to show up in HA:

sensor:
- platform: command_line
  name: Mower status
  command: /home/pi/bin/get_mower_status mowerStatus

- platform: command_line
  name: Mower battery
  command: /home/pi/bin/get_mower_status batteryPercent
  unit_of_measurement: "%"

And now I can see what the mower is up to from my HA display:

6 Likes

Nice! Now I know what lawn mower robot to buy when spring arrives! What about integrating this as a first class citizen (platform)?

2 Likes

Yes, that may be the next step. Although I am good at python coding, I am not too familiar with Github or with HA development. Is there a good tutorial somewhere?

This is a good start: https://home-assistant.io/developers/development_environment/

I’ve been thinking about this and testing pyhusmow some, but I am quite happy that someone with coding-skills took it up. Holler if you want someone to test something I’ll keep the mower outdoors a week more or so!

I don’t know how detailed the resolution of the Map in HA is, but it would make me kinda happy to see the mower roaming my lawn there :slight_smile:

Would be excellent with a more tight integration, but this is quite a step forward!

//Johan

Well, don’t expect anything soon. Mine is going into the garage for the winter this weekend, so it’s a project for next season :smile:

I would like to control the automower using IFTTT Maker Webhooks. I’m not a programmer so I’m struggling to determine the host to which the requests would be sent. Iv’e tried a few ideas on https://www.codepunker.com but no breakthroughs.

Any ideas?

Thanks!

If you install the pyhusmow script and run it as a service (which is what I do), you can use regular GET requests to control the mower, i.e http://127.0.0.1:1234/start to start it. Check out the github page I linked in the first post for more info.

I am working on a “proper” Automower component, i.e. one that doesn’t need pyhusmow running as a daemon somewhere, but will work out of the box.

Anyone interested in giving feedback (or following my progress) can check out https://github.com/yeah/home-assistant.

You need in your configuration.yaml:

automower:
    username: <your husqvarna connect email>
    password: <your husqvarna connect password>

Here’s what it currently looks like:

If anyone has more than one Automower connected to their account, I’d love your feedback in particular. In theory the mowers should be auto-discovered, but I couldn’t test this IRL yet.

Your link is not pointing anywhere, how can I try your component for the mower?

I am not sure how to package components or if that is even possible. Right now, you’d have to check out my fork on Github (where my link is pointing) and try that.

Okay but your link points to how to install home assistant
I just want to test your setup for mower

It points to his fork on Github. It includes the automower.py component he is working on. To test you’d have to clone his fork or merge his changes locally.

In theory you should be able to get by with just pulling the three files that are part of his last 13 change sets and put them in the right spot in your local install.

homeassistant/components/automower.py
homeassistant/components/device_tracker/automower.py
homeassistant/components/sensor/automower.py

1 Like

Thanks, I was going to explain that :slight_smile:

In theory, you should be able to make them work as custom components, but I haven’t had any luck with that so far, so I am just developing in place in my lokal fork. I think custom components are only loaded from <config directory>/custom_components/<component name> directly, but things like sensors, device_trackers, etc. aren’t picked up if they are in the usual sub directories (turns out, I was holding it wrong). I should do a little more digging here to make it easier to share my code…

1 Like

I had no problem adding a custom component sensor for something I was working on.
.homeassistant/custom_components/sensor/newsensor.py

1 Like

Here we go, it’s working now as a custom component. If you’re interested in checking out the current status of the Automower component, copy this .zip file into your ~/.homeassistant/ folder and unzip it.

After that, add the following to your configuration.yaml:

automower:
    username: <your husqvarna connect email>
    password: <your husqvarna connect password>

The component will add a device tracker and a vacuum (I know) to your HA instance. You’ll be able to see where your Automower is, what its status is and you’ll be able to start/stop/park it.

Here are two current screenshots:

SHA256 checksum of that zip file is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.

1 Like

Thanks for this!

Just installed it and it seems to be working fine.

1 Like

Thanks for your feedback! :grinning:

@jenslj which Automower model do you have and which model code is displayed when you click on the device tracker badge at the top? Mine was H which I translated to 450X. Happy to add your model as well.

Edit: Also, if your mower runs into any errors (outside working area, etc.) and there is no lastErrorMessage in HomeAssistant, feel free to let me know the lastErrorCode from HA and the error message displayed in the Automower app (or on its display). I’d like to add all possible error codes step by step…