#Get device_id or entity_id

1 messages · Page 1 of 1 (latest)

autumn patio
#

Hi there, I'm trying to create an automation where Frigate integration detects a motion and once it finishes detection, export the recording. 'Export Recording' action is available to use but it needs a device or entity id. I'm using the mqtt trigger to build the automation. Mqtt payload has 'camera name'. How do i use the camera name to search for the associated device or entity id?
Thanks!

quick turtle
#

This requires templates

#

and we need more info in order to help

autumn patio
#

yes, sure. Here's my current automation where it notifies me on Discord:

alias: Frigate Discord
description: ""
triggers:
  - topic: frigate/events
    trigger: mqtt
conditions:
  - condition: template
    value_template: "{{ trigger.payload_json[\"type\"] == \"end\" }}"
    enabled: true
actions:
  - data:
      message: >-
        A {{trigger.payload_json["after"]["label"]}} was detected in cam
        {{trigger.payload_json["after"]["camera"]}} in e-zones
        {{trigger.payload_json["after"]["entered_zones"]}} with id
        {{trigger.payload_json["after"]["id"]}} and type is
        {{trigger.payload_json["type"]}} between
        {{trigger.payload_json["after"]["start_time"] |
        timestamp_custom("%Y-%m-%d %H:%M:%S") }} e-dt
        {{trigger.payload_json["after"]["end_time"] | timestamp_custom("%Y-%m-%d
        %H:%M:%S") }}.
      target: "1110608"
      data:
        urls: >-
          https://ha.com/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg
        embed:
          title: "{{trigger.payload_json[\"after\"][\"camera\"]}}"
        images:
          - >-
            /media/frigate/clips/{{trigger.payload_json["after"]["camera"]}}-{{trigger.payload_json["after"]["id"]}}.jpg
    action: notify.me

And here's the action available to export Frigate recordings:

action: frigate.export_recording
data:
  playback_factor: realtime
  start_time: "2025-09-04 14:00:07"
  end_time: "2025-09-04 14:00:27"
target:
  entity_id: camera.tbc_5

The target: in above action can also take device_id (which is a number). My question is, How do I get entity_id or device_id based on mqtt payload (above yaml script) to choose the correct camera for which the automation is triggered?

quick turtle
autumn patio
quick turtle
#

if that doesn't have the device_id in it, we'd need to create a map that points a camera id or camera name to a device_id in home assistant

autumn patio