From 26a21600f395ccf795386a8787bde754bc76ce9d Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 20 Apr 2025 22:49:26 +0200 Subject: [PATCH] Fixed URL gfor home-assistant send dynamic notification --- home-assistant/Car counter.yml | 22 +++ home-assistant/Person Detect Logic.yml | 8 ++ home-assistant/Person detect Actions.yml | 67 +++++++-- ...nd Dynamic Notification To All Devices.yml | 87 ++++++++---- home-assistant/mqtt_end.json | 119 ++++++++++++++++ home-assistant/mqtt_new.json | 92 +++++++++++++ home-assistant/mqtt_update1.json | 120 ++++++++++++++++ home-assistant/mqtt_update2.json | 119 ++++++++++++++++ home-assistant/mqtt_update3.json | 124 +++++++++++++++++ ...ification_to_all_devices (no comments).yml | 128 ++++++++++++++++++ 10 files changed, 844 insertions(+), 42 deletions(-) create mode 100644 home-assistant/Car counter.yml create mode 100644 home-assistant/mqtt_end.json create mode 100644 home-assistant/mqtt_new.json create mode 100644 home-assistant/mqtt_update1.json create mode 100644 home-assistant/mqtt_update2.json create mode 100644 home-assistant/mqtt_update3.json create mode 100644 home-assistant/send_dynamic_notification_to_all_devices (no comments).yml diff --git a/home-assistant/Car counter.yml b/home-assistant/Car counter.yml new file mode 100644 index 0000000..dea64ec --- /dev/null +++ b/home-assistant/Car counter.yml @@ -0,0 +1,22 @@ +# deprecated +alias: "FRIGATE: Car counter" +description: FRIGATE car counter - front yard +triggers: + - topic: homeassistant/events + trigger: mqtt +conditions: + - condition: template + value_template: "{{ trigger.payload_json['after']['label'] == 'car' }}" + - condition: template + value_template: "{{ 'driveway_zall' in trigger.payload_json['after']['entered_zones'] }}" +actions: + - action: script.person_in_driveway_detect_actions + metadata: {} + data: + relay: switch.sthome_ut1_relay_4 + counter: counter.car_counter + - action: notify.mobile_app_sm_n986b + data: + message: test message + title: Test +mode: single \ No newline at end of file diff --git a/home-assistant/Person Detect Logic.yml b/home-assistant/Person Detect Logic.yml index 353773c..0692524 100644 --- a/home-assistant/Person Detect Logic.yml +++ b/home-assistant/Person Detect Logic.yml @@ -29,6 +29,14 @@ conditions: - condition: template value_template: "{{ trigger.payload_json[\"after\"][\"entered_zones\"]|length > 0 }}" enabled: false + # This specifically checks for the object to be in the driveway or front_yard zone. This can be removed or those names changed to fit your use case. + # for example: + - condition: template + value_template: '{{ ["driveway_z1", "driveway_zall"] | select("in", after_zones) | list | length > 0 }}' + alias: Object is in Street or Front Yard + # This filters out any car objects. + - condition: template + value_template: '{{ trigger.payload_json["after"]["label"] != "car" }}' actions: - choose: - conditions: diff --git a/home-assistant/Person detect Actions.yml b/home-assistant/Person detect Actions.yml index ed715f6..70b671f 100644 --- a/home-assistant/Person detect Actions.yml +++ b/home-assistant/Person detect Actions.yml @@ -45,28 +45,50 @@ sequence: counter: counter.backyard_person_alarm_counter else: - stop: Unknown camera - - action: counter.increment - target: - entity_id: "{{ counter }}" - data: {} - - action: switch.turn_on - target: - entity_id: "{{ relay }}" - data: {} - - action: script.send_dynamic_notification_to_all_devices + - if: + - condition: template + value_template: "{{ importance == \"max\" }}" + then: + action: counter.increment + target: + entity_id: "{{ counter }}" + data: {} + - if: + - condition: template + value_template: "{{ importance == \"max\" }}" + then: + action: switch.turn_on + target: + entity_id: "{{ relay }}" + data: {} + - action: script.send_dynamic_notification_to_devices data: + send_to_sm_n986b: "{{ send_to_sm_n986b }}" + send_to_nova_4k: "{{ send_to_nova_4k }}" id: "{{ id }}" title: "{{ title }}" message: "{{ message }}" notifTag: "{{ notifTag }}" notifIcon: "{{ notifIcon }}" group: "{{ group }}" + channel: "{{ channel }}" importance: "{{ importance }}" + base_url: "{{ base_url }}" image: "{{ image }}" video: "{{ video }}" - clickAction: "{{ clickAction }}" + when: "{{ when }}" enabled: true fields: + send_to_sm_n986b: + selector: + boolean: null + name: send_to_sm_n986b + required: false + send_to_nova_4k: + selector: + boolean: null + name: send_to_nova_4k + required: false id: selector: text: null @@ -97,21 +119,31 @@ fields: text: null name: group required: true + channel: + selector: + text: null + name: channel + required: true + priority: + selector: + text: null + name: priority + required: true importance: selector: text: null name: importance required: true + base_url: + selector: + text: null + name: base_url + required: true image: selector: text: null name: image required: true - clickaction: - selector: - text: null - name: clickAction - required: true video: selector: text: null @@ -123,3 +155,8 @@ fields: name: camera description: Name of camera as defined in Frigate required: true + when: + selector: + text: null + name: when + required: true diff --git a/home-assistant/Send Dynamic Notification To All Devices.yml b/home-assistant/Send Dynamic Notification To All Devices.yml index 1f28c33..a0cc405 100644 --- a/home-assistant/Send Dynamic Notification To All Devices.yml +++ b/home-assistant/Send Dynamic Notification To All Devices.yml @@ -1,34 +1,52 @@ alias: Send Dynamic Notification To All Devices sequence: + - variables: + image_url: "{{ base_url~image }}" + video_url: "{{ base_url~video }}" - parallel: -# - if: -# - condition: template -# value_template: '{{ send_to_fold | default(True) }}' -# then: -# - data: -# message: '{{ message }}' -# title: '{{ title }}' -# data: -# channel: '{{ channel }}' -# clickAction: '{{ video }}' -# tag: '{{ notifTag }}' -# group: '{{ group }}' -# image: '{% if (importance == "default" and video != null) -%} {{ null -# }} {%- else -%} {{ image }} {%- endif %}' -# video: '{% if (importance == "default" and video != null) -%} {{ video -# }} {%- else -%} {{ null }} {%- endif %}' -# notification_icon: '{{ notifIcon }}' -# importance: '{{ importance }}' -# action: notify.mobile_app_fold + - if: + - condition: template + value_template: '{{ send_to_sm_n986b | default(True) }}' + then: + - data: + message: "{{ message }}" + title: "{{ title }}" + data: + sticky: "true" + color: "#2DF56D" + channel: "{{ channel }}" + vibrationPattern: 100, 1000, 100, 1000, 100 + priority: "{{ priority }}" + ledColor: red + importance: "{{ importance }}" + clickAction: "{{ image_url }}" + tag: "{{ notifTag }}" + group: "{{ group }}" + image: >- + {% if (importance == "default" and video != null) -%} {{ null }} + {%- else -%} {{ image_url }} {%- endif %} + video: >- + {% if (importance == "default" and video != null) -%} {{ video_url + }} {%- else -%} {{ null }} {%- endif %} + notification_icon: "{{ notifIcon }}" + when: "{{ when }}" + actions: + - action: URI + title: Open Image + uri: "{{ image_url }}" + - action: URI + title: Open Clip + uri: "{{ video_url }}" + action: notify.mobile_app_sm_n986b - data: message: '{{ message }}' title: '{{ title }}' data: - url: '{{ video }}' + url: '{{ video_url }}' tag: '{{ notifTag }}' group: '{{ group }}' attachment: - url: '{% if (importance == "default" and video != null) -%} {{ video }} {%- else -%} {{ image }} {%- endif %}' + url: '{% if (importance == "default" and video != null) -%} {{ video }} {%- else -%} {{ image_url }} {%- endif %}' push: interruption-level: '{% if importance == "max" -%} time-sensitive {%- else -%} passive {%- endif %}' # must test above data sent to notify.mobile_app_sm_n986b and check whether the following data is needed @@ -55,6 +73,16 @@ mode: parallel icon: mdi:bell-ring-outline max: 10 fields: + send_to_sm_n986b: + selector: + boolean: null + name: send_to_sm_n986b + required: false + send_to_nova_4k: + selector: + boolean: null + name: send_to_nova_4k + required: false id: selector: text: null @@ -90,18 +118,23 @@ fields: text: null name: importance required: true + base_url: + selector: + text: null + name: base_url + required: true image: selector: text: null name: image required: true - clickaction: - selector: - text: null - name: clickAction - required: true video: selector: text: null name: video - required: true \ No newline at end of file + required: true + when: + selector: + text: null + name: when + required: true diff --git a/home-assistant/mqtt_end.json b/home-assistant/mqtt_end.json new file mode 100644 index 0000000..41b4eaf --- /dev/null +++ b/home-assistant/mqtt_end.json @@ -0,0 +1,119 @@ +{ + "before": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146821.63952, + "snapshot": { + "frame_time": 1745146820.802538, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "region": [ + 255, + 0, + 575, + 320 + ], + "score": 0.68359375, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.5234375, + "box": [ + 574, + 133, + 604, + 147 + ], + "area": 420, + "ratio": 2.142857142857143, + "region": [ + 320, + 0, + 640, + 320 + ], + "stationary": false, + "motionless_count": 1, + "position_changes": 1, + "current_zones": [ + "driveway_zall" + ], + "entered_zones": [ + "driveway_zall", + "driveway_z1" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "after": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146821.63952, + "snapshot": { + "frame_time": 1745146820.802538, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "region": [ + 255, + 0, + 575, + 320 + ], + "score": 0.68359375, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": 1745146822.348831, + "score": 0.5234375, + "box": [ + 574, + 133, + 604, + 147 + ], + "area": 420, + "ratio": 2.142857142857143, + "region": [ + 320, + 0, + 640, + 320 + ], + "stationary": false, + "motionless_count": 1, + "position_changes": 1, + "current_zones": [ + "driveway_zall" + ], + "entered_zones": [ + "driveway_zall", + "driveway_z1" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "type": "end" +} \ No newline at end of file diff --git a/home-assistant/mqtt_new.json b/home-assistant/mqtt_new.json new file mode 100644 index 0000000..5c44207 --- /dev/null +++ b/home-assistant/mqtt_new.json @@ -0,0 +1,92 @@ +{ + "before": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146820.398967, + "snapshot": null, + "label": "car", + "sub_label": null, + "top_score": 0, + "false_positive": true, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.71484375, + "box": [ + 338, + 137, + 436, + 171 + ], + "area": 3332, + "ratio": 2.8823529411764706, + "region": [ + 225, + 0, + 545, + 320 + ], + "stationary": false, + "motionless_count": 0, + "position_changes": 0, + "current_zones": [], + "entered_zones": [], + "has_clip": false, + "has_snapshot": false, + "attributes": {}, + "current_attributes": [] + }, + "after": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146820.604683, + "snapshot": { + "frame_time": 1745146820.604683, + "box": [ + 403, + 136, + 477, + 168 + ], + "area": 2368, + "region": [ + 219, + 0, + 539, + 320 + ], + "score": 0.7265625, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.7265625, + "box": [ + 403, + 136, + 477, + 168 + ], + "area": 2368, + "ratio": 2.3125, + "region": [ + 219, + 0, + 539, + 320 + ], + "stationary": false, + "motionless_count": 1, + "position_changes": 0, + "current_zones": [], + "entered_zones": [], + "has_clip": false, + "has_snapshot": false, + "attributes": {}, + "current_attributes": [] + }, + "type": "new" +} \ No newline at end of file diff --git a/home-assistant/mqtt_update1.json b/home-assistant/mqtt_update1.json new file mode 100644 index 0000000..355b034 --- /dev/null +++ b/home-assistant/mqtt_update1.json @@ -0,0 +1,120 @@ +{ + "before": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146820.802538, + "snapshot": { + "frame_time": 1745146820.802538, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "region": [ + 255, + 0, + 575, + 320 + ], + "score": 0.68359375, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.68359375, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "ratio": 2.3513513513513513, + "region": [ + 255, + 0, + 575, + 320 + ], + "stationary": false, + "motionless_count": 0, + "position_changes": 1, + "current_zones": [ + "driveway_z1", + "driveway_zall" + ], + "entered_zones": [ + "driveway_zall", + "driveway_z1" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "after": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146821.63952, + "snapshot": { + "frame_time": 1745146820.802538, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "region": [ + 255, + 0, + 575, + 320 + ], + "score": 0.68359375, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.5234375, + "box": [ + 574, + 133, + 604, + 147 + ], + "area": 420, + "ratio": 2.142857142857143, + "region": [ + 320, + 0, + 640, + 320 + ], + "stationary": false, + "motionless_count": 1, + "position_changes": 1, + "current_zones": [ + "driveway_zall" + ], + "entered_zones": [ + "driveway_zall", + "driveway_z1" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "type": "update" +} \ No newline at end of file diff --git a/home-assistant/mqtt_update2.json b/home-assistant/mqtt_update2.json new file mode 100644 index 0000000..5aa7ff3 --- /dev/null +++ b/home-assistant/mqtt_update2.json @@ -0,0 +1,119 @@ +{ + "before": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146820.802538, + "snapshot": { + "frame_time": 1745146820.802538, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "region": [ + 255, + 0, + 575, + 320 + ], + "score": 0.68359375, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.68359375, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "ratio": 2.3513513513513513, + "region": [ + 255, + 0, + 575, + 320 + ], + "stationary": false, + "motionless_count": 0, + "position_changes": 1, + "current_zones": [ + "driveway_zall" + ], + "entered_zones": [ + "driveway_zall" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "after": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146820.802538, + "snapshot": { + "frame_time": 1745146820.802538, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "region": [ + 255, + 0, + 575, + 320 + ], + "score": 0.68359375, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.68359375, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "ratio": 2.3513513513513513, + "region": [ + 255, + 0, + 575, + 320 + ], + "stationary": false, + "motionless_count": 0, + "position_changes": 1, + "current_zones": [ + "driveway_z1", + "driveway_zall" + ], + "entered_zones": [ + "driveway_zall", + "driveway_z1" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "type": "update" +} \ No newline at end of file diff --git a/home-assistant/mqtt_update3.json b/home-assistant/mqtt_update3.json new file mode 100644 index 0000000..5fe480c --- /dev/null +++ b/home-assistant/mqtt_update3.json @@ -0,0 +1,124 @@ + "driveway_zall", + "driveway_z1" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "type": "end" +} + +{ + "before": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146820.604683, + "snapshot": { + "frame_time": 1745146820.604683, + "box": [ + 403, + 136, + 477, + 168 + ], + "area": 2368, + "region": [ + 219, + 0, + 539, + 320 + ], + "score": 0.7265625, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.7265625, + "box": [ + 403, + 136, + 477, + 168 + ], + "area": 2368, + "ratio": 2.3125, + "region": [ + 219, + 0, + 539, + 320 + ], + "stationary": false, + "motionless_count": 1, + "position_changes": 0, + "current_zones": [], + "entered_zones": [], + "has_clip": false, + "has_snapshot": false, + "attributes": {}, + "current_attributes": [] + }, + "after": { + "id": "1745146820.398967-j9uxs9", + "camera": "Driveway", + "frame_time": 1745146820.802538, + "snapshot": { + "frame_time": 1745146820.802538, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "region": [ + 255, + 0, + 575, + 320 + ], + "score": 0.68359375, + "attributes": [] + }, + "label": "car", + "sub_label": null, + "top_score": 0.720703125, + "false_positive": false, + "start_time": 1745146820.398967, + "end_time": null, + "score": 0.68359375, + "box": [ + 439, + 131, + 526, + 168 + ], + "area": 3219, + "ratio": 2.3513513513513513, + "region": [ + 255, + 0, + 575, + 320 + ], + "stationary": false, + "motionless_count": 0, + "position_changes": 1, + "current_zones": [ + "driveway_zall" + ], + "entered_zones": [ + "driveway_zall" + ], + "has_clip": true, + "has_snapshot": true, + "attributes": {}, + "current_attributes": [] + }, + "type": "update" +} \ No newline at end of file diff --git a/home-assistant/send_dynamic_notification_to_all_devices (no comments).yml b/home-assistant/send_dynamic_notification_to_all_devices (no comments).yml new file mode 100644 index 0000000..4fe854d --- /dev/null +++ b/home-assistant/send_dynamic_notification_to_all_devices (no comments).yml @@ -0,0 +1,128 @@ +alias: Send Dynamic Notification To Devices +sequence: + - variables: + image_url: "{{ image }}" + video_url: "{{ video }}" + - parallel: + - if: + - condition: template + value_template: "{{ send_to_sm_n986b | default(True) }}" + alias: Send to SM_N986B? + then: + - data: + message: "{{ message }}" + title: "{{ title }}" + data: + sticky: "true" + color: "#2DF56D" + channel: "{{ channel }}" + vibrationPattern: 100, 1000, 100, 1000, 100 + priority: "{{ priority }}" + ledColor: red + importance: "{{ importance }}" + clickAction: "{{ image_url }}" + tag: "{{ notifTag }}" + group: "{{ group }}" + image: >- + {% if (importance == "default" and video != null) -%} {{ null + }} {%- else -%} {{ image_url }} {%- endif %} + video: >- + {% if (importance == "default" and video != null) -%} {{ + video_url }} {%- else -%} {{ null }} {%- endif %} + notification_icon: "{{ notifIcon }}" + when: "{{ when }}" + actions: + - action: URI + title: Open Image + uri: "{{ image_url }}" + - action: URI + title: Open Clip + uri: "{{ video_url }}" + action: notify.mobile_app_sm_n986b + alias: "Notify: Send message to SM_N986B" + - action: counter.increment + target: + entity_id: counter.sm_n986b_notification_counter + data: {} + alias: Increment SM_N986B notification counter + enabled: true +mode: parallel +icon: mdi:bell-ring-outline +max: 10 +fields: + send_to_sm_n986b: + selector: + boolean: null + name: send_to_sm_n986b + required: false + send_to_nova_4k: + selector: + boolean: null + name: send_to_nova_4k + required: false + id: + selector: + text: null + name: id + required: true + title: + selector: + text: null + name: title + required: true + message: + selector: + text: null + name: message + required: true + notiftag: + selector: + text: null + name: notifTag + required: true + notificon: + selector: + text: null + name: notifIcon + required: true + group: + selector: + text: null + name: group + required: true + channel: + selector: + text: null + name: channel + required: true + importance: + selector: + text: null + name: importance + required: true + priority: + selector: + text: null + name: priority + required: true + base_url: + selector: + text: null + name: base_url + required: true + image: + selector: + text: null + name: image + required: true + video: + selector: + text: null + name: video + required: true + when: + selector: + text: null + name: when + required: true +description: ""