feat: add runtime/duration-based task triggers (sensor value monitoring) - #116
Open
Seidlm wants to merge 3 commits into
Open
feat: add runtime/duration-based task triggers (sensor value monitoring)#116Seidlm wants to merge 3 commits into
Seidlm wants to merge 3 commits into
Conversation
Adds support for count-based maintenance tasks (e.g., after 30 washing machine cycles, trigger a cleaning task). New features: - trigger_type field: 'time' (existing) or 'count' (new) - Track HA entity state changes to increment counter - Counter resets to 0 when task is completed - New services: increment_count, reset_count - Frontend: dynamic form for time vs count tasks - Full backward compatibility with existing tasks Closes TJPoorman#109
- New trigger_type 'runtime' monitors numeric sensor values (e.g., blade hours) - Task becomes due when sensor delta exceeds configured threshold - Auto-detects sensor resets (value drops below baseline) - Baseline auto-set from current sensor value on task creation - Baseline updates to current value on task completion - Full frontend support: create, edit, display runtime tasks - Backward compatible with existing time and count tasks
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.
Runtime/Duration-Based Task Triggers
Related to #109 - extends the integration with a third trigger type.
Problem
Many smart home devices report cumulative usage metrics - for example, a Husqvarna robotic lawn mower tracks how many hours the blades have been running. Users need a way to trigger maintenance tasks based on these runtime values (e.g., "replace blades after 100 hours").
This can't be solved with time-based intervals (the mower doesn't run every day) or count-based triggers (it's not about on/off cycles, but accumulated hours).
Solution
A new trigger type: Runtime-based - monitors a numeric sensor entity and triggers a task when the accumulated value exceeds a threshold.
How It Works
sensor.husqvarna_blade_hours)current_value - baseline >= thresholdAutomatic Sensor Reset Detection
Some devices reset their counters (e.g., after blade replacement the mower resets hours to 0). The integration handles this automatically:
current_value < baseline? external reset detectedExample:
Changes
Backend (Python):
store.py- 3 new fields:runtime_entity_id,runtime_threshold,runtime_baseline. Auto-reads sensor value as baseline on task creation and completion.binary_sensor.py- New_update_state_runtime()with delta calculation, reset detection. Exposes attributes:runtime_entity_id,runtime_threshold,runtime_baseline,runtime_current,runtime_delta__init__.py- State change listener for runtime entities, detects external resetswebsocket.py- Accepts runtime fields on add/update, auto-populates baselineFrontend (Panel):
Backward Compatibility
Use Cases
Testing
Tested on Home Assistant (HAOS, Hyper-V) via HACS custom repository. Verified: