LG VHOMBOT3 status into Domoticz

From Domoticz
(Redirected from LG VHOMBOT3)
Jump to: navigation, search

Connect the HOMBOT to the internet

The LG VHOMBOT 3 is a robot dust/vacuum cleaner that can be controlled with the remote control that comes with it. Out of the box it isn't possible to connect the LG VHOMBOT 3 to your WiFi network. To be able to connect the HOMBOT to Domoticz and/or control the HOMBOT, even when you are not at home, you need to follow the steps on this page first. This is the original forum where all (updated) files can be found that you need. The forum is in German and you need an account to download the files. This can be easliy made for free. Rob van Hamersveld translated this German guide into English that can be found here. On this page you can download the files without an account, but remember to always check for the latest version of the software that can be found on the original German forum.


Make your Hombot controllable within Domoticz

Assuming that you have connected your Hombot to the internet succesfully, we now want to control our Hombot with Domoticz. This will be done with JSON commands. These are the basic commands:

Start cleaning:
http://Your-Hombot-ip-address:6260/json.cgi?%7b%22COMMAND%22:%22CLEAN_START%22%7d
 
Pause cleaning:
http://Your-Hombot-ip-address:6260/json.cgi?%7b%22COMMAND%22:%22PAUSE%22%7d
 
Stop cleaning (= back to dock)
http://Your-Hombot-ip-address:6260/json.cgi?%7b%22COMMAND%22:%22HOMING%22%7d


Here you can find more commands.


Steps

1. In Domoticz you'll want to create a virtual dummy switch. Give it a name e.g. "Control Hombot" and add it to your page with switches.

2. Create a bash script for each command. For example: Start cleaning

#!/bin/bash
curl http://Your-Hombot-ip-address:6260/json.cgi?%7b%22COMMAND%22:%22CLEAN_START%22%7d


3. Upload your created Bash script(s) to your RPi, NAS or any other device that you are using. You can do this with Filezilla or WinSCP for example.

4. Login with SSH and browse to the location of your script. E.g. cd domoticz/scripts/bash Now make your script(s) executable with the sudo chmod +x yourfilename.sh command. You can do this with Terminal (MAC) or Putty for example. To test it, run it while you are in the same directory of your file with ./yourfilename.sh

5. Now, edit your switch that you created at step 1. At the Switch on box, fill in the location of your script with the start cleaning command. Repeat the same for the off box for your stop cleaning script.


In my case this is:

On command

script:///home/pi/domoticz/scripts/bash/HomieStart.sh

Off command

script:///home/pi/domoticz/scripts/bash/HomieStop.sh


6. Save your switch and you are able to control your Hombot!


Get the status of your Hombot in Domoticz

Now that you are able to start/stop etc. your Hombot with Domoticz, it would be really useful to see what the status of your Hombot is, especially, if you want to use your Hombot with smart LUA or Blockly scripts.


Steps

1. To do this, you first want to create a virtual text sensor in Domoticz for each piece of Hombot information that you want to see in Domoticz. In my case, I have 2 virtual text switches. One for the status of the Hombot and one for the batterystatus of the Hombot. To create a virtual text switch, you create a normal virtual dummy switch. When this is done, you browse to your hardware tab in Domoticz. Search for your created virtual dummy switch and press on the corresponding create virtual sensor button. Choose text from the dropdown menu and press ok.

These switches will only be used to display the info in your Domoticz environment.

2. Secondly, you want to create a user variable in Domoticz for each piece of Hombot information that you want to see in Domoticz. In my case, I have 2 user variables for this. One for the status of the Hombot and one for the batterystatus of the Hombot. Create one variable with the name HombotStatus with variable type "string" and give it a random value. Create the second variable with the name HombotBatStatus with variable type integer and give it a random number value. These values will be altered later by the script. As for the variable names, you can give them other names if you like, but then don't forget to change the names in the script in accordance with the names of your variables in Domoticz.

The user variables are meant to be used in LUA/Blockly events.

3. Now create a new Bash script with the following code:

#!/bin/bash
 
#HombotStatus.sh
#Get status LG VHOMBOT3 into Domoticz
#Domoticz Wiki page URL: http://www.domoticz.com/wiki/LG_VHOMBOT3_status_into_Domoticz
#Author: Skorpion
#Date: 17-04-2015
#Version: 1.2
#1.1 - Added ping check so off status is sent to Domoticz when Hombot is off or unreachable
#1.2 - Added Var check so that it's possible to use the status in Blockly events. The data from the text sensor itself will not work in Blocky events because the text sensor data can't be compared and will return nil.
 
 
     # Settings - Edit to your situation
 
     HOMBOTIP="Your-Hombot-ip-address"                     # HOMBOT IP Address
     HOMBOT_PORT="6260"                                    # HOMBOT Port
     DOMO_IP="Your-Domoticz-ip-address"                    # Domoticz IP Address
     DOMO_PORT="Your-Domoticz-port"                        # Domoticz Port
     HOMBOT_STATUS_IDX="your text switch IDX"              # HOMBOT status IDX
     HOMBOT_BATTERY_STATUS_IDX="your text switch IDX"      # HOMBOT Battery status IDX
     HombotStatus_VAR_NAME="HombotStatus"		   # Name of variable in Domoticz for HombotStatus Var
     HombotStatus_VAR_IDX="Your IDX"		           # IDX of variable in Domoticz for HombotStatus Var
     HombotStatus_VAR_TYPE="2"				   # Type of variable in Domoticz for HombotStatus Var, see explanation
     HombotBatStatus_VAR_NAME="HombotBatStatus"		   # Name of variable in Domoticz for HombotBatStatus Var
     HombotBatStatus_VAR_IDX="Your IDX"		           # IDX of variable in Domoticz for HombotBatStatus Var
     HombotBatStatus_VAR_TYPE="0"		       	   # Type of variable in Domoticz for HombotStatus Var, see explanation 
 
 
   # Domoticz variable type explanation 
   #  0 = Integer, e.g. -1, 1, 0, 2, 10 
   #  1 = Float, e.g. -1.1, 1.2, 3.1
   #  2 = String
   #  3 = Date in format DD/MM/YYYY
   #  4 = Time in 24 hr format HH:MM
 
  #----------- End of settings -----------------
 
    #Check if Hombot is on/online 
    if ping -c 1 $HOMBOTIP &> /dev/null
