I’m struggling to find a solution to this automation; basically I want hassio to send a notification to my phone when nobody is at home asking if he can start the vacuum.
alias: 'vacuum: nobody home'
trigger:
- platform: state
to: not_home
entity_id: device_tracker.iphone_12_di_luca_2
condition:
- condition: state
state: not_home
entity_id: device_tracker.iphone
action:
- service: notify.mobile_app_iphone_12_di_luca
data:
title: Vacuum
message: 'Seems nobody is home, can I start cleaning?'
data:
push:
category: activate_vacuum
mode: single
The fact is that basically it isn’t working. I think that the problem is the trigger since when I’m at work and my wife is home it won’t start, perfect. But if she leaves home it won’t start either!
The idea is that only when the last person leave the home, then it should send the notification!
The notification is working, the problem is the trigger! It basically never send this notification.
But if I set both person “not_home” and I manually start the automation, then I get the notification and I can trigger the vacuum (there is of course another automation listening to that event)!
Well, the trigger is for device_tracker.iphone_12_di_luca_2 being “not_home” and if that passes then it also is looking for a condition of device_tracker.iphone to also be “not_home”. Is this the intent? They are two different devices, and if the “#2” device doesn’t cause the trigger then the condition won’t be analyzed and if it does cause the trigger and the other phone is not set to “not_home” then your automation won’t run.
Let’s make an example: i leave in the morning (device_tracker.iphone_12_di_luca_2) and my wife (device_tracker.iphone) is home, in this case the automation won’t start since the condition isn’t true, and this is fine for me!
But, if during the day my wife leaves home, I want the automation to start and send the notification, but this isn’t happening!
It can happen also the opposite situation!
It seems like your automation should be set up to trigger when either of the two phones
change to not_home and then use conditions with an AND to determine if both phones are
not_home to then fire the automation. The way you have it set up the automation fires ONCE and that is when YOU leave, and since your wife is home then it stops, but it never fires again because the state hasn’t changed since you left home. This would be more of what you want:
alias: New Automation
description: ''
mode: single
trigger:
- platform: state
entity_id: device_tracker.iphone_12_di_luca_2
to: not_home
- platform: state
entity_id: device_tracker.iphone
to: not_home
condition:
- condition: state
entity_id: device_tracker.iphone_12_di_luca_2
state: not_home
- condition: and
conditions:
- condition: state
entity_id: device_tracker.iphone
state: not_home
The above would fire any time you or your wife’s phone goes to “not_home”, and then the condition checks that the other person is also not home and if that is true then the automation actions run.