I am running these scripts as "Execute script" and then linked it as a file.
First of all, i have used this as the starting point when modifying the script.
https://github.com/chrisz/pyhusmow
There are for better way for sure to do this, but this work.
You need requests and xmltodict installed first
You also need to enter your mail and password in the script see the line that start with mow.login
This is the script for starting the mower (Use the same script for stopping and for parking, just change the command in the script, change the line that start with mow.control)
- Code: Select all
import requests
import xmltodict
class API:
_API_IM = 'https://tracker-id-ws.husqvarna.net/imservice/rest/'
_API_TRACK = 'https://tracker-api-ws.husqvarna.net/services/'
def __init__(self):
self.session = requests.Session()
self.device_id = None
self.push_id = None
def login(self, login, password):
request = ("<login>"
" <email>%s</email>"
" <password>%s</password><language>fr-FR</language>"
"</login>") % (login, password)
response = self.session.post(self._API_IM + 'im/login',
data=request, headers={'Content-type': 'application/xml'})
response.raise_for_status()
self.session.headers.update({'Session-Token': response.headers['Session-Token']})
self.select_first_robot()
def logout(self):
response = self.session.post(self._API_IM + 'im/logout')
response.raise_for_status()
self.device_id = None
del (self.session.headers['Session-Token'])
def list_robots(self):
response = self.session.get(self._API_TRACK + 'pairedRobots_v2')
response.raise_for_status()
result = xmltodict.parse(response.content)
return result
def select_first_robot(self):
result = self.list_robots()
self.device_id = result['robots']['robot']['deviceId']
def status(self):
response = self.session.get(self._API_TRACK + 'robot/%s/status_v2/' % self.device_id)
response.raise_for_status()
result = xmltodict.parse(response.content)
return result
def geo_status(self):
response = self.session.get(self._API_TRACK + 'robot/%s/geoStatus/' % self.device_id)
response.raise_for_status()
result = xmltodict.parse(response.content)
return result
def get_mower_settings(self):
request = ("<settings>"
" <autoTimer/><gpsSettings/><drivePastWire/>"
" <followWireOut><startPositionId>1</startPositionId></followWireOut>"
" <followWireOut><startPositionId>2</startPositionId></followWireOut>"
" <followWireOut><startPositionId>3</startPositionId></followWireOut>"
" <followWireOut><startPositionId>4</startPositionId></followWireOut>"
" <followWireOut><startPositionId>5</startPositionId></followWireOut>"
" <followWireIn><loopWire>RIGHT_BOUNDARY_WIRE</loopWire></followWireIn>"
" <followWireIn><loopWire>GUIDE_1</loopWire></followWireIn>"
" <followWireIn><loopWire>GUIDE_2</loopWire></followWireIn>"
" <followWireIn><loopWire>GUIDE_3</loopWire></followWireIn>"
" <csRange/>"
" <corridor><loopWire>RIGHT_BOUNDARY_WIRE</loopWire></corridor>"
" <corridor><loopWire>GUIDE_1</loopWire></corridor>"
" <corridor><loopWire>GUIDE_2</loopWire></corridor>"
" <corridor><loopWire>GUIDE_3</loopWire></corridor>"
" <exitAngles/><subareaSettings/>"
"</settings>")
response = self.session.post(self._API_TRACK + 'robot/%s/settings/' % self.device_id,
data=request, headers={'Content-type': 'application/xml'})
response.raise_for_status()
result = xmltodict.parse(response.content)
return result
def settingsUUID(self):
response = self.session.get(self._API_TRACK + 'robot/%s/settingsUUID/' % self.device_id)
response.raise_for_status()
result = xmltodict.parse(response.content)
return result
def control(self, command):
if command not in ['PARK', 'STOP', 'START']:
raise Exception("Unknown command")
request = ("<control>"
" <action>%s</action>"
"</control>") % command
response = self.session.put(self._API_TRACK + 'robot/%s/control/' % self.device_id,
data=request, headers={'Content-type': 'application/xml'})
response.raise_for_status()
def add_push_id(self, id):
request = "id=%s&platform=iOS" % id
response = self.session.post(self._API_TRACK + 'addPushId', data=request,
headers={'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8'})
response.raise_for_status()
self.push_id = id
def remove_push_id(self):
request = "id=%s&platform=iOS" % id
response = self.session.post(self._API_TRACK + 'removePushId', data=request,
headers={'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8'})
response.raise_for_status()
self.push_id = None
if __name__ == '__main__':
retry = 5
while retry > 0:
try:
mow = API()
mow.login("mail@mail.com", "your password")#Here you need to enter your mail and password
mow.control("START")#Change the word START to STOP or PARK depending of what your command should be
retry = 0
except Exception as ex:
retry -= 1
if retry == 0:
print("[ERROR] Retrying to send the command")
else:
print("[ERROR] Failed to send the command")
exit(1)
indigo.server.log("Done")
mow.logout()