From 6b5f23ded81cb14b2821af41d8f7386af44bec07 Mon Sep 17 00:00:00 2001 From: Danny Tsang Date: Mon, 6 Jan 2025 17:40:10 +0000 Subject: [PATCH] Fix adding multiple delayed notifications. Checks for existing notification in todo list before adding any more. Update #103 --- packages/rooms/front_garden.yaml | 71 ++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/packages/rooms/front_garden.yaml b/packages/rooms/front_garden.yaml index a4fb547d..ab531443 100644 --- a/packages/rooms/front_garden.yaml +++ b/packages/rooms/front_garden.yaml @@ -24,35 +24,52 @@ automation: - action: input_boolean.turn_on target: entity_id: input_boolean.wait_for_doorbell_camera_update - - if: - - condition: state - entity_id: group.adult_people - state: "not_home" - then: - - action: todo.add_item - data: - item: ":door: :bell: Someone rung the door bell." - target: - entity_id: todo.shared_notifications - - action: button.press + - sequence: + - action: todo.get_items target: - entity_id: button.front_door_take_snapshot - data: {} - - wait_for_trigger: - - trigger: state - entity_id: - - camera.front_door_snapshot - timeout: - minutes: 1 - continue_on_timeout: false - - action: script.send_direct_notification_with_url + entity_id: + - todo.shared_notifications data: - message: Door bell pressed - title: Front Door - people: - - person.danny - url: "{{ state_attr('camera.front_door_snapshot', 'entity_picture') }}" - url_type: image + status: needs_action + response_variable: todo_list + - if: + - condition: state + entity_id: group.adult_people + state: "not_home" + - alias: Does not already exist + condition: template + value_template: >- + {%- for t in todo_list['todo.shared_notifications']['items'] -%} + {%- if t.summary == ':door: :bell: Someone rung the door bell.' -%} + {{ false }} + {%- break -%} + {%- endif-%} + {%- endfor -%} + then: + - action: todo.add_item + data: + item: ":door: :bell: Someone rung the door bell." + target: + entity_id: todo.shared_notifications + - action: button.press + target: + entity_id: button.front_door_take_snapshot + data: {} + - wait_for_trigger: + - trigger: state + entity_id: + - camera.front_door_snapshot + timeout: + minutes: 1 + continue_on_timeout: false + - action: script.send_direct_notification_with_url + data: + message: Door bell pressed + title: Front Door + people: + - person.danny + url: "{{ state_attr('camera.front_door_snapshot', 'entity_picture') }}" + url_type: image mode: single - id: "1621070004545" alias: "Front Garden: Doorbell Camera Updated"