Trigger alert if time ON is less than variable

I have an aquaponics system and I would like to automate a notification of if the pump cycle time is less than a value, I have found plenty for if the cycle time is greater. This would be to determine if the water level is optimal, I am looking to do this purely based off of time and not another sensor.

Typically a cycle has the pump on for 6 minutes, this raises the power consumption by 100W during this time triggering a threshold that is set to ON during this duration. If the water in the system is low the system will have a cycle time of about 3-4 minutes, so what I am looking for is that if the system goes under 5 minutes on its cycle times, to fire an alert to state the system needs more water (This could even go to a relay>valve to fill the tank with more water)

trigger:
  - platform: state
    to: 'off'
    from: 'on'
    entity_id: binary_sensor.fish_tank_threshold
condition:
  - alias: Check if On cycle was less than 6 min
    condition: template
    value_template: |
      {{ now() - trigger.from_state.last_changed < timedelta(minutes = 5) }}
action:
....

Be aware that, this will fire every time the pump turns off and the previous on time was short… so every 5 minutes, getting progressively more frequent as the tank volume reduces. That may be what you want, but if such frequent executions are unwanted, you can add other conditions to throttle how often the actions are executed.

1 Like

That’s very good thank you, so for that other condition you’d say to do a timer like every 8 hours as another condition?

You can use data from the automation’s state object like:

  - alias:  Check that it has been at least 8 hours since the automation actions were last executed 
    condition: template
    value_template: |
      {{ now() - this.attributes.last_triggered | default(as_datetime(0)) >= timedelta(hours = 8) }}
1 Like

Thank you so much!