Rest Sensor receiving JSON - Astralpool - connectmypool.com.au

Can anyone suggest what is not working here?

This is in sensor.yaml

  - name: "Pool Temp"
    platform: rest
    resource: https://www.connectmypool.com.au/api/poolstatus
    method: POST
    payload: '{ "pool_api_code": "ABCDEF-1234567" }'
    force_update: true
    scan_interval: 900
    value_template: "{{ value_json[0].temperature }}"

for value_template: "{{ value_json[0].temperature }}" i have also tried
value_template: "{{ value_json.temperature }}"

When I hit the endpoint above using postman it outputs the JSON below:

{
    "pool_spa_selection": 1,
    "heat_cool_selection": 1,
    "temperature": 17,
    "active_favourite": 255,
    "heaters": [
        {
            "heater_number": 1,
            "mode": 0,
            "set_temperature": 27,
            "spa_set_temperature": 0
        }
    ],
    "solar_systems": [],
    "channels": [
        {
            "channel_number": 1,
            "mode": 1
        }
    ],
    "valves": [
        {
            "valve_number": 0,
            "mode": 0
        }
    ],
    "lighting_zones": [
        {
            "lighting_zone_number": 0,
            "mode": 1,
            "color": 5
        },
        {
            "lighting_zone_number": 1,
            "mode": 1,
            "color": 0
        }
    ]
}

weird, after waiting a while it worked, wonder if it was throttling or something

Hi there, I also have Astralpool - did you add any other sensors?

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

2 Likes

Thanks @smck83 - this really helped me a lot! I can now see from HA exactly how bitterly cold the water is in my pool now that itā€™s winter. :wink:

Have you bothered to setup a thermostat and/or colour chooser card in HA? Iā€™m thinking about it, although not sure if Iā€™d ever actually use it. FWIW Iā€™ve also hooked an esp8266 with a dual relay connected to my Viron Connect 10 so I can trigger a couple of favourites directlyā€¦

Iā€™m glad to hear it helped you out. Definitely cold this time of year and not worthy of a swim.

I put this together for my brother and as you said being winter here, so I dont think heā€™s looked at it since. A thermostat is a good idea and colour selector (prob with input_select).

Untested (as I no longer have access to his HA):

climate:
  - platform: generic_thermostat
    name: Pool
    heater: switch.pool_heater
    target_sensor: sensor.pool1_temperature
    min_temp: 18
    max_temp: 35
    target_temp: 20

EDIT: looking at this again, you would need to create a template switch that turns on the heater and can have the target temp passed to it. If I get some time over the next week Iā€™ll import my bros pool config back into mine and test

Thanks again @smck83 - minor thing to note will be the Viron controller is operating as the thermostat, turning the heater on/off, so the HA temperature control would just need to change the set temp and turning the heater on/off can be left for the controller to deal with. Probably doesnā€™t need to be too complex - maybe using input_select for that as well as for the colours might be good enough. If I get around to doing something Iā€™ll update on this thread as well. :slight_smile:

Well, with the snap lockdown here in Vic I found myself with a little spare time. So FWIW although I am certain that there would be many better ways of doing this, I decided that the simplest thing was to just use input_select for everything. So in configuration.yaml I have:

input_select:
  pool_lights_mode:
    name: Pool Lights Mode
    options:
      - "off"
      - "auto"
      - "on"
    icon: mdi:dome-light
  pool_light_colour:
    name: Pool Lights Colour
    options:
      - "Ocean"
      - "Red"
      - "White"
      - "Blue"
      - "Disco"
    icon: mdi:palette
  pool_set_temp:
    name: Pool Set Temp
    options:
      - "15"
      - "25"
      - "35"
    icon: mdi:coolant-temperature

and in automations.yaml (complete with random unique ID) I have:

- id: '1628215649699'
  alias: Pool Lights on
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_lights_mode
    to: 'on'
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 6
      device_number: 0
      value: 2
  - delay: 2
  - service: homeassistant.update_entity
    entity_id: sensor.pool_status
  mode: single
- id: '1628216257083'
  alias: Pool Lights auto
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_lights_mode
    to: auto
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 6
      device_number: 0
      value: 1
  - delay: 2
  - service: homeassistant.update_entity
    entity_id: sensor.pool_status
  mode: single
- id: '1628216485771'
  alias: Pool Lights off
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_lights_mode
    to: 'off'
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 6
      device_number: 0
      value: 0
  - delay: 2
  - service: homeassistant.update_entity
    entity_id: sensor.pool_status
  mode: single
- id: '1628218549063'
  alias: Pool Temp to 15
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_set_temp
    to: '15'
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 5
      device_number: 1
      value: 15
  - delay: 2
  mode: single
- id: '1628219245273'
  alias: Pool Temp to 25
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_set_temp
    to: '25'
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 5
      device_number: 1
      value: 25
  - delay: 2
  mode: single
- id: '1628219608541'
  alias: Pool Temp to 35
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_set_temp
    to: '35'
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 5
      device_number: 1
      value: 35
  - delay: 2
  mode: single
- id: '1628219940723'
  alias: Pool Colour Ocean
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_light_colour
    to: Ocean
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 7
      device_number: 0
      value: 17
  - delay: 2
  mode: single
- id: '1628220258739'
  alias: Pool Colour White
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_light_colour
    to: White
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 7
      device_number: 0
      value: 7
  - delay: 2
  mode: single
- id: '1628220785067'
  alias: Pool Colour Blue
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_light_colour
    to: Blue
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 7
      device_number: 0
      value: 5
  - delay: 2
  mode: single
- id: '1628221525177'
  alias: Pool Colour Red
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_light_colour
    to: Red
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 7
      device_number: 0
      value: 1
  - delay: 2
  mode: single
- id: '1628221656195'
  alias: Pool Colour Disco
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.pool_light_colour
    to: Disco
  condition: []
  action:
  - service: rest_command.poolaction
    data:
      action_code: 7
      device_number: 0
      value: 10
  - delay: 2
  mode: single

then in lovelace I can have a card:

type: entities
entities:
  - entity: input_select.pool_set_temp
  - entity: input_select.pool_lights_mode
  - entity: input_select.pool_light_colour
title: Pool

I also have devices for the two relays as well as some other scripts but basically, all good now. Sadly although the pool does report back the chemistry levels (ORP and pH) to connectmypool, this info isnā€™t available via the API. Would be nice to be able to see that as well, so I could monitor the levels over timeā€¦ might try asking themā€¦ :slight_smile:

Nice one @zagnuts thanks for sharing.

I noticed the same thing re: chemicals. Seems strange that they wouldnā€™t share that via APi.

Hi @smck83. FWIW I got in contact with them, and they were interested to hear about HA and I sent them some info on what weā€™ve done. I also asked about the missing API info and the response was ā€œI think that the ORP and pH were left off to keep things simpler. We can look at adding these in in the future.ā€ So thereā€™s that to possibly look forward to I guess. I suppose we could use scrape or something to get the pH level and an alert if ORP status ever changes from ā€˜OKā€™ā€¦ but for the moment Iā€™m happy with what I have so far. :slight_smile:

1 Like

The API connection seems pretty solid. The lockdown continues, so just as a test I used ā€œparsehubā€ to capture the pH and ORP info from connectmypool, and to my amazement it worked. In fact it actually worked really well.

Iā€™d be tempted to use it, but looks like I need to use curl statements (which I created - one to fire off the scrape, and another to get the results) and the json responses are in gzip format making life just that little more tricky in hassio. Need to work out how to use the ā€˜nativeā€™ scrape tool and see if/how it handles the login requirements.

As an aside, the other thing that confuses/annoys me slightly is the system just saying the ORP is ā€œOKā€ as opposed to actually saying what it is. The Viron EQ18 thing actually has that info, so my guess is they actively dumb that down by comparing actual with the set point to check if itā€™s good. Just saying itā€™s ā€œOKā€ reminds me of my old Torana that had an engine light - if it ever went on, you knew the reason why the car had stopped was because your engine had just exploded. Kinda would have been nice to have some sort of earlier warning. Sigh.

OK, so more time available due people deciding that itā€™s ok to either not wear masks or have no idea how to wear them properly so more lockdownsā€¦ sigh. Anyhow, here is how Iā€™ve grabbed the ā€˜missingā€™ info - it may not be pretty, but it works. :wink:

  • Create a project on parsehub that is able to grab the pH info. I also grabbed the orp status, setting, and last update info although they are all probably pointless.
  • Use the command_line integration to run the scrape every (say) 15 mins. The levels shouldnā€™t fluctuate all that much so that should be more than enough. Also keep in mind that the info will only update when the pool filter is running.
  • Use the command_line integration to download the info as a gzip json file, and add the attributes to a sensor. Run this at slightly more or less than the scrape so that after the server is restarted, they normally run at different times.
  • Create individual sensors to pull out the info from the main sensor attribute
  • Enjoy
  - platform: command_line
    name: Pool Scrape
    json_attributes:
      - ORP_Status
      - ORP_SetPoint
      - pH
      - LastUpdate
    command: 'curl -X GET "https://www.parsehub.com/api/v2/projects/[magic stuff]/last_ready_run/data?api_key=[more magic stuff]&format=json"|gunzip'
    value_template: "{{ value_json.pool }}"
    scan_interval: 850
  - platform: command_line
    name: Run Scrape
    command: 'curl -X POST "https://www.parsehub.com/api/v2/projects/[magic stuff]/run?api_key=[magic stuff again]"'
    scan_interval: 900

and

  - platform: template
    sensors:
      pool1_ph_status:
        friendly_name: Pool - pH
        value_template: '{{ states.sensor.pool_scrape.attributes["pH"] }}'
        unit_of_measurement: 'pH'
      pool1_orp_status:
        friendly_name: Pool - ORP Status
        value_template: '{{ states.sensor.pool_scrape.attributes["ORP_Status"] }}'
      pool1_orp_setpoint:
        friendly_name: Pool - ORP Set Point
        value_template: '{{ states.sensor.pool_scrape.attributes["ORP_SetPoint"] }}'
        unit_of_measurement: 'mV'
      pool1_lastupdate:
        friendly_name: Pool - pH Last Update
        value_template: '{{ states.sensor.pool_scrape.attributes["LastUpdate"] }}'

2 Likes

This is amazing!

Does someone have a way to install this using a plugin or what is the best way of doing this? - is this on HACS? - I am pretty new to all of this

I am new to HA and have recently just had a Viron Connect 10 installed on my pool. To say the app is underwhelming is an understatement. I already run HA for most the other items in my house.

Can someone please post a screenshot of what your pool controls look like for the above config? I am interested to see how it all looks/behaves.

1 Like

1 Like

No HACS or integrations required, everything is built in, but you do need to request the API specific to your pool (go into the connectmypool website, then settings, then home automation). Once you have the API, you can do pretty much everything except find out the pH and ORP info as that is currently not exposed in the API.

To get the pH info, you need to use a scrape tool to get it from the connectmypool website - in my example in this thread I used parsehub to create a job that grabs the info as json that can then be loaded into HA as sensors. It is possible that you might be able to use the HA scrape integration, but as it has to make its way through a login process parsehub seemed easier - if anyone works out how to use the scrape integration to do this instead, please let use know! :wink:

Thanks, guys. Iā€™m going to have a crack at configuring it now.

How long did it take you to get the api? Iā€™ve registered for it through the web portal and havenā€™t heard anything back.

Thanks @zagnuts I got the API but I am unsure where to paste the code and which one to actually paste since there are a number of revisions.

We have:

  • Pool / Spa Heater
  • Water Feature - Valve Control
  • Water Feature 2 - Valve Control
  • Pool Pump
  • Spa Pump
  • Lights
  • PH reader etcā€¦

Can you give me a hint on which of the above code I need and where I paste this in HA?

Thanks so much!