Skip to content

Instantly share code, notes, and snippets.

@xbmcnut
Last active August 31, 2020 05:03
Show Gist options
  • Save xbmcnut/77866c9bc1d3acd07d0eaf1171ccc5da to your computer and use it in GitHub Desktop.
Save xbmcnut/77866c9bc1d3acd07d0eaf1171ccc5da to your computer and use it in GitHub Desktop.
Complete pool pump management package
###################################
## Customize
###################################
homeassistant:
customize:
switch.pool_pump:
hidden: false
icon: mdi:radiobox-marked
automation.check_pool_pump_in_season:
hidden: true
automation.check_pool_pump_off_season:
hidden: true
automation.pool_pump_off:
hidden: true
automation.pool_pump_off_1200:
hidden: true
automation.pool_pump_off_1700:
hidden: true
automation.pool_pump_on:
hidden: true
sensor.pool_pump_running_today:
hidden: true
input_select.pool_pump:
friendly_name: Pool Pump Mode
sensor.pool_temperature:
icon: mdi:oil-temperature
sensor.pool_pump_time_on:
icon: mdi:av-timer
sensor.pool_pump_status:
icon: mdi:engine-outline
binary_sensor.sonoff_pool_mqtt_status:
friendly_name: Pool MQTT Status
binary_sensor.ping_pool_pump:
friendly_name: Pool Ping
sensor.sonoff_pool_pump_uptime:
friendly_name: Uptime
sensor.sonoff_pool_pump_wifi_rssi:
friendly_name: Pool RSSI
###################################
## Automations
###################################
automation:
- alias: Pool safety override Winter
initial_state: true
trigger:
- platform: time
at: '12:30:00'
condition:
- condition: numeric_state
entity_id: sensor.pool_pump_power
above: 400
- condition: state
entity_id: input_boolean.swimming_season
state: 'off'
action:
- service: homeassistant.turn_on
entity_id: switch.pool_pump
- service: homeassistant.turn_off
entity_id: switch.pool_pump
- service: notify.hass_synochat
data:
message: "Pool pump was left on at {{states('sensor.time')}} so I turend if off"
- alias: Pool safety override Summer
initial_state: true
trigger:
- platform: time
at: '23:30:00'
condition:
- condition: numeric_state
entity_id: sensor.pool_pump_power
above: 400
- condition: state
entity_id: input_boolean.swimming_season
state: 'on'
action:
- service: homeassistant.turn_off
entity_id: switch.pool_pump
- service: notify.hass_synochat
data:
message: "Pool pump was left on at {{states('sensor.time')}} so I turend if off"
- alias: 'Pool Pump On'
initial_state: true
trigger:
- platform: state
entity_id: input_select.pool_pump
to: 'On'
action:
service: homeassistant.turn_on
entity_id: switch.pool_pump
- alias: Pool Pump Off
initial_state: true
trigger:
- platform: state
entity_id: input_select.pool_pump
to: 'Off'
action:
service: homeassistant.turn_off
entity_id: switch.pool_pump
- alias: Reboot Pool Sonoff on MQTT disconnect
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.sonoff_pool_mqtt_status
to: 'off'
for:
seconds: 120
condition:
- condition: state
entity_id: binary_sensor.ping_pool_pump
state: 'on'
action:
- service: homeassistant.turn_on
entity_id: switch.reboot_pool_sonoff
- delay: 00:00:02
- service: homeassistant.turn_off
entity_id: switch.reboot_pool_sonoff
- service: notify.hass_synochat
data:
message: "Pool pump Sonoff went offline so I rebooted"
- alias: 'Manual Pool Timer On'
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.manual_pool_timer
to: 'on'
condition:
- condition: state
entity_id: switch.pool_pump
state: 'off'
action:
- service: homeassistant.turn_on
entity_id: switch.pool_pump
- delay: 03:00:00
- service: homeassistant.turn_off
entity_id: switch.pool_pump
- service: input_boolean.turn_off
entity_id: input_boolean.manual_pool_timer
- alias: 'Manual Pool Timer Off'
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.manual_pool_timer
from: 'on'
to: 'off'
condition:
- condition: state
entity_id: switch.pool_pump
state: 'on'
action:
- service: homeassistant.turn_off
entity_id: switch.pool_pump
### Pool Pump Maintenance Automations ####
- alias: 'Pool Pump Maintenance On'
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.pool_pump_maintenance_mode
to: 'on'
action:
## Turn pump mode to off
- service: input_select.select_option
data:
entity_id: input_select.pool_pump
option: "Off"
- delay: 00:00:10
## Backwash for 2 minutes
- service: homeassistant.turn_on
entity_id: switch.pool_pump
- delay: 00:02:00
- service: homeassistant.turn_off
entity_id: switch.pool_pump
## 10s delay to change filter to rinse mode)
- delay: 00:00:10
## 30s rinse
- service: homeassistant.turn_on
entity_id: switch.pool_pump
- delay: 00:00:30
- service: homeassistant.turn_off
entity_id: switch.pool_pump
- service: input_boolean.turn_off
entity_id: input_boolean.pool_pump_maintenance_mode
- delay: 00:00:10
- service: input_select.select_option
data:
entity_id: input_select.pool_pump
option: "Auto"
- alias: 'Pool Pump Drain On'
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.pool_pump_drain_pool
to: 'on'
condition:
- condition: state
entity_id: switch.pool_pump
state: 'off'
action:
## Run pump in drain mode for X ##
- service: homeassistant.turn_on
entity_id: switch.pool_pump
- delay: "{{ states('input_number.pump_delay_slider') | multiply(60) | timestamp_custom('%H:%M:%S',False) }}"
- service: homeassistant.turn_off
entity_id: switch.pool_pump
- service: input_boolean.turn_off
entity_id: input_boolean.pool_pump_drain_pool
- alias: 'Pool Pump Drain Off'
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.pool_pump_drain_pool
from: 'on'
to: 'off'
condition:
- condition: state
entity_id: switch.pool_pump
state: 'on'
action:
- service: homeassistant.turn_off
entity_id: switch.pool_pump
## Checks pool pump status every few minutes defined by minutes: '/2'
## (2 minutes in this case)
## and as long as the Input slider is set to Auto, the swimming season
## has been turned on
## and it's between 0800 and 1655, it will turn the pump on.
## Designed without timers to survive HA restarts ##
- alias: 'Check Pool Pump in Season'
initial_state: true
trigger:
- platform: time_pattern
minutes: '/2'
# seconds: 00
condition:
condition: and
conditions:
# Add 'and' condition to check all states are true and will only proceed if all are true #
- condition: state
entity_id: input_select.pool_pump
state: Auto
- condition: state
entity_id: input_boolean.swimming_season
state: 'on'
- condition: template
value_template: "{{ states('sensor.pool_pump_running_today') | float < 7.99 }}"
# The 'or' conditions check if 'any' of the stated times are relevant and proceeds if any are #
- condition: or
conditions:
- condition: time
after: '11:00:00'
before: '16:58:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: time
after: '21:00:00'
before: '23:58:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: time
after: '09:00:00'
before: '18:58:00'
weekday:
- sat
- sun
action:
service: homeassistant.turn_on
entity_id: switch.pool_pump
# No longer used as pump switched of in 'off' season now #
##########################################################
# - alias: 'Check Pool Pump off Season'
# initial_state: true
#
# trigger:
# - platform: time_pattern
# minutes: '/2'
# # seconds: 00
# condition:
# - condition: time
# after: '09:00:00'
# before: '11:55:00'
# - condition: state
# entity_id: input_select.pool_pump
# state: Auto
# - condition: state
# entity_id: input_boolean.swimming_season
# state: 'off'
# action:
# service: homeassistant.turn_on
# entity_id: switch.pool_pump
- alias: 'Turn Pool Pump Off after 8hrs'
initial_state: true
trigger:
- platform: numeric_state
entity_id: sensor.pool_pump_running_today
above: 8.00
condition:
- condition: state
entity_id: input_boolean.swimming_season
state: 'on'
- condition: state
entity_id: input_select.pool_pump
state: Auto
- condition: state
entity_id: switch.pool_pump
state: 'on'
action:
service: homeassistant.turn_off
entity_id: switch.pool_pump
- alias: 'Turn Pool Pump off mid week at Peak Power start'
initial_state: true
trigger:
- platform: time
at: '17:00:00'
condition:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.swimming_season
state: 'on'
- condition: state
entity_id: input_select.pool_pump
state: Auto
- condition: state
entity_id: switch.pool_pump
state: 'on'
action:
service: homeassistant.turn_off
entity_id: switch.pool_pump
# No longer used as pump switched of in 'off' season now #
##########################################################
# - alias: 'Pool Pump Off 1200'
# initial_state: true
#
# trigger:
# - platform: time
# at: '12:00:00'
# condition:
# - condition: state
# entity_id: input_boolean.swimming_season
# state: 'off'
# - condition: state
# entity_id: input_select.pool_pump
# state: Auto
# action:
# service: homeassistant.turn_off
# entity_id: switch.pool_pump
input_boolean:
swimming_season:
name: Swimming Season
icon: mdi:swim
manual_pool_timer:
name: 3hr Manual Pool Timer
initial: off
icon: mdi:av-timer
pool_pump_maintenance_mode:
name: Pool Pump Maintenance Mode
initial: off
icon: mdi:wrench
pool_pump_drain_pool:
name: Drain Pool for x delay
initial: off
icon: mdi:wrench
input_select:
pool_pump:
name: Pool Pump Mode
options:
- 'Auto'
- 'On'
- 'Off'
# initial: 'Auto'
icon: mdi:engine
input_number:
pump_delay_slider:
name: Draining Delay (m)
# mode: box
initial: 6
min: 6
max: 39
step: 3
icon: mdi:camera-timer
sensor:
- platform: mqtt
name: "Pool Temperature"
state_topic: "tele/wemos_pool/SENSOR" ## Was "tele/pool_temp/SENSOR" when using a Sonoff" ##
value_template: "{{ value_json['DS18B20'].Temperature }}"
unit_of_measurement: "°C"
## Jsonpath for MQTT Dashboard is $.DS18B20.Temperature ##
## after subscribing to tele/pool/SENSOR ##
- platform: mqtt
name: "Pool Pump Power"
state_topic: "tele/pool/SENSOR"
value_template: '{{ value_json["ENERGY"]["Power"] }}'
unit_of_measurement: 'W'
- platform: mqtt
name: "Pool Pump Energy"
state_topic: "tele/pool/SENSOR"
value_template: '{{ value_json["ENERGY"]["Today"] }}'
unit_of_measurement: 'kWh'
# - platform: mqtt
# name: 'Sonoff Pool Pump WiFi RSSI'
# state_topic: "tele/pool/STATE"
# value_template: '{{ value_json.Wifi.RSSI }}'
# icon: mdi:signal-variant
# unit_of_measurement: 'dBm'
- platform: mqtt
name: 'Sonoff Pool Pump Uptime'
state_topic: "tele/pool/STATE"
value_template: '{{ value_json.Uptime }}'
icon: mdi:timer-outline
- platform: template
sensors:
pool_pump_status:
friendly_name: "Pool Pump Status"
value_template: "{% if states('sensor.pool_pump_power') | float > 3 %}Active{% else %}Idle{% endif %}"
# Reports 'on' time as a decimal. Used to stop pump after 8.00 hours #
- platform: history_stats
name: Pool Pump running today
entity_id: sensor.pool_pump_status
state: 'Active'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
# Converts above sensor from decimal to Hours and Minutes. Only used to UI #
- platform: template
sensors:
pool_pump_time_on:
value_template: '{{ states.sensor.pool_pump_running_today.attributes.value }}'
friendly_name: 'Pool Pump Hours Running'
- platform: statistics
name: Pool Temperature Stats
entity_id: sensor.pool_temperature
binary_sensor:
- platform: mqtt
name: "Sonoff Pool MQTT Status"
state_topic: "tele/pool/LWT"
value_template: "{{ value }}"
payload_on: "Online"
payload_off: "Offline"
device_class: connectivity
# - platform: ping
# name: Ping Pool Pump
# host: 10.0.1.175
# count: 2
switch:
# - platform: mqtt
# name: "Pool Pump"
# state_topic: "/pool/relay/state"
# command_topic: "/pool/gpio/12"
# payload_on: "1"
# payload_off: "0"
# qos: 2
# retain: true
#
# - platform: rest
# name: Reboot Pool Sonoff
# resource: http://10.0.1.171/?cmd=reboot
- platform: mqtt
name: "Pool Pump"
state_topic: "stat/pool/POWER"
command_topic: "cmnd/pool/POWER"
availability_topic: "tele/pool/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- platform: mqtt
name: Reboot Pool Sonoff
command_topic: "cmnd/pool/Restart1"
###################################
## Group
###################################
group:
@xbmcnut
Copy link
Author

xbmcnut commented Aug 31, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment