I have a Salt Water Chlorinator for my pool. When the filter or leaf baskets start getting clogged, it requires the filter to be cleaned otherwise the flow through the chlorinator slows to the point that the chlorinator stops functioning. There is an integration i’ve installed that creates a binary sensor indicating that the SWG is functional or not.
I need the ability to check the status of that binary_sensor and if either the percentage of time over the past x hours or the number of occurrences exceeds some arbitrary number. I prefer the percentage of the past x hours because it is semi-normal for that binary_sensor to indicate there’s a problem (outliers) (such as when the pumps initially turn on or when it flips to ‘spa’, etc). I only want this value though calculated when another binary sensor is in ‘pool mode’ or ‘on’. So that makes it a but more difficult.
I know I can create a complicated automation to start incrementing counters and such but that seems pretty convoluted. I was thinking of a statistics sensor but those only ‘update’ when the value changes rather than ‘staying off’ and only flipping on a few times once in a while.
What I really envision is using something like the ‘trend’ sensor maybe but I feel I am going to get too many false positives and frankly I am not clear how I would even configure it.
When I need is something that says "alert me when there is 20 minutes of ‘on’ time (not necessarily continuous. It can be 'off,on,off,on… ) on the binary sensor over a rolling 2 hours during the time when pool_mode = ‘ON’ "
sensor:
- platform: statistics
name: "Percent On Pool"
entity_id: binary_sensor.pool
state_characteristic: average_step
sample_size: 132 <-- assumes one per minute double if once every 30 seconds
max_age:
minutes:120
average_step: A percentage of time across all stored measurements, in which the binary source sensor was “On”. If over the course of one hour, movement was detected for 6 minutes, the average_step is 10%.
I might be able to use that! I’d have to make the entity_id based on a template sensor to weed out times when the alarm shouldn’t matter. I’ll give it a try. I knew there had to be a more simple way than trying to create a bunch of automations myself.
- platform: statistics
name: "Percent On Pool"
entity_id: sensor.pool_swg_alarm_on
state_characteristic: average_step
sample_size: 264 #-- assumes one per minute double if once every 30 seconds
max_age:
minutes:120
pool_swg_alarm_on:
friendly_name: "Pool SWG Alarm On"
value_template: >-
{%- if is_state('binary_sensor.pentair_xx_dc_xx_chemistry_alarm', 'on') and
states('sensor.pentair_xx_dc_xx_pool_pump_current_rpm') | default('0') | float(0) > 1000 and
(is_state('switch.pentair_xx_dc_xx_pool', 'on') or ( is_state('switch.pentair_xx_dc_xx_spillway', 'on') and is_state('switch.pentair_xx_dc_xx_spa', 'off') ))
%}
on
{% else %}
off
{%- endif %}
icon_template: >-
{%- if is_state('binary_sensor.pentair_xx_dc_xx_chemistry_alarm', 'on') and
states('sensor.pentair_xx_dc_xx_pool_pump_current_rpm') | default('0') | float(0) > 1000 and
(is_state('switch.pentair_xx_dc_xx_pool', 'on') or ( is_state('switch.pentair_xx_dc_xx_spillway', 'on') and is_state('switch.pentair_xx_dc_xx_spa', 'off') ))
%}
mdi:radioactive
{% else %}
mdi:radioactive-off
{%- endif %}
It is accurate actually. The binary_sensor (not the template sensor I wrap around it) tells me when there isn’t enough flow through the pump to activate the salt chlorinator. That is a Pentair unit and if it is borderline, it can fluctuate on/off. The flow needs to be a certain gallons per minute or it activates the binary_sensor to indicate a flow problem. Switching pump valves can do it too because the pumps will spin up and down while that happens.