Automation template/state triggers. Vacuum next zones

Since Xiaomi Roborock S5 can only do 5 zones at a time, I’m trying to set up an automation that’ll continue on to the remaining 5 zones once it did the first 5.

For now the zones are static, but I can’t seem to make the automation trigger, neither with a template or state. I know it works beyond the trigger, because I can trigger it manually/with a timed trigger.

I need it to trigger when status changes to ‘Returning to dock’ (optionally from status ‘Cleaning’). I’ve tried many versions, with templates or states (with a status sensor), but none seem to trigger. Initial state is ‘off’ because it’s turned on elsewhere (works).

Any ideas? Can use state instead of template if anyone knows how to get that working.

- alias: Vacuum next 5 zones
  initial_state: 'off'
  trigger:
    platform: template
    value_template: "{{ is_state_attr('vacuum.xiaomi_vacuum_cleaner', 'status', 'Returning to dock') }}"
  condition:
    condition: template
    value_template: "{{ state_attr('vacuum.xiaomi_vacuum_cleaner', 'battery_level') > 19 }}"
  action:
    - service: vacuum.pause
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
    - delay: '00:00:01'
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_zoned_clean
        params: [[15294,28996,18144,31296,1],
                [13867,32540,19817,36890,1],
                [11034,32889,13884,36939,1],
                [14460,23095,19410,25645,1],
                [21386,22704,25486,25154,1]]
    - service: automation.turn_off
      entity_id: automation.vacuum_next_5_zones

Your trigger template is looking for the state in the attributes instead of the state. If the value you’re looking for is in fact reported as a state, then change the trigger template to:

{{ is_state('vacuum.xiaomi_vacuum_cleaner','Returning to dock') }}

It’s supposed to be an attribute when working directly with the vacuum entity. Using state on it right now, returns ‘undefined’. Using state_attr returns ‘Charging’.

If I define the sensor itself as a template (sensor.vacuum_status) then I need to use state instead of state_attr. I’ve tried both, and neither worked.

When status goes from ‘Cleaning’ to ‘Returning to dock’ nothing happens. According to the docs, the template trigger simply looks for a change from False to True, so I imagine it doesn’t matter whether it’s state or attribute in this one.

I did figure out a way to make it work with state itself (instead of a template), it seems it uses slightly different keywords (probably why the last attempt didn’t work), like ‘cleaning’ instead of ‘Cleaning’.

Though I still wonder why the above doesn’t work? So template doesn’t work for Trigger, but works for Condition?

Instead of testing if status is:

Returning to dock

try:

returning

I’m basing that on what I see in the source code.

When I checked the status attribute state it was ‘Returning to dock’, when I checked the state of the vacuum itself it was ‘returning’.

Like I said above, using state with a vacuum entity_id and from ‘cleaning’ to ‘returning’ worked.
Using state of status attribute and ‘Returning to dock’ didn’t, but perhaps the template tester just shows the wrong values?

Templates work for triggers, most certainly. It’s likely the values, or capitalization. Either way, if you can use a template to generate a true or false result, then they should work in the trigger.

Have you looked at NodeRED?

I tried but failed to find that string in the source code. I can’t find it in the Xiaomi Vacuum component:

Nor can I find it (most curiously of all) in the library that it depends upon:

I feel the string should be in the library’s list of constants but, nope:

? :thinking: ?

1 Like

Well damn, sorry, it turns out that the value I saw before came from a sensor that was part of some custom card, and the value in status is ‘Returning home’. I imagine this one will work…

image

I do wonder however, how would I go about using From/To in a template? The reason is that it would be more specific to use ‘Zoned cleaning’ from status than the generic ‘cleaning’ from vacuum state.
So I’d like From: ‘Zoned cleaning’ To: ‘Returning home’ in a template trigger. Is there some way to check previous state (from) on an attribute?

I guess we needed to know all the places where the string didn’t come from in order to narrow down its source. :slight_smile:

I’ve checked all my automations and I’ve never attempted to use the trigger object with a Template Trigger. I’m not saying it can’t be done only that I have no experience with how it behaves. The documentation suggests it’s possible but I have difficulty understanding which entity within the template (when there’s more than one) is represented by trigger.to_state. I’ll have to experiment with it to gain a better understanding.

I have a quick question and that seem to be the right thread.

My roborock s5 is set to turbo mode, and when i give him coordinates to clean,
He first turn himself on on turbo mode - making a lot of noise, and then driving to the requested spot to clean it.

I would like it to set it’s fan to “quite”, drive to the requested area, switch to turbo and then clean.

That way if he passes through the living room for example while i’m watching TV, he doesn’t annoys me.

What i did, is i added a command to the script which first send the vacuum to a near spot (so he drives there quietly) and then start to clean the requested area.
However in reality, once he get to the requested spot - nothing happens he ignores all the rest of the commands.

Any thoughts?