SgtBatten / HA_blueprints

Somewhere to store automation blueprints
193 stars 76 forks source link

[Issue]: `custom_action_auto` never triggers #238

Closed jsamr closed 3 months ago

jsamr commented 3 months ago

Description

I cannot get the custom_action_auto to trigger.

Version

0.12.0.4a

Automation Config

- id: '1717517126512'
  alias: Frigate Notifications
  description: ''
  use_blueprint:
    path: SgtBatten/Stable.yaml
    input:
      camera: camera.front_south
      notify_device: 304e608602d6b9d50e22cba03a1dbd1d
      icon: mdi:cctv
      android_auto: true
      alert_once: true
      cooldown: 60
      debug: true
      ios_live_view: camera.front_south
      zones:
      - front_patio
      message: A {{ label }} {{ 'is loitering' if loitering else 'was detected' }}
        on the {{ camera_name }} camera{% if enteredzones %} in the {{ enteredzones
        | join(', ') | replace('_',' ') }}{% endif %}.
      channel: security
      attachment: snapshot.jpg?crop=1
      video: '{{base_url}}/api/frigate{{client_id}}/notifications/{{id}}/{{camera}}/clip.mp4'
      color: '#6e41ab'
      zone_filter: true
      state_filter: true
      state_entity: input_boolean.enable_guest_detection_alerts
      state_filter_states:
      - 'on'
      notify_group: notify.alldevices
      custom_action_auto:
      - service: sirens.enable_mode
        data:
          mode: guest_bell

Frigate Config

ffmpeg:
 # QVI not working
  hwaccel_args: preset-vaapi
go2rtc:
  api:
    # redacted
  webrtc:
    # Requires ports forwarding for external access
    # https://docs.frigate.video/configuration/live/#webrtc-extra-configuration
    candidates:
    - 192.168.20.8:8555
    - stun:8555
  streams:
    front_south:
      - rtsp://redacted@192.168.30.2:554/cam/realmonitor?channel=1&subtype=0
    garden_west:
      - rtsp://redacted@192.168.30.2:554/cam/realmonitor?channel=2&subtype=0
    garden_east:
      - rtsp://redacted@192.168.30.2:554/cam/realmonitor?channel=3&subtype=0
    garden_north_west:
      - rtsp://redacted@192.168.30.2:554/cam/realmonitor?channel=4&subtype=0
channel=4&subtype=1
    garden_north_east:
      - rtsp://redacted@192.168.30.2:554/cam/realmonitor?channel=5&subtype=0channel=5&subtype=1
mqtt:
  enabled: true
  host: redacted
  user: redacted
  password: redacted
audio:
  enabled: false
