Get Roomba/Thinking Cleaner Status

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Get Roomba/Thinking Cleaner Status

Post by Skippiemanz »

After getting inspired by this topic http://www.domoticz.com/forum/viewtopic ... bot#p39453 Where the status off the Hombot vacuum cleaner was displayed in Domoticz i got curious to do the same with my Roombo iRobot 587 with the Thinking Cleaner Wifi plate.

But i got a little Stuck.

From the thinking cleaner i now use the status.xml, it containts the following data

Code: Select all

<status>
<name>Thinking</name>
<modelnr>86</modelnr>
<battery_charge>86</battery_charge>
<cleaner_state>st_wait</cleaner_state>
<cleaning>0</cleaning>
<near_homebase>1</near_homebase>
<bin_status>0</bin_status>
<cleaning_time>54</cleaning_time>
<light_bump>0</light_bump>
<virtual_wall>0</virtual_wall>
<wall>0</wall>
<bumper_state>0</bumper_state>
</status>
Ive changed the Hombot script to the following script:

Code: Select all

 #!/bin/bash

     # Settings

     ROOMBAIP="192.168.165.23"                  # Roomba IP Address
     DOMO_IP="192.168.165.10"                   # Domoticz IP Address
     DOMO_PORT="9090"                           # Domoticz Port
     ROOMBA_STATUS_IDX="123"                            # Roomba status IDX
     ROOMBA_BATTERY_STATUS_IDX="your text switch IDX"      # Roomba Battery status IDX




    #Get data from status.txt and place text status.txt in new file named Roomba.txt
    curl http://$ROOMBAIP/status.xml  > Roomba.txt

#EXAMPLE /WORKING/You can name this word here to whatever you like/g' Roomba.txt

sed -i 's/st_base/On homebase: Not Charging/g' Roomba.txt
sed -i 's/st_base_recon/On homebase: Reconditioning Charging/g' Roomba.txt
sed -i 's/st_base_full/On homebase: Full Charging/g' Roomba.txt
sed -i 's/st_base_trickle/On homebase: Trickle Charging/g' Roomba.txt
sed -i 's/st_base_wait/On homebase: Waiting/g' Roomba.txt
sed -i 's/st_plug/Plugged in: Not Charging/g' Roomba.txt
sed -i 's/st_plug_recon/Plugged in: Reconditioning Charging/g' Roomba.txt
sed -i 's/st_plug_full/Plugged in: Full Charging/g' Roomba.txt
sed -i 's/st_plug_trickle/Plugged in: Trickle Charging/g' Roomba.txt
sed -i 's/st_plug_wait/Plugged in: Waiting/g' Roomba.txt
sed -i 's/st_stopped/Stopped/g' Roomba.txt
sed -i 's/st_clean/Cleaning/g' Roomba.txt
sed -i 's/st_cleanstop/Stopped with cleaning/g' Roomba.txt
sed -i 's/st_clean_spot/Spot cleaning/g' Roomba.txt
sed -i 's/st_clean_max/Max cleaning/g' Roomba.txt
sed -i 's/st_delayed/Delayed cleaning will start soon ../g' Roomba.txt
sed -i 's/st_dock/Searching Homebase/g' Roomba.txt
sed -i 's/st_pickup/Roomba picked up/g' Roomba.txt
sed -i 's/st_remote/Remote control driving/g' Roomba.txt
sed -i 's/st_wait/Waiting for command/g' Roomba.txt
sed -i 's/st_off/Off/g' Roomba.txt
sed -i 's/st_error/Error/g' Roomba.txt
sed -i 's/st_locate/Find me!/g' Roomba.txt
sed -i 's/st_unknown/Unknown state/g' Roomba.txt

# Roomba Status
           RoombaStatus=`grep -oP '(?<=cleaner_state=").*(?<=")' Roomba.txt`
           #Remove "" Characters from string
                  #RoombaStatus=`echo $RoombaStatus | 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=$ROOMBA_STATUS_IDX&nvalue=0&svalue=$RoombaStatus"
This results in the following debug log of bash:

Code: Select all

pi@raspberrypi:~/domoticz/scripts/bash$ bash -x Roomba.sh
+ ROOMBAIP=192.168.165.23
+ DOMO_IP=192.168.165.10
+ DOMO_PORT=9090
+ ROOMBA_STATUS_IDX=123
+ ROOMBA_BATTERY_STATUS_IDX='your text switch IDX'
+ curl http://192.168.165.23/status.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   276    0   276    0     0   3416      0 --:--:-- --:--:-- --:--:--  4928
+ sed -i 's/st_base/On homebase: Not Charging/g' Roomba.txt
+ sed -i 's/st_base_recon/On homebase: Reconditioning Charging/g' Roomba.txt
+ sed -i 's/st_base_full/On homebase: Full Charging/g' Roomba.txt
+ sed -i 's/st_base_trickle/On homebase: Trickle Charging/g' Roomba.txt
+ sed -i 's/st_base_wait/On homebase: Waiting/g' Roomba.txt
+ sed -i 's/st_plug/Plugged in: Not Charging/g' Roomba.txt
+ sed -i 's/st_plug_recon/Plugged in: Reconditioning Charging/g' Roomba.txt
+ sed -i 's/st_plug_full/Plugged in: Full Charging/g' Roomba.txt
+ sed -i 's/st_plug_trickle/Plugged in: Trickle Charging/g' Roomba.txt
+ sed -i 's/st_plug_wait/Plugged in: Waiting/g' Roomba.txt
+ sed -i s/st_stopped/Stopped/g Roomba.txt
+ sed -i s/st_clean/Cleaning/g Roomba.txt
+ sed -i 's/st_cleanstop/Stopped with cleaning/g' Roomba.txt
+ sed -i 's/st_clean_spot/Spot cleaning/g' Roomba.txt
+ sed -i 's/st_clean_max/Max cleaning/g' Roomba.txt
+ sed -i 's/st_delayed/Delayed cleaning will start soon ../g' Roomba.txt
+ sed -i 's/st_dock/Searching Homebase/g' Roomba.txt
+ sed -i 's/st_pickup/Roomba picked up/g' Roomba.txt
+ sed -i 's/st_remote/Remote control driving/g' Roomba.txt
+ sed -i 's/st_wait/Waiting for command/g' Roomba.txt
+ sed -i s/st_off/Off/g Roomba.txt
+ sed -i s/st_error/Error/g Roomba.txt
+ sed -i 's/st_locate/Find me!/g' Roomba.txt
+ sed -i 's/st_unknown/Unknown state/g' Roomba.txt
++ grep -oP '(?<=cleaner_state" :").*(?<=")' Roomba.txt
+ RoombaStatus=
+ curl -s -i -H 'Accept: application/json' 'http://192.168.165.10:9090/json.htm?type=command&param=udevice&idx=123&nvalue=0&svalue='
HTTP/1.0 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache

{
   "status" : "OK",
   "title" : "Update Device"
}
Im not that big in scripting so who can give me a help in the right direction?

It probably has something to do with the way the text is written in the Roomba.txt file compared to the Hombot.txt file

In the Hombot it is:

Code: Select all

JSON_ROBOT_STATE="CHARGING"
And in the Roomba/Thinking Cleaner it is:

Code: Select all

<cleaner_state>st_wait</cleaner_state>
Perhaps its easier to get the satus directly from the Thinking cleaner Json. But thats all very new to me. The have a very detailed API Guide: http://www.thinkingcleaner.com/downloads/TC_API.pdf

Help would be aprecciated.

I the status is working i want to interper the battery charge en wifi signal strength also using the &rssi=10&battery=89 command found in the wiki.
Skorpion
Posts: 27
Joined: Thursday 15 January 2015 9:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by Skorpion »

If you try it with this, it must work.

Code: Select all

RoombaStatus=`grep -oP '(?<=<cleaner_state>).*(?<=</cleaner_state>)' Roomba.txt`
Repeat this for the other data you want to get in Domoticz.

PS. You can find a new version of my script at the wiki. I added code so you can use user variables in combination with LUA or Blocky. ;)
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by Skippiemanz »

Thanks for your input.

It now reads the value but prints it out wrong.

Here is the result of the Bash Debug:

Code: Select all

pi@raspberrypi:~/domoticz/scripts/bash$ bash -x Roomba.sh
+ ROOMBAIP=192.168.165.23
+ DOMO_IP=192.168.165.10
+ DOMO_PORT=9090
+ ROOMBA_STATUS_IDX=123
+ ROOMBA_BATTERY_STATUS_IDX='your text switch IDX'
+ curl http://192.168.165.23/status.xml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   303    0   303    0     0   2905      0 --:--:-- --:--:-- --:--:--  3787
+ sed -i 's/st_base/On homebase: Not Charging/g' Roomba.txt
+ sed -i 's/st_base_recon/On homebase: Reconditioning Charging/g' Roomba.txt
+ sed -i 's/st_base_full/On homebase: Full Charging/g' Roomba.txt
+ sed -i 's/st_base_trickle/On homebase: Trickle Charging/g' Roomba.txt
+ sed -i 's/st_base_wait/On homebase: Waiting/g' Roomba.txt
+ sed -i 's/st_plug/Plugged in: Not Charging/g' Roomba.txt
+ sed -i 's/st_plug_recon/Plugged in: Reconditioning Charging/g' Roomba.txt
+ sed -i 's/st_plug_full/Plugged in: Full Charging/g' Roomba.txt
+ sed -i 's/st_plug_trickle/Plugged in: Trickle Charging/g' Roomba.txt
+ sed -i 's/st_plug_wait/Plugged in: Waiting/g' Roomba.txt
+ sed -i s/st_stopped/Stopped/g Roomba.txt
+ sed -i s/st_clean/Cleaning/g Roomba.txt
+ sed -i 's/st_cleanstop/Stopped with cleaning/g' Roomba.txt
+ sed -i 's/st_clean_spot/Spot cleaning/g' Roomba.txt
+ sed -i 's/st_clean_max/Max cleaning/g' Roomba.txt
+ sed -i 's/st_delayed/Delayed cleaning will start soon ../g' Roomba.txt
+ sed -i 's/st_dock/Searching Homebase/g' Roomba.txt
+ sed -i 's/st_pickup/Roomba picked up/g' Roomba.txt
+ sed -i 's/st_remote/Remote control driving/g' Roomba.txt
+ sed -i 's/st_wait/Waiting for command/g' Roomba.txt
+ sed -i s/st_off/Off/g Roomba.txt
+ sed -i s/st_error/Error/g Roomba.txt
+ sed -i 's/st_locate/Find me!/g' Roomba.txt
+ sed -i 's/st_unknown/Unknown state/g' Roomba.txt
++ grep -oP '(?<=<cleaner_state>).*(?<=</cleaner_state>)' Roomba.txt
+ RoombaStatus='On homebase: Not Charging_trickle</cleaner_state>'
+ curl -s -i -H 'Accept: application/json' 'http://192.168.165.10:9090/json.htm?type=command&param=udevice&idx=123&nvalue=0&svalue=On homebase: Not Charging_trickle</cleaner_state>'
HTTP/1.0 400 Bad Request
Content-Length: 89
Content-Type: text/html

<html><head><title>Bad Request</title></head><body><h1>400 Bad Request</h1></body></html>
Looks like it has something to do with the end of the value

*EDIT*

I found it!

The fault was in the (?<=<cleaner_state)'

It should be:

Code: Select all

grep -oP '(?<=<cleaner_state>).*(?=</cleaner_state>)' Roomba.txt
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by Skippiemanz »

Ok..

New challenge...

When i run the bach script it puts out the following error:

Code: Select all

++ grep -oP '(?<=<cleaner_state>).*(?=</cleaner_state>)' Roomba.txt
+ RoombaStatus='Waiting for command'
++ grep -oP '(?<=<battery_charge>).*(?=</battery_charge)' Roomba.txt
+ RoombaBatStatus=98
+ curl -s -i -H 'Accept: application/json' 'http://192.168.165.10:9090/json.htm?type=command&param=udevice&idx=123&nvalue=0&svalue=Waiting for command&rssi=12&battery=98'
HTTP/1.0 400 Bad Request
Content-Length: 89
Content-Type: text/html

<html><head><title>Bad Request</title></
But when i copy and paste the

Code: Select all

http://192.168.165.10:9090/json.htm?type=command&param=udevice&idx=123&nvalue=0&svalue=Waiting for command&rssi=12&battery=98'
it works, i get the status" : "OK", "title" : "Update Device" back from domoticz
Skorpion
Posts: 27
Joined: Thursday 15 January 2015 9:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by Skorpion »

Your error probably has to do with your status containing spaces. For example, "waiting for command". Try to edit it to WaitingForCommand and it should work. Don't forget to do this for all translations you made at the rules containing the "sed" command.

Let me know if you got it to work. ;)
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by Skippiemanz »

Skorpion,

Thnaks for your input it indeed hat to do with the spaces.

First i tried it wit %20 instead of spaces. That resulted in the same error.

Somwhere else i read to use the + sign instead of spaces and that works flawlessly!

Thanks a lot!
gvanrekum
Posts: 9
Joined: Monday 22 February 2016 9:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by gvanrekum »

Hi,

Nice topic! Do you have some more information how to setup this in Domoticz?

Thanks and have a nice day,

Greetz,
Gerard
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by Skippiemanz »

Gerard, I have to redo it on my nas. I will try to make a short how to

Verstuurd vanaf mijn SM-G925F met Tapatalk
gvanrekum
Posts: 9
Joined: Monday 22 February 2016 9:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by gvanrekum »

Hi,

Thanks! Any news?

Greetz,
Gerard
gvanrekum
Posts: 9
Joined: Monday 22 February 2016 9:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by gvanrekum »

Hi,

I got it working. I pimped the script mayde by Skippiemanz and tuned it a little bit. I now have the device status and battery status visable in Domoticz as a separate virtual switch.
There's one strange thing: status "st_base_trickle" doesn't seem to work. I've got the status of "st_base" visible in Domoticz with "_trickle" behind it: "Gedocked: Niet aan het laden_trickle". But Roomba is trickle charging right now. Other statuses seem to work fine.

Thanks for the nice script.

Greetz,
Gerard
Skippiemanz
Posts: 230
Joined: Sunday 14 July 2013 20:21
Target OS: Linux
Domoticz version: 4.10233
Location: Alkmaar, The Netherlands
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by Skippiemanz »

Gerard, great to here. What kind of code did you pimp? Perhaps willing to share? I remember something about the docking status also..

Verstuurd vanaf mijn HTC One_M8 met Tapatalk
gvanrekum
Posts: 9
Joined: Monday 22 February 2016 9:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by gvanrekum »

Sure, here you go. Maybe I'll make an Wiki page someday.... ;)

Code: Select all

 #!/bin/bash


	# Get status Roomba Thinking Cleaner in Domoticz
	# Author: G. van Rekum
	# Date: 13-5-2015
	# Support: http://www.domoticz.com/forum/viewtopic.php?f=23&t=6195
	# Version 1.1
	# 1.1 - Added comments in script

	# ------------------------------------------------------------------------------------------------------------
	# !!!Change settings below to your own Roomba/ Domoticz parameters!!!
	# ------------------------------------------------------------------------------------------------------------
	
	# Settings

     		ROOMBAIP="IP ADDRESS HERE"								# Roomba IP Address
		DOMO_IP="IP ADDRESS HERE"								# Domoticz IP Address or URL (without HTTP:\\)
	     	DOMO_PORT="PORT HERE"									# Domoticz Port
	     	ROOMBA_STATUS_IDX="IDX OF VIRTUAL SENSOR"					# Roomba status IDX
	     	ROOMBA_BATTERY_CHARGE_STATUS_IDX="IDX OF VIRTUAL SENSOR"	# Roomba battery charge status IDX

	# -----------------------------------------------------------------------------------------------------------
	# !!!Do not change anything below this line!!!
	# -----------------------------------------------------------------------------------------------------------

	# Get data from status.txt and place text status.txt in new file named Roomba.txt

   			 curl http://$ROOMBAIP/status.xml  > Roomba.txt

	# Change status text to more readable text
			sed -i 's/st_base/On+homebase:+Not+Charging/g' Roomba.txt
			sed -i 's/st_base_recon/On+homebase:+Reconditioning+Charging/g' Roomba.txt
			sed -i 's/st_base_full/On+homebase:+Full+Charging/g' Roomba.txt
			sed -i 's/st_base_trickle/On+homebase+Trickle+Charging/g' Roomba.txt
			sed -i 's/st_base_wait/On+homebase:+Waiting/g' Roomba.txt
			sed -i 's/st_plug/Plugged+in:+Not+Charging/g' Roomba.txt
			sed -i 's/st_plug_recon/Plugged+in:+Reconditioning+Charging/g' Roomba.txt
			sed -i 's/st_plug_full/Plugged+in:+Full+Charging/g' Roomba.txt
			sed -i 's/st_plug_trickle/Plugged+in:+Trickle+Charging/g' Roomba.txt
			sed -i 's/st_plug_wait/Plugged+in:+Waiting/g' Roomba.txt
			sed -i 's/st_stopped/Stopped/g' Roomba.txt
			sed -i 's/st_clean/Cleaning/g' Roomba.txt
			sed -i 's/st_cleanstop/Stopped+with+cleaning/g' Roomba.txt
			sed -i 's/st_clean_spot/Spot+cleaning/g' Roomba.txt
			sed -i 's/st_clean_max/Max+cleaning/g' Roomba.txt
			sed -i 's/st_delayed/Delayed+cleaning+will+start+soon../g' Roomba.txt
			sed -i 's/st_dock/Searching+homebase/g' Roomba.txt
			sed -i 's/st_pickup/Roomba+picked+up/g' Roomba.txt
			sed -i 's/st_remote/Remote+control+driving/g' Roomba.txt
			sed -i 's/st_wait/Waiting+for+command/g' Roomba.txt
			sed -i 's/st_off/Off/g' Roomba.txt
			sed -i 's/st_error/Error/g' Roomba.txt
			sed -i 's/st_locate/Find+me!/g' Roomba.txt
			sed -i 's/st_unknown/Unknown+state/g' Roomba.txt

	# Get cleaner state from Roomba.txt and send to Domoticz
		# Roomba Status
	  		RoombaStatus=`grep -oP '(?<=<cleaner_state>).*(?=</cleaner_state>)' Roomba.txt`
          	# Remove "" Characters from string
                  	RoombaStatus=`echo $RoombaStatus | 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=$ROOMBA_STATUS_IDX&nvalue=0&svalue=$RoombaStatus"

	# Get Battery Charge Status from Roomba.txt and send to Domoticz
		# Roomba Battery Charge Status
	   		RoombaBatteryChargeStatus=`grep -oP '(?<=<battery_charge>).*(?=</battery_charge>)' Roomba.txt`
           	# Remove "" Characters from string
                  	RoombaBatteryChargeStatus=`echo $RoombaBatteryChargeStatus | 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=$ROOMBA_BATTERY_CHARGE_STATUS_IDX&nvalue=0&svalue=$RoombaBatteryChargeStatus"
Greetz,
Gerard
sam329
Posts: 7
Joined: Monday 24 July 2017 10:14
Target OS: Linux
Domoticz version:
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by sam329 »

gvanrekum wrote: Tuesday 23 February 2016 12:04 Hi,

Nice topic! Do you have some more information how to setup this in Domoticz?

Thanks and have a nice day,

Greetz,
Gerard
Yeah check out this @gvanrekum :http://www.domoticz.com/forum/viewtopic.php?f=28&t=6064.
TankySpanky
Posts: 43
Joined: Wednesday 06 February 2019 18:54
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by TankySpanky »

Hello all,

I love the Topic, but i bought a Roomba 671 robot, and the script seems not to work for that one?
Also i get a "acces denied" error when it tries to reach the roomba.
It has wifi by default enabled and works like a charm with the app etc.
Raspberry Pi 3 B+ & Domoticz Beta & Dashticz Beta = Headache :)
But it keeps you van the straat
nigels0
Posts: 221
Joined: Thursday 23 January 2014 12:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: Get Roomba/Thinking Cleaner Status

Post by nigels0 »

I have the same - looks like they have removed access for the 671
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest