Vacum every second day if nobody home

Hi I would like to find a way how to trigger a vacuum every second day plus when nobody is at home. It means that if the third day will be somebody present, the trigger wil run next day after.

I am noob programmer so any hints are appreciated.

That’s a little unclear. Do you mean you want it to run at a specified time of day if nobody is home and it’s been at least two days since the last time it was run?

Current condition is to run on Mon, Wed, Fri between - 9:00 to 19:00 if nobody is home. The trigger is either 9:00 or anybody left.

The problem occurs when somebody is home on the “vaccuum day”’ or a few “vacuum days” in a row.

So I want to have trigger and condition to start vacuum every second day when nobody is at home between 9-18. If the second day the home is occupied during this period the vacuum start next closes days when nobody is at home betwwn 9-18. Hope now it is clearer.

Trigger will remain: anybody left or 9:10
Condition is big question for me

Ok, so you don’t want it to run normally on Mon, Wed & Fri anymore, just every two days?

So let’s see if I have it now. It should run at 09:00, or when everyone has left home if it’s between 09:00 and 19:00. Also, it should only run if it’s been at least two days since the last time it ran. Is that it?

Exactly! :slight_smile:

Ok. Well, you didn’t specify how you know when nobody is home, or any of the actual entity_id’s, so I’ll just write an example and you can substitute as necessary.

- alias: run_vacuum
    - platform: time
      at: 09:00:00
    - platform: state
      entity_id: group.all_devices
      to: 'not_home'
    - condition: time
      after: 09:00:00
      before: 19:00:00
    - condition: template
      value_template: >
        {% set last_run = state_attr('automation.run_vacuum', 'last_triggered') %}
        {{ last_run is none or (now().date() - >= 2 }}
    # Run the vacuum
1 Like

Oh I have just been googling how to write the value template explained for noobs I would really like to understand the code. It so simple when you read it but I don’t understand why is what and where written. Thanks!

You can start with the HA documentation. See Templating and Automation Templating.

Thank you very much. I will try to somehow remake tha code to do it every second day not starting of the last automation triggered hour but that day.

I’m not sure I understand what you’re saying here. The solution I provided will start the vacuum at either 09:00 or when the last person leaves (If they leave between 09:00 and 19:00), no matter which day it is, as long as the day it was last started on was the day before yesterday or before.

It seems that if the automation run today at 16:00 for example, the next will run no sooner that after two days starting at 16:00 (not earlier). Tested by sensor. Maybe I did something wrong.

You must not have used exactly what I suggested. The condition only tests if today’s date is at least 2 after the date of the last time the automation ran. It is not using time, just the dates.

Phil, sorry you are right. It was due to not updated entity of the sensor I created. I put the automation to update it every 1:00 am.

I have no idea what a sensor has to do with the automation triggers & conditions I suggested.

The sensor was only visual test if the condition is fullfiled or not. Many thanks Phil!

1 Like