I recently switched from Domoticz to HASS and one thing I really missed was the integration with my LG Hom Bot robot vacuum so that I can control it with presence detection, automation etc. I adapted the original script found here and got it to work with hass with minimum effort. Here’s how I did it. I’m pretty sure there’s a more elegant way to do it but I’m a total noob when it come to writing code so I did all of it with a command line switch and sensor.
First of all you’ll need to make your HomBot wifi-capable. There’s an excellent tutorial online written by Rob Van Hamersveld which you guys can find right here. Also make sure your vacuum has a static IP adres.
Then, create a shell script called hombot.sh and save it in your home dir. Don’t forget to make it executable with sudo +x
And that’s basically it. Only thing that’s kind off a bummer is that it takes a maximum of 60 seconds for the status to update when you engage the hombot but I can live with that :).
I took a slightly more complicated approach with a Python script that downloads the status.txt file and that will change the status of the Hom Bot in my HASS UI when the Hom Bot is offline, or when lg.srv has crashed. I also have a second Python script that downloads the statistic.html page and scrapes it for the number of finished runs, so HASS can send me a notification whenever my Hom Bot actually finishes a run.
Oh, and based on the modification timestamp of the local copies of status.txt and statistic.html, my sensors only seem to contact my Hom Bot every 90 seconds…not sure why. I wish I could have that happen more frequently, especially to determine the status of the Hom Bot.
Thanks for sharing this!
I have tried to get this working here… a few changes were needed to get the commands to working but the status update doesn’t work. I changed the switch definition like this:
switch:
platform: command_line
switches:
hombot:
command_on: "curl GET http://1HOMBOTIP:HOMBOTPORT/json.cgi?%7b%22COMMAND%22:%22CLEAN_START%22%7d"
command_off: "curl GET http://HOMBOTIP:HOMBOTPORT/json.cgi?%7b%22COMMAND%22:%22HOMING%22%7d"
command_state: grep -oP '(?<=JSON_ROBOT_STATE=").*(?<=")' /home/pi/Hombot.txt | sed -e 's/^"//' -e 's/"$//'
value_template: '{{ return_value == "WORKING" }}'
friendly_name: LG HomBot
So using command_on and command_off, value_template and “WORKING” as my Hombot returns. I can see the status “WORKING” as a sensor value and also when executing the grep command manually, but the switch never shows “on”, and so switching off is not possible. Any idea what’s wrong?
Thanks for the tip of changing the scan_interval, but the Sensor is based on a Txt File that is generated with a Cronjob. And unfortunately this Cronjobs runs once per minute. So If you could share the scripts that would be awesome
The above took alot of Googling, as well as trial and error, as I’m not familiar with Python. In other words: the scripts may not be as elegant or efficient as they could be. They also took some tweaking as the webserver (lg.srv) would originally crash within less than 24 hours, probably due to simultaneous requests.
I have been running these scripts for months now without issues. The webserver lg.srv has been super stable. However, I do occasionally get an error in the HASS log stating that running the command from one of the sensors failed, but I’m putting those down to connection drops.