From 14e3e405c1f32b9fba5207eae509be6658ac77b2 Mon Sep 17 00:00:00 2001 From: Joshua King Date: Fri, 6 Nov 2026 09:47:44 -0500 Subject: [PATCH] Route OctoEverywhere alerts to a Google Chat space per printer Co-Authored-By: Claude Opus 5.5 --- .../05c_octoeverywhere_google_chat.yaml | 29 +++++++++++++--- helpers/rest_command.yaml | 33 +++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/automations/05_printers_and_workshop/05c_octoeverywhere_google_chat.yaml b/automations/05_printers_and_workshop/05c_octoeverywhere_google_chat.yaml index b1fc64f..bbd83bd 100644 --- a/automations/05_printers_and_workshop/05c_octoeverywhere_google_chat.yaml +++ b/automations/05_printers_and_workshop/05c_octoeverywhere_google_chat.yaml @@ -1,8 +1,12 @@ ### OctoEverywhere -> Google Chat ### # 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 -# rest_command.google_chat_octoeverywhere (helpers/rest_command.yaml). -# Requires `google_chat_octoeverywhere_webhook` in secrets.yaml. +# rest_command.google_chat_octoeverywhere_ (helpers/rest_command.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_` secrets in secrets.yaml. # # Card: header (printer + event), details (file, progress, layer, time, error), # camera snapshot, and an "Open printer" button to OctoEverywhere Quick View. @@ -67,6 +71,21 @@ # Build the message - variables: 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) }}" event_name: >- {{ 'Print progress: ' ~ pct ~ '%' if ev == 6 @@ -123,8 +142,8 @@ {%- if p.QuickViewUrl %}{% set ns.lines = ns.lines + ['<' ~ p.QuickViewUrl ~ '|Open printer>'] %}{% endif -%} {{ ns.lines | join('\n') }} - # Send the card - - action: rest_command.google_chat_octoeverywhere + # Send the card to this printer's space + - action: "rest_command.{{ chat_cmd }}" data: payload: "{{ card }}" response_variable: chat_resp @@ -137,7 +156,7 @@ value_template: "{{ chat_resp is not defined or (chat_resp.status | int(0)) != 200 }}" then: - delay: 2 - - action: rest_command.google_chat_octoeverywhere + - action: "rest_command.{{ chat_cmd }}" data: payload: text: "{{ plain }}" diff --git a/helpers/rest_command.yaml b/helpers/rest_command.yaml index 712945f..a7ba23e 100644 --- a/helpers/rest_command.yaml +++ b/helpers/rest_command.yaml @@ -44,3 +44,36 @@ google_chat_octoeverywhere: method: POST content_type: "application/json; charset=UTF-8" 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 }}"