Skip to content

Implement "Time Duration" (Persistence) parameter for Rule Conditions #64

@markoceri

Description

@markoceri

Summary: Currently, the rule engine triggers an action the exact moment a condition is met (e.g., Value > Threshold). We need to add a time-based factor to define how long a condition must be true before the rule is triggered. This is essential to filter out transient spikes and manage sustained states.

User Story: As a Bitcoin miner operator, I want my miners to run exclusively on surplus energy. I need to set a rule that turns off the miner if the system draws power from the battery or the grid for more than X minutes, ensuring that short-term power spikes (e.g., a 30-second cloud or a boiler starting) don't trigger an immediate shutdown, while sustained deficits do.

Current Behavior:

  • Rule: IF Grid_Import_Power > 500W THEN Turn OFF Miner
  • Result: The miner is turned off immediately, even if the imported power spikes to 501W for just 1 second and then drops back down.

Desired Behavior:

  • The user should be able to add a "Duration" parameter to the condition.
  • The rule logic should be: IF Condition IS True FOR [Duration] THEN Action.
  • If the condition becomes False before the [Duration] elapses, the timer resets and no action is taken.

Technical Requirements:

  • Time Format: The input must accept the format HH:MM:SS (Hours:Minutes:Seconds).
  • Trigger Persistence: The system must monitor the condition Value > Threshold and start a timer.
  • Action Execution: The action (e.g., Switch OFF Miner) must execute only if the timer reaches the defined HH:MM:SS duration without the condition ever becoming False.
  • Instant Reset: If the power draw drops below the threshold even for a second before the timer expires, the timer must reset to zero (to allow for short, acceptable spikes).

Specific Use Cases for Implementation:

  • Case A (Battery Discharge Prevention):

    • Metric: Battery Discharge Power.
    • Condition: > 2500W .
    • Persistence: 00:02:00.
    • Action: Smart Plug / Miner: OFF.
    • Goal: Protect battery discharge.
  • Case B (Grid Bypass Prevention):

    • Metric: Grid Import Power (Enel).
    • Condition: > 100W.
    • Persistence: 00:05:00.
    • Action: Smart Plug / Miner: OFF.
    • Goal: Minimize electricity costs by ensuring the system doesn't stay connected to the grid longer than necessary during temporary solar gaps.

Benefits:

  • System Stability: Prevents "flapping" (continuous switching on and off) during transient cloud coverage or home loads startups.
  • Avoid Battery Drain: Mining is only profitable if the energy cost is near zero. Using battery-stored energy (which has a cost per cycle) or grid energy (Enel) makes the operation unprofitable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions