Fix: ignore unavailable/unknown flickers in tray trigger (mid-print meter reset)#69
Open
andreiz wants to merge 1 commit into
Open
Fix: ignore unavailable/unknown flickers in tray trigger (mid-print meter reset)#69andreiz wants to merge 1 commit into
andreiz wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:That sensor’s availability is
falsewhen all of a printer's tray sensors are unavailable. So a momentary integration/MQTT hiccup makesactive_traygoN -> unavailable -> Nand both edges trigger the automation:On the
unavailable -> Nedge,old_trayresolves to-1, so the tray-change branch falls through to its default, which unconditionally resets the usage meter: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.3gfor a25.6gprint.The
Tray Changeautomation already guards against this exact case (trigger.to_state.state not in ['unavailable', 'unknown']); theUpdate Spoolautomation's tray trigger does not.Fix
Add
not_from/not_toguards to the tray trigger so transientunavailable/unknowntransitions don't run the automation. Applied to both the Bambu and Creality generators.Genuine tray changes (including a real tray -> "no active tray"/empty-string transition) still trigger as before.
Notes