opravdin / weback-unofficial

Unofficial WeBack API client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zoning

dinki opened this issue · comments

Forgive me as I've only had this device a few days. My vacuum can do a large section of my home before depleting the battery. Unfortunately it seems like it follows the same pattern of cleaning each time so the master bedroom is usually missed. I may be wrong but that's how it appears.

Someone posted about creating a zone in the WeBack app and the robot will then clean that zone. Is it possible to create a zone using this software and then instruct the robot to clean that zone? I see the working state has changed to 'PlanningRect' when it is doing the zone cleaning.

I think this would be a worthy addition as I'd prefer more control over what the robot does. It seems to like to clean our dining room (the charging base is located here) first, but this room is not used nearly as much as other rooms. Being able to tell it to clean this room less often and rooms like the living room, kitchen, and bathrooms would be fantastic.

Your thoughts?

I can't make it because my robot is not support map saving and zone cleaning features. I think we should wait for someone who has this type of vacuum cleaner will add support for this set of features (at least run cleaning on already saved zone). Or until someone will by this type of vacuum for me :D

Haha. Understood. So far this Tesvor S6 works pretty well but as with everything I'd like to force it to do more :)

Me again. I've got a question that you may or may not be able to answer. I'd like to be able to send the robot to a particular room. I can use the Weback app and draw out a 'zone' and when I click done it will go to that zone and clean it. The state changes to 'PlanningRect' . I see from your GH page that there are these:

PLANNING_RECT("PlanningRect"),
PLANNING_LOCATION("PlanningLocation"),

I am assuming that one of these is the location to be cleaned and the other is the command to send the robot to that location and clean it.

I've installed your python library and am able to identify the rectangle that I created for my kitchen:

'planning_rect_x': [55, 55, 146, 146],
'planning_rect_y': [103, 175, 175, 103],

Can you please tell me how I might send this data as well as the PLANNING_RECT("PlanningRect"),
command to start the bot? Can I do this via MQTT?

I think once I can do this for one room, I'll just need to create a rectangle for another room, query and save those values. At that point I should be able to script something for each room and have Home Assistant or Node Red call those scripts as needed.

Thanks again.

@opravdin

Okay. Success. I did as described above. I created the room rectangle in Weback app, then ran the script to pull the attributes and got the coordinates of the room. I repeated this for another room and recorded those coordinates. I then issued the command like this:

payload = {
    'state': {
        'desired': {
            "working_status": "PlanningRect",
            "planning_rect_x": [115, 115, 189, 189],
 	    "planning_rect_y": [106, 176, 176, 106]
        }
    }
}

The robot went to the first room and started cleaning. I then stopped the robot, changed the values for the room coordinates and resissued the modified command above. The robot went to the second room and started cleaning.

I can now create a script that will send the robot to various rooms.

My question does remain to if there is an easier way to communicate with the robot via MQTT. Could you consider a way to allow for sending custom payloads like what I've shown through the integration somehow? I am not a programmer so I don't know how hard/easy this would be but it would certainly be cool to have this capability. I know it does not benefit you directly as your vacuum doesn't use lidar for location awareness.

@dinki
Thank you for investigation! I will mention it in the readme file. Could you also provide script that you use to find out exact zone coordinates?
Related to HASS: you can use custom command to send any payload you like to your robot. This feature is mentioned in this section of readme: https://github.com/opravdin/weback-hass#custom-commands
Check this integration example (fan_status is passed straight to MQTT payload):

- alias: Automatic set fan high
  trigger:
  - entity_id: vacuum.livingroom
    from: 'off'
    platform: state
  condition: []
  action:
  - entity_id: vacuum.livingroom
    data:
      command: anything 
      params: 
        fan_status: Strong
    service: vacuum.send_command

Fantastico! I'll give it a try in a bit. Here's the steps to follow to get the map coordinates:

  1. In the Weback app, click the map (?) icon and select 'Zone'
  2. Click 'Add' and drag the rectangle to the area you want to define and resize it.
  3. Click 'Finish' and let the robot start the cleaning process

Run this script to pull the values while the robot is running. You will need to change your credentials:

from weback_unofficial.client import WebackApi
import boto3
import json
import pprint

# Method 1: make this package keep session itself
client = WebackApi('+1-youremail_or_phonenumber', 'your_password')
session = client.get_session() # Returns Amazon Session from boto3 package 

print (session)

devices = client.device_list()
device_name = devices[0]['Thing_Name']

client = session.client('iot-data')
resp = client.get_thing_shadow(thingName=device_name)
shadow = json.loads(resp['payload'].read())
print("Attributes:")
pp = pprint.PrettyPrinter(indent=1)
pp.pprint(shadow['state']['reported'])

You will then see the values for the room you've defined in the attributes:

'planning_rect_x': [55, 55, 146, 146],
'planning_rect_y': [103, 175, 175, 103],

Note these coordinates. Stop the robot then repeat the procedure for any additional rooms noting the coordinates of each.

Important: You will will need to stop the robot before you attempt to send it to an area via script.

You can now add this to the bottom of the script posted above to test if it worked. Be sure to change the coordinates to what you have found.

# Start up vacuum cleaner
client = session.client('iot-data')
topic = f"$aws/things/{device_name}/shadow/update"
# See more MQTT commands below
payload = {
    'state': {
        'desired': {
            "working_status": "PlanningRect",
            "planning_rect_x": [115, 115, 189, 189],
 	    "planning_rect_y": [106, 176, 176, 106]
        }
    }
}
resp = client.publish(topic=topic, qos = 0, payload = json.dumps(payload))
print(resp)

The robot should then go to that room and start cleaning if all goes well.

I'll explore the automation example provided above and see if I can pass the required parameters to do this via an automation. Hopefully this will work in the same way and individual automations can be created as needed. I'll report back on what I find.

Well that was easy! This automation sends the robot to my office and cleans it:

- id: '1527474342232'
  alias: Test Vac
  trigger:
    entity_id: vacuum.tesvor_s6
    from: 'off'
    platform: state
  action:
    entity_id: vacuum.tesvor_s6
    data:
      command: anything 
      params: 
        fan_status: Strong
        planning_rect_x: [252, 252, 322, 322]
        planning_rect_y: [217, 276, 276, 217]
        working_status: PlanningRect

    service: vacuum.send_command 

Thanks again for your work on this. You've just made my robot a whole lot smarter. I'm planning on adding this to my Node Red Alexa skill so that I can say 'Alexa vacuum living room/office/bed room/etc'. Very cool indeed!

i'm having this error...
the credentials are right.. i also create another account with cell phone number just in case, but the problem presist..

Logger: homeassistant.setup
Source: custom_components/weback/init.py:47
Integration: weback
First occurred: 10:04:49 PM (1 occurrences)
Last logged: 10:04:49 PM

Error during setup of component weback
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 248, in _async_setup_component
result = await task
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/weback/init.py", line 47, in setup
devices = weback_api.device_list()
File "/usr/local/lib/python3.8/site-packages/weback_unofficial/client.py", line 75, in device_list
session = self.get_session()
File "/usr/local/lib/python3.8/site-packages/weback_unofficial/client.py", line 137, in get_session
raise Exception(f"Could not authenticate. {weback_data['Fail_Reason']}")
Exception: Could not authenticate. account or password is incorrect

any idea?

Stumbled upon an issue with SSL certificate for the endpoint is being used. Altering this line fixed the issue:

client = session.client('iot-data', verify=False)

Could not authenticate.
"account or password is incorrect"
credentials are correct