cameras:
  front_south:
    enabled: true
    ffmpeg:
      inputs:
      - path: rtsp://127.0.0.1:8554/front_south
        input_args: preset-rtsp-restream
        roles:
        - record
        - detect
        - rtmp
    detect: &detect_config
      enabled: true
      width: 960
      height: 480
      fps: 15
    objects: &objects_config
      track:
        - person
        - cat
        - dog
    snapshots: &snapshot_config
      enabled: true
    record: &record_config
      enabled: true
      retain:
        days: 5
      events:
        retain:
          default: 10
    live:
      stream_name: front_south
    motion:
      mask:
      - 702,82,526,74,345,68,331,0,960,0,960,111
      - 198,21,260,0,306,0,324,92,231,126
    zones:
      front_patio:
        coordinates: 539,98,403,90,350,92,331,31,309,38,347,180
      sidewalk:
        coordinates: 381,68,541,70,878,101,872,139,479,94,402,91,349,88,347,69
      garage:
        coordinates: 396,163,60,379,155,480,791,480,872,175,874,137,535,98
  garden_west:
    enabled: true
    ffmpeg:
      inputs:
      - path: rtsp://127.0.0.1:8554/garden_west
        input_args: preset-rtsp-restream
        roles:
        - record
        - detect
        - rtmp
    detect: *detect_config
    objects: *objects_config
    record: *record_config
    snapshots: *snapshot_config
    live:
      stream_name: garden_west
    motion:
      mask:
      - 759,0,744,12,415,117,0,301,0,0
      - 960,0,960,38,799,37,779,18,754,2
  garden_east:
    enabled: true
    ffmpeg:
      inputs:
      - path: rtsp://127.0.0.1:8554/garden_east
        input_args: preset-rtsp-restream
        roles:
        - record
        - detect
        - rtmp
    detect: *detect_config
    objects: *objects_config
    record: *record_config
    snapshots: *snapshot_config
    live:
      stream_name: garden_east
    motion:
      mask:
      - 0,351,0,416,46,419,49,346,960,138,960,0,0,0
  garden_north_west:
    enabled: true
    ffmpeg:
      inputs:
      - path: rtsp://127.0.0.1:8554/garden_north_west
        input_args: preset-rtsp-restream
        roles:
        - record
        - detect
        - rtmp
    detect: *detect_config
    objects: *objects_config
    record: *record_config
    snapshots: *snapshot_config
    live:
      stream_name: garden_north_west
    motion:
      mask:
      - 0,0,78,0,78,59,73,114,0,126
      - 960,0,960,78,930,119,886,118,879,57,823,50,791,44,790,0
  garden_north_east:
    enabled: true
    ffmpeg:
      inputs:
      - path: rtsp://127.0.0.1:8554/garden_north_east
        input_args: preset-rtsp-restream
        roles:
        - record
        - detect
        - rtmp
    detect: *detect_config
    objects: *objects_config
    record: *record_config
    snapshots: *snapshot_config
    live:
      stream_name: garden_north_east
    motion:
      mask:
      - 0,136,41,133,53,0,0,0
      - 960,0,960,175,826,149,825,59,788,49,789,0
  ruda:
    enabled: true
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-aac
      inputs:
      - path: rtsp://127.0.0.1:8554/tapo_ruda_1080p?video=h264&audio=aac
        input_args: preset-rtsp-restream
        roles:
        - record
        - rtmp
    detect:
      enabled: false
    snapshots:
      enabled: true
    record: *record_config
    live:
      stream_name: tapo_ruda_1080p

Any other relevant information

In the traces, I can see the conditions block is never matched. Everything else works fine (we receive our companion notifications). I also tested the configured service (sirens.enable_mode) with developer tools and it triggers just fine.

alias: Custom Action Auto
choose:
  - conditions:
      - '{{ custom_action_auto |length > 0 }}'
      - >-
        {{ not zone_only or (not zone_multi and zones|select('in',
        enteredzones)|list|length > 0) or (zone_multi and enteredzones|length >
        0 and zones |reject('in', enteredzones) |list |length == 0) }}
      - '{{ not initial_home }}'
      - '{{ not state_only or states(input_entity) in states_filter }}'
    sequence:
      - service: sirens.enable_mode
        data:
          mode: guest_bell
image
SgtBatten commented 3 months ago

Which condition fails?

jsamr commented 3 months ago

@SgtBatten I am not sure unfortunately; how could that be found out?

SgtBatten commented 3 months ago

When viewing the trace you should be able to click the little check box underneath the choice icon where you put your arrow.

jsamr commented 3 months ago

@SgtBatten Thank you! Could reproduce this evening:

image
SgtBatten commented 3 months ago

Zone conditions failed

Likely your setup means events start earlier than the target enters the mandatory zones.

Custom action auto only works in the first iteration. Everything needs to be true at the start

jsamr commented 3 months ago

Likely your setup means events start earlier than the target enters the mandatory zones. Custom action auto only works in the first iteration. Everything needs to be true at the start

@SgtBatten I very much appreciate this feedback; but not sure if I understand exactly how can I fix that. I don't have multi-zones setup, so I don't see how "events start earlier than the target enters the mandatory zones".

The only enabled zone, front_patio, is delimited here in this Frigate zone image

image

I have 3 zones in total, garage, front_patio and sidewalk.

SgtBatten commented 3 months ago

People are likely entering the sidewalk and being detected there first, firing the automation and failing the zone condition you have entered.

Removing the zone means you will trigger more often, including in the carport. undesirable i assume.

Using custom action auto multi will trigger the custom action multiple times potentially depending on the rest of the config. You can potenitally include something in the custom action that disables itself for x amount of time, i;ve seen people do that before to stop it triggering multiple times in the loop.

With frigate 0.14 you can specify the conditions in frigate itself as to what determines an alert.

jsamr commented 3 months ago

@SgtBatten Thanks for the advices! I will close this post and explore solutions.