Skip to content

Fix: ignore unavailable/unknown flickers in tray trigger (mid-print meter reset)#69

Open
andreiz wants to merge 1 commit into
gibz104:mainfrom
andreiz:fix/tray-trigger-availability-flicker
Open

Fix: ignore unavailable/unknown flickers in tray trigger (mid-print meter reset)#69
andreiz wants to merge 1 commit into
gibz104:mainfrom
andreiz:fix/tray-trigger-availability-flicker

Conversation

@andreiz

@andreiz andreiz commented Jun 15, 2026

Copy link
Copy Markdown

Problem

Filament usage can be massively under-counted if the printer/MQTT connection briefly flickers during a print.

The Update Spool automation triggers on any state change of sensor.spoolmansync_<prefix>_active_tray:

triggers:
  - entity_id: sensor.spoolmansync_<prefix>_active_tray
    id: tray
    trigger: state

That sensor’s availability is false when all of a printer's tray sensors are unavailable. So a momentary integration/MQTT hiccup makes active_tray go N -> unavailable -> N and both edges trigger the automation:

  • On the unavailable -> N edge, old_tray resolves to -1, so the tray-change branch falls through to its default, which unconditionally resets the usage meter:

    # Reset meter anyway to prevent stale values from accumulating
    - action: utility_meter.calibrate
      target: { entity_id: sensor.spoolmansync_<prefix>_filament_usage_meter }
      data: { value: "0" }

All filament tracked before the blip is discarded. The meter recounts from 0, and the print-end deduction only reflects usage after the flicker.

Real-world example

A 25.58g print flickered once at ~90% progress. The meter (correctly at ~23g) was reset to 0, then only re-accumulated the final ~10%. Spoolman was charged 2.3g for a 25.6g print.

The Tray Change automation already guards against this exact case (trigger.to_state.state not in ['unavailable', 'unknown']); the Update Spool automation's tray trigger does not.

Fix

Add not_from/not_to guards to the tray trigger so transient unavailable/unknown transitions don't run the automation. Applied to both the Bambu and Creality generators.

triggers:
  - entity_id: sensor.spoolmansync_<prefix>_active_tray
    id: tray
    not_from: [unavailable, unknown]
    not_to:   [unavailable, unknown]
    trigger: state

Genuine tray changes (including a real tray -> "no active tray"/empty-string transition) still trigger as before.

Notes

  • Users must regenerate their HA config (re-run config generation in the add-on) to pick up the new trigger.

The "Update Spool" automation triggers on any state change of the
active-tray sensor. That sensor reports `unavailable` whenever all of a
printer's tray sensors are briefly unavailable (e.g. an MQTT reconnect).
A transient `unavailable -> tray` flicker mid-print is therefore misread
as a tray change: the `unavailable -> N` edge falls into the default
branch, which unconditionally calibrates the filament-usage utility meter
to 0. All filament tracked before the blip is silently discarded, so the
print-end deduction only reflects usage after the flicker (e.g. 2.3g
logged for a 25.6g print).

Add `not_from`/`not_to` guards for `unavailable`/`unknown` to the tray
trigger in both the Bambu and Creality generators, mirroring the guard
the Tray Change automation already has. A flicker is not a real tray
change, so the automation no longer runs for it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant