I have spent about two weeks on this and after reading multiple threads and getting it REALLY close, I am afraid I need guidance. I have been using home assistant for about 2 months now and I have made great strides, however this is something that I have not been able to get working all the way. I have used some code from the excellent @petro as well and that has brought me almost to the finish line.
My use case:
I have 5 doors and a carport bay door that I am trying to reduce from 18 automations and 6 scripts down to 2 automations (or less) and 2 scripts (or less).
I have the trigger for when the a door is noted to be open for a given time. In this case I have 10 seconds for testing:
alias: Snapshot and Script for Open Doors
trigger:
- platform: state
entity_id:
- binary_sensor.sensor_backdoor_contact
- cover.garage_door_controller
- binary_sensor.sensor_frontdoor_contact
- binary_sensor.sensor_garagedoor_contact
- binary_sensor.sensor_sheddoor_contact
- binary_sensor.sensor_sunroomdoor_contact
to: "on"
for:
hours: 0
minutes: 0
seconds: 10
action:
- service: script.1713838195721
data: {}
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: script.1713830770799
data: {}
and this then calls the 2 scripts. One for the snapshot of the appropriate camera that corresponds to the door that has set the trigger:
alias: snapshot test
sequence:
- condition: template
value_template: >
{% set snapshot_sensors = [
'binary_sensor.sensor_backdoor_contact',
'cover.garage_door_controller',
'binary_sensor.sensor_frontdoor_contact',
'binary_sensor.sensor_garagedoor_contact',
'binary_sensor.sensor_sheddoor_contact',
'binary_sensor.sensor_sunroomdoor_contact'] %}
# Is the entity_id inside the sensor map that displays the snapshot? # yes
= move forward, no = stop {{ snapshot_entity_id in snapshot_sensors }}
- service: camera.snapshot
data_template:
entity_id: |
{% set mapper = {
'binary_sensor.sensor_backdoor_contact':'camera.back_yard',
'cover.garage_door_controller':'camera.garage',
'binary_sensor.sensor_frontdoor_contact':'camera.front_porch',
'binary_sensor.sensor_garagedoor_contact':'camera.garage',
'binary_sensor.sensor_sheddoor_contact':'camera.shed',
'binary_sensor.sensor_sunroomdoor_contact':'camera.back_porch' } %}
{{ mapper[trigger.entity_id] }}
filename: |
{% set mapper = {
'binary_sensor.sensor_backdoor_contact':'/config/www/images/backdoor.jpg',
'cover.garage_door_controller':'/config/www/images/garage.jpg',
'binary_sensor.sensor_frontdoor_contact':'/config/www/images/frontdoor.jpg',
'binary_sensor.sensor_garagedoor_contact':'/config/www/images/garage.jpg',
'binary_sensor.sensor_sheddoor_contact':'/config/www/images/shed.jpg',
'binary_sensor.sensor_sunroomdoor_contact':'/config/www/images/sunroom_door.jpg' } %}
{{ mapper[trigger.entity_id] }}
filename: /config/www/images/snapshot_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
and then followed by the script that sends the actionable notification to my phone:
alias: door_open_reminder
sequence:
- condition: template
value_template: >
{% set snapshot_sensors = [
'binary_sensor.sensor_backdoor_contact',
'cover.garage_door_controller',
'binary_sensor.sensor_frontdoor_contact',
'binary_sensor.sensor_garagedoor_contact',
'binary_sensor.sensor_sheddoor_contact',
'binary_sensor.sensor_sunroomdoor_contact'] %}
# Is the entity_id inside the sensor map that displays the snapshot? #
yes = move forward, no = stop {{ snapshot_entity_id in snapshot_sensors
}}
- service: notify.mobile_app_pixel_6_pro
data_template:
message: The {{ trigger.to_state.attributes.friendly_name }} is open.
title: Door Open
data:
image: /local/images/{{ trigger.to_state.entity_id.split(".")[1] }}.jpg
clickAction: app://com.ubnt.unifi.protect
ttl: 0
priority: high
actions:
- action: REMIND
title: Remind Me
- action: IGNORE
title: Ignore
destructive: true
- action: URI
title: Open Camera
uri: >-
/dashboard-unifiprotect/{{
trigger.to_state.entity_id.split(".")[1] }}
mode: single
icon: mdi:reminder
then lastly and I havent made it to this part yet, is the actual remind part of the notification… the actual reminder:
alias: Send New Snapshot and Reminder Notification
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.remindme_backdoor
- input_boolean.remindme_carport
- input_boolean.remindme_frontdoor
- input_boolean.remindme_garage
- input_boolean.remindme_sheddoor
- input_boolean.remindme_sunroom
to: "on"
action:
- service: camera.snapshot
data_template:
entity_id: >
{{ 'camera.back_yard' if trigger.entity_id ==
'input_boolean.remindme_backdoor' else
'camera.garage' if trigger.entity_id == 'input_boolean.remindme_carport' else
'camera.front_porch' if trigger.entity_id == 'input_boolean.remindme_frontdoor' else
'camera.garage' if trigger.entity_id == 'input_boolean.remindme_garage' else
'camera.shed' if trigger.entity_id == 'input_boolean.remindme_sheddoor' else
'camera.back_porch' }}
filename: /config/www/snapshot_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
- service: script.door_open_reminder
data_template:
entity_id: "{{ trigger.entity_id }}"
So… thats it, I am not getting any errors per se, but I am also not getting any notifications. I am SUPER sorry to add yet another post about this, but I have really tried and if there is something I have missed, by all means let me know. I really want this one behind me. I have wasted a lot of time on it. lol
EDIT:
It should be noted that no matter what I do, the yaml format is absolutely not honored by home assistant. What you see is how I get it back and if I try to “fix” it, then it errors out.