I’ve spent a bit more time on this and have the below configured and working. Still playing around with it but will add any updates here. My only gripe is the 30 second limit on calls which means there is a delay with updating the status of lights in particular when they are toggled (minor though):
sensor:
- platform: rest
name: Pool Status
resource: https://www.connectmypool.com.au/api/poolstatus
method: POST
payload: '{ "pool_api_code": "ABCDEF-1234567" }'
force_update: true
json_attributes:
- pool_spa_selection
- heat_cool_selection
- temperature
- active_favourite
- heaters
- solar_systems
- channels
- valves
- lighting_zones
value_template: 'OK'
scan_interval: 35
verify_ssl: true
headers:
User-Agent: Home Assistant
Content-Type: application/json
The above, grabs the status every 35 seconds - the API only allows 1 call every 30 seconds which is why I chose 35 seconds.
I then have a number of sensor templates to use some of the variables collected by a single call above to create an individual sensor
- platform: template
sensors:
pool1_spa_selection:
friendly_name: Pool - Pool Spa Selection
value_template: >-
{{ ['Spa', 'Pool'][states.sensor.pool_status.attributes["pool_spa_selection"]|int] }}
pool1_heat_cool_selection:
friendly_name: Pool - Heat Cool Selection
value_template: >-
{{ ['Cooling', 'Heating'][states.sensor.pool_status.attributes["heat_cool_selection"]|int] }}
pool1_temperature:
friendly_name: Pool - Current Temperature
value_template: '{{ states.sensor.pool_status.attributes["temperature"] }}'
device_class: temperature
unit_of_measurement: '°C'
pool1_active_favourite:
friendly_name: Pool - Active Favourite
value_template: '{{ states.sensor.pool_status.attributes["active_favourite"] }}'
pool1_heaters0_mode:
friendly_name: Pool - Heater Mode
value_template: >-
{{ ['Off', 'On'][states.sensor.pool_status.attributes["heaters"][0]["mode"]|int] }}
pool1_heaters0_settemp:
friendly_name: Pool - Heater set temperature
value_template: >-
{{ states.sensor.pool_status.attributes["heaters"][0]["set_temperature"]|int }}
device_class: temperature
unit_of_measurement: '°C'
pool1_heaters0_spasettemp:
friendly_name: Pool - Spa heater set temperature
value_template: >-
{{ states.sensor.pool_status.attributes["heaters"][0]["spa_set_temperature"]|int }}
device_class: temperature
unit_of_measurement: '°C'
pool1_solar_systems0_mode:
friendly_name: Pool - Solar System Mode
value_template: >-
{{ ['Off', 'Auto', 'On'][states.sensor.pool_status.attributes["solar_systems"][0]["mode"]|int] }}
pool1_solar_systems0_set_temp:
friendly_name: Pool - Solar System Set Temp
value_template: >-
{{ states.sensor.pool_status.attributes["solar_systems"][0]["set_temp"]|int }}
device_class: temperature
unit_of_measurement: '°C'
pool1_channels0_mode:
friendly_name: Pool - Current Channel Mode
value_template: >-
{{ ['Off', 'Auto', 'On', 'Low Speed', 'Medium Speed', 'High Speed'][states.sensor.pool_status.attributes["channels"][0]["mode"]|int] }}
pool1_valves0_mode:
friendly_name: Pool - Valve Mode
value_template: >-
{{ ['Off', 'Auto', 'On'][states.sensor.pool_status.attributes["valves"][0]["mode"]|int] }}
pool1_light_status:
friendly_name: Pool - Light Status
value_template: >-
{{ ['Off', 'Auto', 'On'][states.sensor.pool_status.attributes["lighting_zones"][0]["mode"]|int] }}
I also have a rest command that uses variables so when you call the service you can pass action_code, device_number and value
rest_command:
poolaction:
url: "https://www.connectmypool.com.au/api/poolaction"
method: post
content_type: 'application/json; charset=utf-8'
payload: '{"pool_api_code": "ABCDEF-123456","action_code": {{action_code}},"device_number": {{device_number}},"value": "{{value}}","wait_for_execution": false}'
verify_ssl: true
Below is an example of how i call the poolaction in an automation (automations.yaml) though I’ve chosen to use a switch instead leveraging the rest_command:
alias: Pool Lights On
description: ''
trigger:
- platform: webhook
webhook_id: pool0075-7c52e280-99f7
condition: []
action:
- service: rest_command.poolaction
data:
action_code: 6
device_number: 0
value: 2
mode: single
Below is my switch config for the lights which could be easily adjusted to turn on/off other components (heating, channels, valves) - despite the 30 second limit on API calls, this seems to work well by requesting the sensor.pool_status is updated after each state change from on/off:
#########################################
####### ASTRAL POOL LIGHT SWTICH ########
#########################################
- platform: template
switches:
pool_lights:
value_template: "{{ is_state('sensor.pool1_light_status', 'On') }}"
unique_id: 82343cb7e79-82332cde7e79
friendly_name: Pool Light Switch
turn_on:
- service: rest_command.poolaction
data:
action_code: 6
device_number: 0
value: 2
- delay: 2
- service: homeassistant.update_entity
entity_id: sensor.pool_status
turn_off:
- service: rest_command.poolaction
data:
action_code: 6
device_number: 0
value: 0
- delay: 2
- service: homeassistant.update_entity
entity_id: sensor.pool_status
Pool Heater Switch
#########################################
###### ASTRAL POOL HEATER SWTICH ######
#########################################
- platform: template
switches:
pool_heater:
value_template: "{{ is_state('sensor.pool1_heaters0_mode', 'On') }}"
unique_id: 82343cb1e79-82cc2cde7e79
friendly_name: Pool Heater Switch
turn_on:
- service: rest_command.poolaction
data:
action_code: 4
device_number: 1
value: 1
- delay: 2
- service: homeassistant.update_entity
entity_id: sensor.pool_status
turn_off:
- service: rest_command.poolaction
data:
action_code: 4
device_number: 1
value: 0
- delay: 2
- service: homeassistant.update_entity
entity_id: sensor.pool_status
Pool Valve Switch
#########################################
####### ASTRAL POOL VALVE SWTICH #######
#########################################
- platform: template
switches:
pool_valve:
value_template: "{{ is_state('sensor.pool1_valves0_mode', 'Auto') }}"
unique_id: 81343cb1e79-82cc1cde7e76
friendly_name: Pool Valve Switch
turn_on:
- service: rest_command.poolaction
data:
action_code: 2
device_number: 0
value: 1 #1 - auto, 2 - on
- delay: 2
- service: homeassistant.update_entity
entity_id: sensor.pool_status
turn_off:
- service: rest_command.poolaction
data:
action_code: 2
device_number: 0
value: 0
- delay: 2
- service: homeassistant.update_entity
entity_id: sensor.pool_status
Astral’s API documentation