The above triggers each time someone leaves but only executes the action if both conditions are met (no one is home). The zone trigger only works if you are using a gps based tracker, it can be easily adjusted if you only have local device tracking.
- alias: "Camera Off When Home"
trigger:
- platform: zone
entity_id: device_tracker.person1
zone: zone.home
event: 'enter'
- platform: zone
entity_id: device_tracker.person2
zone: zone.home
event: 'enter'
action:
- service: switch.turn_off
entity_id: webcam_1
This automation triggers anytime someone comes home. You may want to add a condition to this automation for the camera to already be off. Would need to know the camera entity_id and ‘off’ state to do this though. You will also need to adjust the service and entity_ids listed to match your camera and device trackers.
I think the issue has to do with the quotes in your conditions.
Place “quotes” around the entire value template. Use single ‘quotes’ inside those quotes. Note that you have multiple single ’ ’ quotes ’ ’ around home and device_tracker.XXXXXXXX.
Wouldn’t it be easier just to use a group? And if those are the only two device_trackers, there’s already a group that could be used - group.all_devices.
Basically, the automation trigger would be the group. A group of device_trackers, by default, is home when any one of the device_trackers is home, and not_home when all of the device_trackers are not home. And it could be done with one automation with a service_template.
Something like:
- alias: Camera control
trigger:
platform: state
entity_id: group.my_devices
action:
service_template: >
{% if trigger.to_state.state == 'home' %}
switch.turn_off
{% else %}
switch.turn_on
{% endif %}
entity_id:
- switch.74607070dc4f22fb6002
- switch.74607070dc4f22fb6254
EDIT: Oops, just noticed a mistake in the service template. Corrected.
Seconding the group suggestion. They work great. The status of the members in the group are treated as a logical OR. So as long as one person in the group is ‘home’, then the group status is home. You can also use groups to define what you want to turn on/off.
So I am new to Home Assistant and I am trying to configure device detection to trigger a switch on/off to change the state of Motion Detection in MotionEyeOS.
So far I have a working button; from ‘Configuration.yaml’: