@johntdyer,
Sure, I misunderstood what you were looking for.
#
# Created by Keith Townsend, 8/8/2020
# Set pool mode from a simple button that represents one of the modes.
# The use case is to have a pair of pool & spa buttons handling 3 states: pool/spa/off.
# Pressing one will switch to that mode if it wasn't in that mode, or it will turn the system off if it was.
#
# # The following may be added to your python_scripts/services.yaml if you like.
# set_pool_mode:
# description: Set pool mode. Switches to given mode if not current mode, or turns system off if it was in that mode.
# fields:
# mode:
# description: spa, pool or off
# dependencies:
mode_desire = data.get('mode').lower()
mode_sensor = 'sensor.aqualink_pump_mode'
pump_switch = 'switch.filter_pump'
spa_switch = 'switch.spa_mode'
cleaner_switch = 'switch.cleaner'
blower_switch = 'switch.spa_blower'
spa_heater_switch = 'switch.spa_heater'
pool_heater_switch = 'switch.pool_heater'
if mode_desire is None:
logger.warning("===== mode argument is required")
elif hass.states.get(mode_sensor) is None:
logger.warning("===== entity %s wasn't found", mode_sensor)
elif hass.states.get(pump_switch) is None:
logger.warning("===== entity %s wasn't found", pump_switch)
elif hass.states.get(spa_switch) is None:
logger.warning("===== entity %s wasn't found", spa_switch)
elif hass.states.get(cleaner_switch) is None:
logger.warning("===== entity %s wasn't found", cleaner_switch)
elif hass.states.get(blower_switch) is None:
logger.warning("===== entity %s wasn't found", blower_switch)
elif hass.states.get(spa_heater_switch) is None:
logger.warning("===== entity %s wasn't found", spa_heater_switch)
elif hass.states.get(pool_heater_switch) is None:
logger.warning("===== entity %s wasn't found", pool_heater_switch)
else:
current_mode = hass.states.get(mode_sensor).state.lower()
if current_mode == 'delay':
logger.info("===== command for mode [%s] ignored; waiting for pump delay", mode_desire)
elif mode_desire == 'off' or current_mode == mode_desire:
hass.services.call('homeassistant', 'turn_off', {"entity_id":spa_heater_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":pool_heater_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":cleaner_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":blower_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":spa_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":pump_switch})
elif mode_desire == 'pool':
hass.services.call('homeassistant', 'turn_off', {"entity_id":spa_heater_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":blower_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":spa_switch})
hass.services.call('homeassistant', 'turn_on', {"entity_id":pump_switch})
elif mode_desire == 'spa':
hass.services.call('homeassistant', 'turn_off', {"entity_id":pool_heater_switch})
hass.services.call('homeassistant', 'turn_off', {"entity_id":cleaner_switch})
hass.services.call('homeassistant', 'turn_on', {"entity_id":pump_switch})
hass.services.call('homeassistant', 'turn_on', {"entity_id":spa_switch})
else:
logger.warning("===== mode %s wasn't expected", mode_desire)