Skip to content

Commit

Permalink
Frigate-to-Ntfy: Add filename_template option to apprise-ntfy svc
Browse files Browse the repository at this point in the history
Dynamically compute name to snapshot file, based on `camera` and
`label`, using a filename template string like
`./var/media/{camera}-{label}.jpg`.
  • Loading branch information
amotl committed Apr 13, 2023
1 parent f61c3a1 commit 63dda29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/frigate/frigate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ status_publish = True
[config:apprise-ntfy]
module = apprise_single
baseuri = ntfys://ntfy/frigate
filename_template = './var/media/{camera}-{label}.jpg'


[frigate/events]
Expand Down
10 changes: 10 additions & 0 deletions examples/frigate/frigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def frigate_events(topic, data, srv: Service):
mqttwarn transformation function which computes options to be submitted to Apprise/Ntfy.
"""

# Acceptable hack to get attachment filename template from service configuration.
context: RuntimeContext = srv.mwcore["context"]
service_config = context.get_service_config("apprise-ntfy")
filename_template = service_config.get("filename_template")

# Decode JSON message.
after = json.loads(data['payload'])['after']

# Collect details from inbound Frigate event.
Expand All @@ -68,11 +74,15 @@ def frigate_events(topic, data, srv: Service):
entered_zones=after['entered_zones'],
)

# Interpolate event data into attachment filename template.
attach_filename = filename_template.format(**event.to_dict())

# Compute parameters for outbound Apprise / Ntfy URL.
ntfy_parameters = NtfyParameters(
title=f"{event.label} entered {event.entered_zones_str}",
format=f"In zones {event.current_zones_str} at {event.time}",
click=f"https://frigate/events?camera={event.camera}&label={event.label}&zone={event.entered_zones[0]}",
attach=attach_filename,
)
return ntfy_parameters.to_dict()

Expand Down

0 comments on commit 63dda29

Please sign in to comment.