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: