Advertisement
DieMetRik

Frigate. Пересечение зон (Из любой в любую зону)

Jun 16th, 2025 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 6.67 KB | Housing | 0 0
  1. alias: Frigate. Пересечение зон
  2. description: ""
  3. triggers:
  4.   - topic: frigate/events
  5.     trigger: mqtt
  6.   - topic: test/events
  7.     trigger: mqtt
  8. conditions: []
  9. actions:
  10.   - variables:
  11.       entrance_camera_name: entrance
  12.     alias: Определение УСТАНОВОЧНЫХ переменных для условий
  13.   - variables:
  14.       after_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
  15.       before_zones: "{{ trigger.payload_json['before']['entered_zones'] }}"
  16.       camera: "{{ trigger.payload_json['after']['camera'] }}"
  17.       id: "{{ trigger.payload_json['after']['id'] }}"
  18.       label: "{{ trigger.payload_json['after']['label'] }}"
  19.       score: "{{ trigger.payload_json['after']['score'] }}"
  20.       type: "{{ trigger.payload_json['type'] }}"
  21.       datetime: >-
  22.         {{ trigger.payload_json['after']['frame_time'] |
  23.        timestamp_custom('%Y-%m-%d %H:%M:%S') }}
  24.     alias: Определение переменных из MQTT frigate events
  25.   - alias: Проверочное сообщние, если нужно проверить ПЕРЕМЕННЫЕ
  26.     action: telegram_bot.send_message
  27.     metadata: {}
  28.     data:
  29.       disable_notification: true
  30.       message: |-
  31.         MQTT frigate event:
  32.         <pre>after_zones: "{{ after_zones }}"
  33.         before_zones: "{{ before_zones }}"
  34.         camera: "{{ camera }}"
  35.         id: "{{ id }}"
  36.         label: "{{ label }}"
  37.         score: "{{ score }}"
  38.         type: "{{ type }}"
  39.         </pre>
  40.         УСТАНОВОЧНЫЕ:
  41.        <pre>camera_name = "{{ camera_name }}"
  42.         zone_name_out: "{{ zone_name_out }}"
  43.         zone_name_in: "{{ zone_name_in }}"
  44.         </pre>
  45.       parse_mode: html
  46.     enabled: false
  47.   - alias: >-
  48.       Сравниваем название камеры прилетевшее с frigate event с УСТАНОВОЧНЫМ
  49.       значением.
  50.     if:
  51.       - condition: template
  52.         value_template: "{{ type == \"update\" }}"
  53.         alias: type == update
  54.       - condition: template
  55.         value_template: "{{ before_zones !=  after_zones}}"
  56.         alias: before_zones !=  after_zones
  57.       - condition: template
  58.         value_template: "{{ after_zones | length > 1 }}"
  59.         alias: Если длинна массива after_zones[...] > 1
  60.     then:
  61.       - variables:
  62.           max_arr: "{{ after_zones | length - 1 }}"
  63.           zone_out: "{{ after_zones[max_arr - 1] }}"
  64.           zone_in: "{{ after_zones[max_arr] }}"
  65.       - alias: >-
  66.           Если название камеры = установочной (для каждоый камеры нужны свои
  67.           зоны)
  68.         if:
  69.           - alias: camera == camera_name
  70.             condition: template
  71.             value_template: "{{ camera == entrance_camera_name }}"
  72.         then:
  73.           - action: telegram_bot.send_photo
  74.             metadata: {}
  75.             data:
  76.               parse_mode: html
  77.               authentication: digest
  78.               url: >-
  79.                 http://192.168.1.130:8123/api/frigate/notifications/{{id}}/snapshot.jpg?bbox=1&motion=1&regions=1
  80.               caption: |-
  81.                 Перемещение
  82.                 <u> {{ zone_out }} </u> --> <u>{{ zone_in }}</u>
  83.                <pre>{{ datetime }}"
  84.                id:{{ id }}</pre>
  85.            enabled: true
  86.    enabled: true
  87.  - alias: >-
  88.      Сравниваем название камеры прилетевшее с frigate event с УСТАНОВОЧНЫМ
  89.      значением.
  90.    if:
  91.      - condition: template
  92.        value_template: "{{ type == \"update\" }}"
  93.        alias: type == update
  94.      - condition: template
  95.        value_template: "{{ before_zones !=  after_zones}}"
  96.        alias: before_zones !=  after_zones
  97.      - condition: template
  98.        value_template: "{{ after_zones | length > 1 }}"
  99.        alias: Если длинна массива after_zones[...] > 1
  100.    then:
  101.      - variables:
  102.          max_arr: "{{ after_zones | length - 1 }}"
  103.          zone_out: "{{ after_zones[max_arr - 1] }}"
  104.          zone_in: "{{ after_zones[max_arr] }}"
  105.      - alias: >-
  106.          Если название камеры = установочной (для каждоый камеры нужны свои
  107.          зоны)
  108.        if:
  109.          - condition: or
  110.            conditions:
  111.              - condition: and
  112.                conditions:
  113.                  - alias: camera == camera_name
  114.                    condition: template
  115.                    value_template: "{{ camera == entrance_camera_name }}"
  116.                  - condition: and
  117.                    conditions:
  118.                      - condition: template
  119.                        value_template: "{{ zone_out == entrance_zone_name_out }}"
  120.                      - condition: template
  121.                        value_template: "{{ zone_in == entrance_zone_name_in }}"
  122.                alias: Камера 1 (entrance)
  123.              - alias: Камера 2 (livingroom)
  124.                condition: and
  125.                conditions:
  126.                  - alias: camera == camera_name
  127.                    condition: template
  128.                    value_template: "{{ camera == livingroom_camera_name }}"
  129.                  - condition: and
  130.                    conditions:
  131.                      - condition: template
  132.                        value_template: "{{ zone_out == livingroom_zone_name_out }}"
  133.                      - condition: template
  134.                        value_template: "{{ zone_in == livingroom_zone_name_in }}"
  135.        then:
  136.          - action: telegram_bot.send_message
  137.            metadata: {}
  138.            data:
  139.              disable_notification: true
  140.              message: |-
  141.                <pre>
  142.                datetime: "{{datetime}}"
  143.                zone_out: "{{ zone_out }}"
  144.                entrance_zone_name_out: "{{ entrance_zone_name_out }}"
  145.                zone_in: "{{ zone_in }}"
  146.                entrance_zone_name_out: "{{ entrance_zone_name_in}}"
  147.                </pre>
  148.              parse_mode: html
  149.            alias: ПРОВЕРОЧНОЕ сообщение
  150.            enabled: false
  151.          - action: telegram_bot.send_photo
  152.            metadata: {}
  153.            data:
  154.              parse_mode: html
  155.              authentication: digest
  156.              url: >-
  157.                http://192.168.1.130:8123/api/frigate/notifications/{{id}}/snapshot.jpg?bbox=1&motion=1&regions=1
  158.              caption: |-
  159.                Перемещение
  160.                <u> {{ zone_out }} </u> --> <u>{{ zone_in }}</u>
  161.                <pre>{{ datetime }}"
  162.                 id:{{ id }}</pre>
  163.             enabled: true
  164.     enabled: false
  165. mode: single
  166.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement