Howto: Xiaomi vacuum zoned cleaning

I have set this up, and it seems to work to zone clean a room by choosing it in HA, but I can not get the Google Assistant +IFTTT to work. Google responds with the response I put in IFTTT, but nothing happens.
In my IFTTT applet I have the following:
URL: https//xxxx.duckdns.org:8123/api/webhooks/MYTOKENFROMIFTTT
Method: POST
Content type: application/json
Body: {“action”: “call_service”, “service”: “script.vacuum_room_select”, “room”:" {{TextField}}"}

But I am not sure what to put in the Body part? Can anybody help me?

Thank you very much for this great guide which I have benefitted much from. I use this way of controlling my vacuum regularly and primarily and I have even made a great iOS Shortcut using MQTT to activate the different zone cleaning scripts. I also added queueing functionality with the q-gate node in Node-RED.

This is very useful because the robot can start vacuuming as soon as I am done removing stuff from the floor in one room and then only vacuum the rooms in the order I choose.

Made a video showing the iOS Shortcut implementation: https://youtu.be/c-mypX6TnQQ

I am aware that there are many ways to achieve this, but sharing knowledge and experience is what it’s about, right? Of course I made sure to link to this guide in the video. Thanks again.

Hi,
I’m trying to add room cleaning to GA through IFTTT. Does anyone know why isn’t this working: { “action”: “call_service”, “service”: “vacuum.send_command”, “command”: “app_segment_clean”, “params”: [19], “entity_id”: “vacuum.rocky” } ??
It works in HA but when I add this to IFTTT webhook applet it pushes the HA with log error: “Error while executing automation automation.ifttt_integration. Invalid data for call_service at pos 1: required key not provided @ data[‘command’]”. Others, like “vacuum.locate” works fine. Vacuum: Roborock S6. In automations.yaml I have:

[quote]

  • alias: ‘ifttt integration’
    trigger:
    • event_data:
      action: call_service
      event_type: ifttt_webhook_received
      platform: event
      condition: []
      action:
    • data_template:
      entity_id: ‘{{ trigger.event.data.entity_id }}’
      service_template: ‘{{ trigger.event.data.service }}’
      [endofquote]

I suppose that the problem is with parameters being passed as a string instead of an array of strings: "[19]" instead of ["19"]

Nope, still no difference and same error “Error while executing automation automation.ifttt_integration. Invalid data for call_service at pos 1: required key not provided @ data[‘command’]”.

I’m not sure if this is right, but what happens if you put command, params and entity_id into data first?

{ “action”: “call_service”, **“service”: “vacuum.send_command”, "data": [“command”: “app_segment_clean”** , “params”: [19], “entity_id”: “vacuum.rocky” ]}

:frowning: nothing happened. Even the error in HA didnt occur. Like nothing happened.

Looking at your automations.yaml it seems that you’re never passing the field params and command which is needed to run the command app_segment_clean. Try adding this to your automation:

- alias: ‘ifttt integration’
  trigger:
  - event_data:
      action: call_service
    event_type: ifttt_webhook_received
    platform: event
  condition: []
  action:
  - data_template:
      entity_id: ‘{{ trigger.event.data.entity_id }}’        
      command: ‘{{ trigger.event.data.command }}’
      params: ‘{{ trigger.event.data.params }}’
    service_template: ‘{{ trigger.event.data.service }}’

In Developer Tools of HA go to “Events” and try listening to the event ifttt_webhook_received while triggering the IFTTT applet to see what data is passed from IFTTT to HA.

Also, look for the button that looks like </> when pasting code here to have it format correctly. Good luck! (I’m also trying to get room cleaning to work from Google Assistant but got stuck taking a slightly different approach),

Like @szmyrgibyrgi I am also trying to get room cleaning triggered by Google Assistant to work, but I’m having a hard time figuring out how to pass the correct params depending on what Google Assistant picked up as the room name.

Right now I’m getting this in the log when telling Google Assistant to clean the kitchen:

Unable to send command to the vacuum: {'code': -10000, 'message': 'data for segment is not a number'}

Question 1: how can I debug this to see what data was actually sent?

This is a sample event fired from IFTTT:

{
    "event_type": "ifttt_webhook_received",
    "data": {
        "action": "vacuum",
        "room": "the kitchen",
        "webhook_id": "mysecretwebhookidiwillnothsharehere"
    },
...

This is my automation which is calling the script vacuum_room:

- alias: Ckean room
  trigger:
  - event_data:
      action: vacuum
    platform: event
    event_type: ifttt_webhook_received
  condition: []
  action:
  - service: script.vacuum_room
    data_template:
      room_name: '{{ trigger.event.data.room }}'

And finally, this is the script where I’m trying to send different values for params given if I can find some string within the field room_name that’s being passed to the script from the automation:

vacuum_room:
  sequence:
    - service: vacuum.send_command
      data:
        entity_id: vacuum.robocop
        command: app_segment_clean
      data_template: 
        params: >-
          {% if 'kitchen' in room_name %}
            [19]
          {% elif 'living room' in room_name %}
            [20]
          {% else %}
            [21]
          {% endif %}

Question 2: Is this the correct way to check if a given string occurs within a parameter and then passing an array with one integer as the result?

1 Like

Thanks Oscar but still nothing. Only log error changed to: Error while executing automation automation.ifttt_integration. Invalid data for call_service at pos 1: Service does not match format <domain>.<name>. I think its time to pass :wink:

And if you try listening for the ifttt_webhook_received event, does the event data include "command": "vacuum.send_command" ?

Update: Could you try pasting what you get when listening to the ifttt_webhook_received in the developer tools? My previous question was a little bit on the fast side and might not help at all :stuck_out_tongue:

Well, thats emberrassing but I dont know how to use this tool. I googled it but I really dont know what to do with it. I started the listener for ifttt_webhook_received but all I see is { "event_type": "ifttt_webhook_received", "data": {}, "origin": "REMOTE", "time_fired": "2020-01-03T21:48:09.475834+00:00", "context": { "id": "xxx", "parent_id": null, "user_id": "xxx" } } and I dont think its that.

Update: What you’re seeing seems to be events that you triggered from within HA, maybe you clicked the “Fire Event” button? Can you confirm that you have

  • Set up the IFTTT integration in Configuration > Integrations ?
  • Set up the IFTTT applet with correct URL, Method, Content-Type and Body?

Awesome, now we’re getting somewhere! What you’re seeing is the events created in HA whenever your IFTTT webhook is triggered (looking more closely on your logs they do not seem to be coming from IFTTT, cause then they should actually have "origin": "LOCAL"). It seems that you’re missing some data from IFTTT that your automation requires…

If you head over to IFTTT, find your applet and then click settings you should see something like the attached picture. Where the blue box is (Body) you’ll need to enter

{ “action”: “call_service”, “service”: “vacuum.send_command”, “command”: “app_segment_clean”, “params”: [19], “entity_id”: “vacuum.rocky” } 

Yes I clicked the “Fire event” button :slight_smile:
I have everything set up:

  • integration in the configuration.yaml
  • ifttt applet with correct URL, Method, Content-Type and Body, at least I hope so, because I dont really know how should correct body look like. I have: { “action”: “call_service”, “service”: “vacuum.send_command”, “command”: “app_segment_clean”, “params”: [19], “entity_id”: “vacuum.rocky” } so exactly as you wrote.
  • I updated the automation.yaml as you wrote few posts above:
- alias: ‘ifttt integration’
  trigger:
  - event_data:
      action: call_service
    event_type: ifttt_webhook_received
    platform: event
  condition: []
  action:
  - data_template:
      entity_id: ‘{{ trigger.event.data.entity_id }}’        
      command: ‘{{ trigger.event.data.command }}’
      params: ‘{{ trigger.event.data.params }}’
    service_template: ‘{{ trigger.event.data.service }}’
  • set up port forwarding for 8123

Alright! Hmm… When you’re in developer tools > events and after you’ve clicked “start listening” (for ifttt_webhook_received events), what do you then see if you now talk to your Google Assistant?

Nothing happens, is still blank.

If nothing at all is happening… then my best guess is that IFTTT is unable to reach your HA. Verify that the webhook URL you got when you set up the IFTTT integration in HA works (try to use it outside your wifi if possible).

If what you mean is that the body is blank as in "data": {} when listening for events, then my best guess is that something is not setup properly in IFTTT.

Ok I did some tests:

  • when I use this in automations.yaml:
- alias: 'ifttt integration'
  trigger:
  - event_data:
      action: call_service
    event_type: ifttt_webhook_received
    platform: event
  action:
  - data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'
      command: '{{ trigger.event.data.command }}'
      params: '{{ trigger.event.data.params }}'
    service_template: '{{ trigger.event.data.service }}'

and this code in ifttt:

{ "action": "call_service", "service": "light.turn_off", "entity_id": "light.floor_lamp" }

nothing happens with the lamp but the event listener logs this:

{
    "event_type": "ifttt_webhook_received",
    "data": {
        "action": "call_service",
        "service": "light.turn_off",
        "entity_id": "light.floor_lamp",
        "webhook_id": "6bea8edc0fb6eadbddb6b2cb251350814f3cf10062a82cb351693a6dbf6ed10c"
    },
    "origin": "LOCAL",
    "time_fired": "2020-01-03T23:44:46.477551+00:00",
    "context": {
        "id": "83a45e8efe3a4ba2be09052f687edb56",
        "parent_id": null,
        "user_id": null
    }
}
  • but when I use this in automations.yaml:
- alias: 'ifttt integration'
  trigger:
  - event_data:
      action: call_service
    event_type: ifttt_webhook_received
    platform: event
  action:
  - data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'
#      command: '{{ trigger.event.data.command }}'
#      params: '{{ trigger.event.data.params }}'
    service_template: '{{ trigger.event.data.service }}'

the light actually turns off but the event listener in HA still logs the same:

{
    "event_type": "ifttt_webhook_received",
    "data": {
        "action": "call_service",
        "service": "light.turn_off",
        "entity_id": "light.floor_lamp",
        "webhook_id": "6bea8edc0fb6eadbddb6b2cb251350814f3cf10062a82cb351693a6dbf6ed10c"
    },
    "origin": "LOCAL",
    "time_fired": "2020-01-03T23:47:09.757138+00:00",
    "context": {
        "id": "25c2d804cb944af5a2a83ff7aec83305",
        "parent_id": null,
        "user_id": null
    }
}

Now I, at least, know that connection between IFTTT > HASS works.

Also tried:

{ “action”: “call_service”, “service”: “vacuum.locate", "entity_id": "vacuum.rocky" }

which worked yesterday, but now it isnt working anymore. Grrrrr. Ok so this works, I used the wrong quotation marks. This works: { "action": "call_service", "service": "vacuum.locate", "entity_id": "vacuum.rocky" }

======
Ok, so now I am where you are:

Unable to send command to the vacuum: {'code': -10000, 'message': 'data for segment is not a number'}

:slight_smile:
Interesting… value number of the room works in HA when I use services in dev options.

Maybe, but MQTT is working with everything else but the vacuum.

This is the error i get:

"Call-service API error. Error Message: dictionary update sequence element #0 has length 5; 2 is required"

The S5 gets the new app update with the room mapping capabilities. It’s currently in beta, but you can use FloleVac to update to that firmware version already!