Xiaomi vaccum clean bin notification

Hi guys,

I’m trying to get an automation to work with some attributes on the Xiaomi Vacuum.
There is an attribute called ‘cleaning_count’ and my idea is to get a notification every time that number increases by 3. This will help me know when to empty the bin.

Here’s the best I could manage but it still doesn’t work:

  id: '1593188318134'
  alias: Esvaziar aspirador
  description: ''
  trigger:
  - entity_id: vacuum.aspirador
    platform: state
    to: returning
  condition:
  - condition: template
    value_template: '{{ (trigger.to_state.attributes.cleaning_count / 3)|int > (trigger.from_state.attributes.cleaning_count
      / 3)|int }}'
  action:
  - data:
      message: O deposito do aspirador deve estar cheio porque ja aspirou 3 vezes
        seguidas!
      title: Limpar aspirador
    service: notify.mobile_app_oneplus_a6013

I’m still new to templating so I’m pretty sure the problem is there!

Thanks in advance

What exactly is this template supposed to do?

value_template: '{{ (trigger.to_state.attributes.cleaning_count / 3)|int > (trigger.from_state.attributes.cleaning_count/ 3)|int }}'

There’s two issues I see.

  1. you are dividing the state strings by 3 before converting them to integers.
  2. you are attempting to divide both by 3 then comparing if one is larger than the other. The divisions are pointless. X/3 > Y/3 will be true if X > Y. There is no point dividing both by the same amount.

To check if the count has increased by 3 try this template:

value_template: '{{ ( trigger.to_state.attributes.cleaning_count|int - trigger.from_state.attributes.cleaning_count|int ) >= 3 }}'

However this will only work if the cleaning count goes up by 3 in one returning trigger event.

First of all thank you for taking the time to reply.
Well this was me experimenting… I was not quite sure about the output.

What I’m trying to achieve is a notification when it’s time to empty the vacuum bin, usually it occurs after 3 full cleans. So the usage of the cleaning count. But maybe I should try to do an incrementing number and reset every time the bin is cleaned.

If the count only goes up by one each clean then use this and forget the template:

Use one automation to increment the counter whenever the robot enters the returning state. Use another automation to trigger on a count of 4 (the counter starts on 1) that resets the counter and notifies you to clean the bin.

1 Like

Simple and elegant solution!
Thank you very much!

1 Like