Hi, I’m trying to make a simple automation that detects motion when I’m not home.
I want to take this:
description: notify when detects motion when not home
trigger:
- type: motion
platform: device
device_id: 858d37003d922a280f438557d94a8f55
entity_id: binary_sensor.pir1_occupancy
domain: binary_sensor
condition:
- condition: zone
entity_id: person.gal
zone: zone.home
action:
- service: notify.persistent_notification
data:
message: Motion detected
title: Motion detected
mode: single
and change the condition from being home to being not at home.
I’ve seen condition like {{states('person.gal') != 'home'}}
but I’ve no idea where to plant it in the yaml.
This assumes that OP didn’t configure any zones, otherwise the state of the person entity in his absence can be the name of a zone and not necessarily not_home.
- alias: motion-Living room
trigger:
platform: state
entity_id: binary_sensor.living_room_motion_motion
to: 'on'
condition:
condition: or
conditions:
- condition: template
value_template: "{{ states('group.family') != 'home' }}"
- condition: and
conditions:
- condition: state
entity_id: input_boolean.day_night
state: 'off'
- condition: state
entity_id: switch.living_room_fan_light
state: 'off'
action:
- service: notify.mobile_app_my_phone
data:
message: 'motion: Living Room'
It only responds to motion if no one in my family is home
or if it’s night-time and the room light is not on.
(I sometimes get up in the middle of the night to work on something and I don’t want HA telling me that I’m moving around all the time.)
The day_night input boolean is set and cleared in another automation. Right now it’s entirely time based, but one could just as easily make it based on sun position.
I use sun position to trigger porch and patio lights.
To some extent, there is the documentation. Follow the links on the right after you visit this link for more detail. As you’ve done, feel free to also ask questions. That’s what the community is here for. I did both to arrive at what you saw.
Thanks for all your comments. I found that reading on templating and jinja helped me understand snippets I read, but it feels like there are multiple layers (yaml, jinja, python?, HA specifics) and it’ll probably take some time to get how it all fit together.