then
# If true, Hombot is on and the following code will be executed.
  echo 'Hombot is aan'
 
 
 
    ##Get data from status.txt and place text status.txt in new file named Hombot.txt  
    curl http://$HOMBOTIP:$HOMBOT_PORT/status.txt  > Hombot.txt
 
	#Change text CHARGING to Laden
	sed -i 's/CHARGING/Laden/g' Hombot.txt
 
	#Change text Pause to Pauze
	sed -i 's/PAUSE/Pauze/g' Hombot.txt
 
	#Change text BACKMOVING-INIT to Positioneren
	sed -i 's/BACKMOVING-INIT/Positioneren/g' Hombot.txt
 
	#Change text Working to Bezig
	sed -i 's/WORKING/Bezig/g' Hombot.txt
 
	#Change text HOMING to NaarOplader
	sed -i 's/HOMING/NaarOplader/g' Hombot.txt
 
	#Change text Docking to OpladerBetreden
	sed -i 's/DOCKING/OpladerBetreden/g' Hombot.txt
 
	#Change text STANDBY to Standby
	sed -i 's/STANDBY/Standby/g' Hombot.txt
 
 
 
  # Hombot Status
           HombotStatus=`grep -oP '(?<=JSON_ROBOT_STATE=").*(?<=")' Hombot.txt`
           #Remove "" Characters from string
		   HombotStatus=`echo $HombotStatus | sed -e 's/^"//'  -e 's/"$//'` 
 
            # Send data
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HOMBOT_STATUS_IDX&nvalue=0&svalue=$HombotStatus"
 
  #Compare status Hombot and send corresponding value to variable          
	 if [ $HombotStatus = "Laden" ];
 then
		    # Send data
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=Laden"
 
            elif [ $HombotStatus = "Bezig" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=Bezig"
 
            elif [ $HombotStatus = "Pauze" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=Pauze"
 
             elif [ $HombotStatus = "NaarOplader" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=NaarOplader"
 
             elif [ $HombotStatus = "OpladerBetreden" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=OpladerBetreden"
 
             elif [ $HombotStatus = "Standby" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=Standby"
 
             elif [ $HombotStatus = "Positioneren" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=Positioneren"
 
 
 
fi
 
 
# Battery Status
           HombotBatStatus=`grep -oP '(?<=JSON_BATTPERC=").*' Hombot.txt`
           #Remove "" Characters from string
		   HombotBatStatus=`echo $HombotBatStatus | sed -e 's/^"//'  -e 's/"$//'`
 
 
            # Send data
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HOMBOT_BATTERY_STATUS_IDX&nvalue=0&svalue=$HombotBatStatus"
 
 
              #Compare battery status Hombot and send corresponding value to variable          
	 if [ $HombotBatStatus = "100" ];
 then
		    # Send data
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotBatStatus_VAR_IDX&vname=$HombotBatStatus_VAR_NAME&vtype=$HombotBatStatus_VAR_TYPE&vvalue=100"
 
            elif [ $HombotBatStatus = "80" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotBatStatus_VAR_IDX&vname=$HombotBatStatus_VAR_NAME&vtype=$HombotBatStatus_VAR_TYPE&vvalue=80"
 
            elif [ $HombotBatStatus = "60" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotBatStatus_VAR_IDX&vname=$HombotBatStatus_VAR_NAME&vtype=$HombotBatStatus_VAR_TYPE&vvalue=60"
 
             elif [ $HombotBatStatus = "40" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotBatStatus_VAR_IDX&vname=$HombotBatStatus_VAR_NAME&vtype=$HombotBatStatus_VAR_TYPE&vvalue=40"
 
             elif [ $HombotBatStatus = "20" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotBatStatus_VAR_IDX&vname=$HombotBatStatus_VAR_NAME&vtype=$HombotBatStatus_VAR_TYPE&vvalue=20"
 
             elif [ $HombotBatStatus = "0" ];
            then
             curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotBatStatus_VAR_IDX&vname=$HombotBatStatus_VAR_NAME&vtype=$HombotBatStatus_VAR_TYPE&vvalue=0"
 
 
fi
 
# If ping result is false, Hombot is off, the code above will be skipped and the following code will be executed.          
            else
  echo 'Hombot is uit'
 
   # Hombot Status
           HombotStatus='Uit'
 
             # Send data to HombotStatus text sensor
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HOMBOT_STATUS_IDX&nvalue=0&svalue=$HombotStatus"
 
		    # Send data to HombotStatus variable
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotStatus_VAR_IDX&vname=$HombotStatus_VAR_NAME&vtype=$HombotStatus_VAR_TYPE&vvalue=Uit"
 
 
 
# Battery Status
           HombotBatStatus='-'
 
 
            # Send data to HombotBatStatus text sensor
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HOMBOT_BATTERY_STATUS_IDX&nvalue=0&svalue=$HombotBatStatus"
 
             # Send data to HombotBatStatus variable
            curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=updateuservariable&idx=$HombotBatStatus_VAR_IDX&vname=$HombotBatStatus_VAR_NAME&vtype=$HombotBatStatus_VAR_TYPE&vvalue=000"
 
fi

Remember to adjust the IP, IDX etc. under "settings" to your situation.

You can check your variable IDX's with the following URL: http://DomoticzIP:DomoticzPORT/json.htm?type=command&param=getuservariables


3. Upload this created Bash script to your RPi, NAS or any other device that you are using.

4. Login with SSH and browse to the location of your script. E.g. cd domoticz/scripts/bash Now make your script(s) executable with the sudo chmod +x yourfilename.sh. To test it, run it while you are in the same directory of your file with ./yourfilename.sh

5. Now we want to have this script run every minute. To do this, type the following while you are still logged in to your device with SSH.: ==crontab -e==


Add this line in the crontab file:

*/1 * * * * /home/pi/domoticz/scripts/bash/YOURHombotStatusfile.sh

(Note: I located all my Bash scripts in a folder called bash. Create this folder in your scripts folder or edit the directory location to your situation)


6. Save your crontab and exit.


Now the status of your Hombot will be updated in Domoticz! Because the crontab runs the script every minute, the status in Domoticz can have a delay of max. 1 minute towards the actual status of your Hombot.

All information of the Hombot can be found at http://Your-Hombot-ip-address:6260/status.txt. You can copy/paste parts in the script to add more information from your Hombot into Domoticz. Don't forget to create a virtual text switch for each piece of information that you want to have in Domoticz!