Route OctoEverywhere alerts to a Google Chat space per printer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2ae16ceb97
commit
14e3e405c1
@@ -1,8 +1,12 @@
|
|||||||
### OctoEverywhere -> Google Chat ###
|
### OctoEverywhere -> Google Chat ###
|
||||||
# OctoEverywhere (LAN mode) POSTs fixed JSON to this webhook. Google Chat needs a
|
# OctoEverywhere (LAN mode) POSTs fixed JSON to this webhook. Google Chat needs a
|
||||||
# `text` or `cardsV2` body, so this automation builds a card and sends it through
|
# `text` or `cardsV2` body, so this automation builds a card and sends it through
|
||||||
# rest_command.google_chat_octoeverywhere (helpers/rest_command.yaml).
|
# rest_command.google_chat_octoeverywhere_<printer> (helpers/rest_command.yaml).
|
||||||
# Requires `google_chat_octoeverywhere_webhook` in secrets.yaml.
|
# Each printer has its own Google Chat space, picked by a keyword in PrinterName
|
||||||
|
# (see `spaces` below). Unknown printers and the safety-net message go to the
|
||||||
|
# shared space, rest_command.google_chat_octoeverywhere.
|
||||||
|
# Requires `google_chat_octoeverywhere_webhook` and the per-printer
|
||||||
|
# `google_chat_octoeverywhere_<printer>` secrets in secrets.yaml.
|
||||||
#
|
#
|
||||||
# Card: header (printer + event), details (file, progress, layer, time, error),
|
# Card: header (printer + event), details (file, progress, layer, time, error),
|
||||||
# camera snapshot, and an "Open printer" button to OctoEverywhere Quick View.
|
# camera snapshot, and an "Open printer" button to OctoEverywhere Quick View.
|
||||||
@@ -67,6 +71,21 @@
|
|||||||
# Build the message
|
# Build the message
|
||||||
- variables:
|
- variables:
|
||||||
printer: "{{ p.PrinterName | default('Printer', true) | string }}"
|
printer: "{{ p.PrinterName | default('Printer', true) | string }}"
|
||||||
|
# Keyword in the printer name (lowercase, letters/digits only) -> rest_command
|
||||||
|
spaces:
|
||||||
|
constipation: google_chat_octoeverywhere_constipation_orion
|
||||||
|
printney: google_chat_octoeverywhere_printney_spears
|
||||||
|
charming: google_chat_octoeverywhere_prints_charming
|
||||||
|
polly: google_chat_octoeverywhere_polly_pocket
|
||||||
|
slayer: google_chat_octoeverywhere_layer_slayer
|
||||||
|
turd: google_chat_octoeverywhere_turd_flinger
|
||||||
|
chat_cmd: >-
|
||||||
|
{%- set key = printer | lower | regex_replace('[^a-z0-9]', '') -%}
|
||||||
|
{%- set ns = namespace(cmd='google_chat_octoeverywhere') -%}
|
||||||
|
{%- for word, cmd in spaces.items() if word in key and ns.cmd == 'google_chat_octoeverywhere' -%}
|
||||||
|
{%- set ns.cmd = cmd -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{{ ns.cmd }}
|
||||||
pct: "{{ p.Progress | int(0) }}"
|
pct: "{{ p.Progress | int(0) }}"
|
||||||
event_name: >-
|
event_name: >-
|
||||||
{{ 'Print progress: ' ~ pct ~ '%' if ev == 6
|
{{ 'Print progress: ' ~ pct ~ '%' if ev == 6
|
||||||
@@ -123,8 +142,8 @@
|
|||||||
{%- if p.QuickViewUrl %}{% set ns.lines = ns.lines + ['<' ~ p.QuickViewUrl ~ '|Open printer>'] %}{% endif -%}
|
{%- if p.QuickViewUrl %}{% set ns.lines = ns.lines + ['<' ~ p.QuickViewUrl ~ '|Open printer>'] %}{% endif -%}
|
||||||
{{ ns.lines | join('\n') }}
|
{{ ns.lines | join('\n') }}
|
||||||
|
|
||||||
# Send the card
|
# Send the card to this printer's space
|
||||||
- action: rest_command.google_chat_octoeverywhere
|
- action: "rest_command.{{ chat_cmd }}"
|
||||||
data:
|
data:
|
||||||
payload: "{{ card }}"
|
payload: "{{ card }}"
|
||||||
response_variable: chat_resp
|
response_variable: chat_resp
|
||||||
@@ -137,7 +156,7 @@
|
|||||||
value_template: "{{ chat_resp is not defined or (chat_resp.status | int(0)) != 200 }}"
|
value_template: "{{ chat_resp is not defined or (chat_resp.status | int(0)) != 200 }}"
|
||||||
then:
|
then:
|
||||||
- delay: 2
|
- delay: 2
|
||||||
- action: rest_command.google_chat_octoeverywhere
|
- action: "rest_command.{{ chat_cmd }}"
|
||||||
data:
|
data:
|
||||||
payload:
|
payload:
|
||||||
text: "{{ plain }}"
|
text: "{{ plain }}"
|
||||||
|
|||||||
@@ -44,3 +44,36 @@ google_chat_octoeverywhere:
|
|||||||
method: POST
|
method: POST
|
||||||
content_type: "application/json; charset=UTF-8"
|
content_type: "application/json; charset=UTF-8"
|
||||||
payload: "{{ payload | to_json }}"
|
payload: "{{ payload | to_json }}"
|
||||||
|
|
||||||
|
# One Google Chat space per printer. The automation picks one by PrinterName and
|
||||||
|
# falls back to google_chat_octoeverywhere (shared space) for unknown printers.
|
||||||
|
google_chat_octoeverywhere_constipation_orion:
|
||||||
|
url: !secret google_chat_octoeverywhere_constipation_orion
|
||||||
|
method: POST
|
||||||
|
content_type: "application/json; charset=UTF-8"
|
||||||
|
payload: "{{ payload | to_json }}"
|
||||||
|
google_chat_octoeverywhere_printney_spears:
|
||||||
|
url: !secret google_chat_octoeverywhere_printney_spears
|
||||||
|
method: POST
|
||||||
|
content_type: "application/json; charset=UTF-8"
|
||||||
|
payload: "{{ payload | to_json }}"
|
||||||
|
google_chat_octoeverywhere_prints_charming:
|
||||||
|
url: !secret google_chat_octoeverywhere_prints_charming
|
||||||
|
method: POST
|
||||||
|
content_type: "application/json; charset=UTF-8"
|
||||||
|
payload: "{{ payload | to_json }}"
|
||||||
|
google_chat_octoeverywhere_polly_pocket:
|
||||||
|
url: !secret google_chat_octoeverywhere_polly_pocket
|
||||||
|
method: POST
|
||||||
|
content_type: "application/json; charset=UTF-8"
|
||||||
|
payload: "{{ payload | to_json }}"
|
||||||
|
google_chat_octoeverywhere_layer_slayer:
|
||||||
|
url: !secret google_chat_octoeverywhere_layer_slayer
|
||||||
|
method: POST
|
||||||
|
content_type: "application/json; charset=UTF-8"
|
||||||
|
payload: "{{ payload | to_json }}"
|
||||||
|
google_chat_octoeverywhere_turd_flinger:
|
||||||
|
url: !secret google_chat_octoeverywhere_turd_flinger
|
||||||
|
method: POST
|
||||||
|
content_type: "application/json; charset=UTF-8"
|
||||||
|
payload: "{{ payload | to_json }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user