Help with vacuum automation and theory of automation

Hello,

New to Home Assistant. I have a few, very basic automations (send message if “Garbage” in calendar” etc.), want to go more advanced, but having difficulty with my attempt + how I think about automations.

Goal: robot vacuum should clean the house.

Trigger: Day is Monday, Wednesday or Friday at 12pm.

Conditions: No one is home, vacuum hasn’t run in 24 hours before and the floor is cleared of children stuffs.

Is the above flow “normally” how automations are thought about / described? Because I have come to realise that a condition might as well be a trigger instead and the other way around. Do the above make sense?

Regarding the “clear floor”: I have a Ikea tradfri switch, which I wanted to use to change status of a sensor (via an automation) - the sensor would be the “Floor clear?” and state “On/Off”. Could I do this with a sensor without an actual input, but merely there for automation?

I realise this topic is both a specific question + help with what you could call “theory of automation” - hope that is okay.

Thank you for your time,

For my understanding they are well described (with the addition of what you mean by the cleared floor) as you qualified your conditions in items that can be “measured”

If I understand you correctly, you want an input_boolean and change it with your tradfri switch.

configuration.yaml:

input_boolean:
  floor_clean:
    name: floor_clean
    initial: off

The automation could look like this (please note that I am doing this from the top of my head and have not verified it working :p)

automation.yaml

- id: 'vacuum_clean_routine'
  alias: 'vacuum_clean_routine'
  trigger: # trigger every day at noon
    platform: time
    at: '12:00:00'
  condition:
    condition: and
    conditions:
    - condition: time # check if it is monday, wednesday, friday
      weekday:
      - mon
      - wed
      - fri
    - condition: state # check if peter is home
      entity_id: device_tracker.Peter
      state: not_home
    - condition: state # check if peters  wife is home
      entity_id: device_tracker.Peters_wfie
      state: not_home
    ... # check if peters kids etc are home
    - condition: state # check if the floor is clean with an input boolean
      entity_id: input_boolean.floor_clean
      state: on
    - condition: state # check if the vacuum is in the state docked for at least 24h
      entity_id: vacuum.vacuum1
      state: docked
      for:
        hours: 24
  action: # start vacuum1
    - service: vacuum.start
      entity_id: vacuum.vacuum1

I’ve used the device tracker(s) for presence, but I’d suggest you set up, if you have not already done that, the person integration and use that one instead.

Also I do not know how tradfri works. Is it like a zigbee hub? Do you see your devices that you connected to the hub in home assistant? Because then you can just ask for the state of the switch instead of going the extra step of creating an input boolean to change it based on the switch.

Hope this helps

I’ve added the switch using Conbee 2. From what I can tell, the switch is a device that I can use in automations, but haven’t been able to see its status anywhere else. My guess is that it doesn’t have a status, so will have a try with the Boolean.

Switches integrated through deconz don’t create a sensor where you see which button has been pressed, instead an event will be fired every time you press a button. So you’ll need the input boolean anyway, the switch is just there to turn on/off the input boolean. More information about the events from deconz and how to use them for automations can be found here

Thank you! Will take a look at it.

I’m a huge fan of the “doing it from the top of my head, so not verified” and your suggestion is something that I would have spent days getting just a little closer to :smiley:

What I would change in your code would be handle the check for the vacuum run in last 24 hours differently. Your condition will work, however if you restart Home Assistant or the vacuum has some connectivity issues and goes quickly to unavailable for a few seconds, it will fail. I would create an input_datetime that stores the current time once cleaning is finished and then in the condtion check if current time is more than 24 hours after the time from the input_datetime.

1 Like

Valid point! Thank you for that

1 Like

The input_boolean works very smoothly, great!

For my device_tracker,one of the devices is my iPhone GPS. For some reason there were three iphone_gps entities, which I figured to be an error - so I deleted the two that looked wrong. Lo and behold, the GPS entity I kept does not seem to update correctly (Whoops).

I do not have external access to my Home Assistant - is this necessary in order to even use gps as device_tracker?
Is there a way to reset the gps tracker on the iphone app - just try to reconnect?

No idea about iphones, but there are other ways for presence detection, like bluetooth, nmap, ping or one of the community favorites monitor

device tracker can be tough to get to work correctly. Those wifi based trackers may report as away, even though you are home, because phones turn off their wifi to save power. Bluetooth presence scanning might congest the 2.4Ghz wifi and gps based may drain your phone battery if updated too frequently.

Monitor, while most likely taking a weekend afternoon to set up and get used to it, utilizes bluetooth in a way to not have the need to constantly scan for devices to “still be there” but to trigger a scan in a smart way.

I myself am using the unifi presence detection, but you should experiment around and see what suits you the best.

As far as I know you need to have external access, otherwise I can’t imagine how your phone should send your GPS data to home assistant.

I’ve resorted to use ping for my electronics, but you’re right, the iPhone turns off WiFi fairly often… so I’ve also set ping up for anything else that I’m pretty much the only one using. I’m using a TP-link mesh router.

Since I probably need the subscription to actually use the GPS tracking, I think I’ll leave the GPS issue to another day - currently no need to have external access. Might come at a later date.

If I do need

A simple solution would be to subscribe to the nabu casa cloud for $5 a month. It is not a big load of money, but gives you secure access - and if you are into it, makes it easy to set up google home and alexa with home assistant

Also it supports the devs :slight_smile:

Or you set it up yourself, I believe there are docs for that as well

When It’s time, I’ll definitely go and pay the 5 dollars a month, both because it’s easy and to support the devs. I’m currently not too much away from home, so no need to check in when away :slight_smile:

Just that you know, you don’t need a nabu casa subscription for external access, it’s just the easiest option and supports the devs (I actually have a subscription but don’t use it). You can do it for free with a dynamic dns from a provider such as DuckDNS.

Was aware that I can technically do it myself, but I’m fine with local access at the moment. My user level is nowhere near doing networking myself :smiley:

If you are using Home Assistant (formerly hass.io), then with add-ons it’s pretty easy as well.

I’m using Hass.io. Wasn’t aware they changed to HA. Was that part of the name changes recently? Should have read the whole thing.

Yes, it is :slight_smile:
hass.io => Home Assistant
Home Assistant => Home Assistant Core