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

No - I got distracted trying moving my Tuya kit to the new integration. I might have another look at it this weekend if I get the chance. I promise to update this thread if I do get it to work using multiscrape rather than parsehub… I should note that it definitely does work with parsehub, it just (for me) seemed to not always fire.

So, I’ve given up trying to get the info via the built in scrape tool, or by multiscrape. For whatever reason, I suspect the authentication side of things simply isn’t working. I expect it should be possible, but the solution eludes me. If someone else would like to give it a go, please feel free, but I’ve gone back to using parsehub with some minor tweaks as follows:

  • 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 fairly pointless.
  • Use the shell command to run the scrape every (say) 30 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. I found that this would stop running randomly when I first set it up, so instead I changed this to be executed via an automation eg: in your automations.yaml, create the following (easiest thing is to create it via the gui, edit in yaml, and paste:
alias: Parsehub - run pool scrape
description: ''
trigger:
  - platform: time_pattern
    minutes: /30
condition:
  - condition: time
    after: '09:00:00'
    before: '18:00:00'
action:
  - service: shell_command.run_pool_parsehub
mode: single

This runs the parsehub scrape command every 30 minutes, between 9am and 6pm. Obviously you can change that if you want. I figure that the pH etc won’t change that quickly, plus I don’t want to hit the parsehub or connectmypool servers too hard. Also keeping in mind that the data only gets updated whilst the filter pump is running.

And in configuration.yaml insert:

shell_command:
  run_pool_parsehub: 'curl -X POST "https://www.parsehub.com/api/v2/projects/magicnumbers/run?api_key=magicnumbers"'

Changing the ‘magicnumbers’ to match your project and api key in parsehub. This asks parsehub to run the saved project.

  • Use the command_line integration to download the info as a gzip json file, and add the attributes to a sensor. So add this into your sensor.yaml file (or configuration.yaml file if you have everything in the one file)
  - 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: 300
  • Create individual sensors to pull out the info from the main sensor attribute, again in the sensor.yaml or configuration.yaml file
  - 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"] }}'
      pool1_lastscrape:
        friendly_name: Pool - pH Last Scrape
        value_template: "{{ as_timestamp(state_attr('automation.parsehub_run_pool_scrape', 'last_triggered')) | timestamp_custom('%A @ %-I:%M %p') }}"

  • Enjoy

I should note that by moving the commands to fire off the parsehub project into an automation, I’ve found this to be pretty reliable. It is also a lot easier to tweak when it actually runs than it was before. As an aside, I did try to combine everything into the one command - and it would have worked but the script takes just over a minute to run and HA has a non-configurable 60 second limit to scripts so it would timeout. So computer says no. :wink:

Looks like www.connectmypool.com.au has been down (for a couple of days?)

image

It would be good not to depend on going through the cloud to read/write data to the Astral internet gateway device to avoid situations like this.

PS I’ve got a number of things going with the code above. Also using a Fibaro Smart Implant added to our Hayward Heatpump unit - connected in to measure the input/output temperature sensors (measuring the voltage) and converting it from voltage to temp - seems to work ok.

A big +1 from me, in particular given that the server has gone down a few times over the past couple of months. Sadly, however, I don’t think that we have much choice. I’ve done a quick scan of the gateway, and no obvious ports seem to be open. Now of course this is pool equipment, not a mainframe at the CIA, so I have to assume it would be more than possible to somehow capture the info going to/from the gateway and then in turn spoof that but meh, I have better things to do with my life. :wink:

Speaking of which, I updated my sensor code above to include an extra one that lets me know when the scrape last ran. Not super critical, but hey - why not.

I’ve got most stuff working.

Yet to play with the code for the Ph etc a go - but will do that next - thanks for sharing (and updating).

Read with interest this thread. Got my pool completed last Friday and got an internet gateway. As mentioned, the app is really poor.

So I wrapped this screen today:

All buttons are effective and will reflect within a few seconds the action performed.

To sync the input_select list I used the following script:

- alias: Sync Light Colour from Input Select
  trigger:
    - platform: state
      entity_id: input_select.pool_light_colour
      for: 00:00:02
  condition: []
  action:
    - service: rest_command.poolaction
      data_template:
        action_code: 7
        device_number: 0
        value: >
          {% set coloursDict = { '-': 0, 'Red' : 1, 'Orange': 2 , 'Yellow' : 3 , 'Green' : 4 , 'Blue' : 5, 'Purple' : 6, 'White' : 7, 'User 1' : 8, 'User 2': 9, 'Disco': 10, 'Smooth': 11, 'Fade': 12, 'Magenta':13, 'Cyan':14, 'Pattern':15, 'Rainbow': 16, 'Ocean': 17 } %}
          {{ coloursDict[states('input_select.pool_light_colour')] }}
    - delay: 5
    - service: homeassistant.update_entity
      entity_id: sensor.pool_status
  mode: single
- alias: Sync Light Colour from Sensor
  trigger:
    - platform: state
      entity_id: sensor.pool_light_colour
      for: 00:00:02
  condition: []
  action:
    - service: input_select.select_option
      target:
        entity_id: input_select.pool_light_colour
      data_template:
        option: >
          {{ states('sensor.pool_light_colour') }}
  mode: single

- alias: Sync Gas Heater Temperature
  trigger:
    - platform: state
      entity_id: input_select.pool_gas_set_temp
      for: 00:00:02
  condition: []
  action:
    - service: rest_command.poolaction
      data_template:
        action_code: 5
        device_number: 1
        value: >
          {{ states('input_select.pool_gas_set_temp') }}
    - delay: 5
    - service: homeassistant.update_entity
      entity_id: sensor.pool_status
  mode: single

- alias: Sync Heat Pump Heater Temperature
  trigger:
    - platform: state
      entity_id: input_select.pool_heatpump_set_temp
      for: 00:00:02
  condition: []
  action:
    - service: rest_command.poolaction
      data_template:
        action_code: 5
        device_number: 2
        value: >
          {{ states('input_select.pool_heatpump_set_temp') }}
    - delay: 5
    - service: homeassistant.update_entity
      entity_id: sensor.pool_status
  mode: single

Which I believe is a bit better than the solution given above that creates as many automations as there are colours.

All buttons are toggles: in the spa can set the blower and the two different jets pump.
The list of pumps have a tap action to cycle between the modes and the text will reflect that.

The action to switch in the entities card is call this script:

alias: Cycle Channel
mode: single
sequence:
  - service: rest_command.cyclechannel
    data:
      channel: "{{ channel }}"
  - delay: 5
  - service: homeassistant.update_entity
    entity_id: sensor.pool_status

The rest_command.yaml being:

poolaction:
  url: "https://www.connectmypool.com.au/api/poolaction"
  method: post
  content_type: "application/json; charset=utf-8"
  payload: '{"pool_api_code": "ABCDEF-1234567","action_code": {{ action_code }}, "device_number": {{ device_number }}, "value": "{{ value }}", "wait_for_execution": false}'
  verify_ssl: true

cyclechannel:
  url: "https://www.connectmypool.com.au/api/poolaction"
  method: post
  content_type: "application/json; charset=utf-8"
  payload: '{"pool_api_code": "ABCDEF-1234567","action_code": 1, "device_number": {{ channel }}, "value": "", "wait_for_execution": false}'
  verify_ssl: true

It shouldn’t be too complicated to write an integration that automatically create the input_select list for t for the favourites as can be retrieved from the poolconfig action.
And that present the lighting like a proper coloured lights.

Though, as everything is really custom with likely no generic configuration, I’m not sure it’s worth spending the time on this.

View with blower on, phone in landscape:

Tapping on the pool temperature in the centre also let you change it.

Do you guys know if it’s possible to get the status of the pump or heater when in Auto mode?

On the Astral app or website, you see a little symbol next to the switch to indicate that it’s on. But I don’t see that anywhere in the poolstatus data.

unfortunately not through the API. you could try scrapping the website as mentioned above. I am planning on doing this for my gas heater so i can see when it is actually heating so I can then make some assumptions on the gas usage.

Hi guys,

Fantastic work!
I’ve have everything working with my system, but I’m a little stuck on configuring a dropdown in Lovelace to set the heater temperature.

Would anyone be able to help with the required code, please?

Thanks so much!

I wrote that code in the post above.

This is the input_select components I’ve created

pool_lights_mode:
  name: Pool Lights Mode
  options:
    - "off"
    - "auto"
    - "on"
  icon: mdi:dome-light
pool_light_colour:
  name: Pool Lights Colour
  options:
    - "Red"
    - "Orange"
    - "Green"
    - "Blue"
    - "White"
    - "User1"
    - "Disco"
    - "Magenta"
    - "Cyan"
    - "Pattern"
    - "Rainbow"
    - "Ocean"
pool_heatpump_set_temp:
  name: Heat Pump Set Temp
  options:
    - "18"
    - "19"
    - "20"
    - "21"
    - "22"
    - "23"
    - "24"
    - "25"
    - "26"
    - "27"
    - "28"
    - "29"
    - "30"
  icon: mdi:coolant-temperature
pool_gas_set_temp:
  name: Gas Heater Set Temp
  options:
    - "18"
    - "19"
    - "20"
    - "21"
    - "22"
    - "23"
    - "24"
    - "25"
    - "26"
    - "27"
    - "28"
    - "29"
    - "30"
    - "31"
    - "32"
    - "33"
    - "34"
    - "35"
    - "36"
    - "37"
    - "38"
  icon: mdi:coolant-temperature
pool_set_favourite:
  name: Pool Set Favourite
  options:
    - "All Off"
    - "All Auto"
    - "Pool"
    - "Spa"
  icon: mdi:heart-plus-outline

The automations to sync all of those into the required REST commands are in the post prior to yours

Hi @zagnuts, others, I’ve been trying to update the state of the input_select for the pool favourite to match that from the API, but doesn’t seem to be working. IE when someone changes the pool mode on the controller or changes the mode via myconnect app.

I tried adding the automation below to the automations.yaml. The names of the favourites match the input_select options. Any thoughts anyone? have you used some other mechanism to update the input_select value to match the sensor.pool_favourite_active. One issue I can see is that the sensor takes a while to update - but should be ok still ??

- id: '1640827860154'
  alias: Pool Mode - Update Selector
  description: If the state changes update the input_select for Pool Mode
  trigger:
  - platform: state
    entity_id: sensor.pool_active_favourite
  condition: []
  action:
  - service: input_select.select_option
    target:
      entity_id: input_select.pool_favourites
    data:
      option: "{{ states('sensor.pool_active_favourite') }}"
  mode: single

I see what you’re trying to do there - I had noticed the same issue (the state of the input_select doesn’t get updated if it is changed outside of HA), but hadn’t really bothered to make a work around. Check out the post above from Jean-Yves (Rest Sensor receiving JSON - Astralpool - connectmypool.com.au - #97 by jyavenard).

Thanks - my solution doesn’t work very reliably as there is a bit of a delay and loop in that the input_select is changing the sensor favourites which seems to go to All Off before going to the new state which then sets input_select to All Off and this triggers the sensor (actual state to go to All Off) rather than the new state. I think because a) goes through All Off before the new state and b) the delay in updates.

Will look at Jean-Yves post - I didn’t seen anything pop out for this on first pass. Cheers

I’d check the extra ‘for’ line missing in your code:

Which I suspect means - because there’s no line asking what attribute state to check for - that it will check the state every two seconds no matter what. This means the input_select status will be updated correctly even if it has to go through a few states on the way. Personally, I’d probably do it less frequently - maybe once a minute - but that’s a personal choice!

it’s not that. It will only trigger the action if the state has been stable for over 2s.

It’s to reduce the time it takes to change say temperature by doing +, +, + ; otherwise it would send a REST command immediately when you’re adjusting the temperature or like scrolling in the list.

This allows the final command to be sent to the server much quicker. The average time for the server to acknowledge a command is very low sometimes, up to 30s.

So if you to change the temp from 25 to 28 you had sent 4 times a command, it would take over 2 minutes for the final one to be the active one.
Hence why I added a delay of 2s when the state change.

1 Like

The server lately has been ultra slow; I’ve seen up to 5 minutes when turning on the light before it actually happens.

I’m guessing you’re seeing this issue, little to do with HA or your rules by temselves.

1 Like

Thanks @jyavenard BTW did anyone figure out how to detect if a channel is actually turned on. EG Pump can have settings Off, Auto, On. And in Auto, it will come on, but the status still returns Auto.

I see in the actual ConnectMyPool app / webinterface that is shows if the pump is actually on or off next to the mode.

image

There’s no ability to do that with the API.

Earlier here there were talks about scraping the website to get that information along the pH information)

1 Like

@zagnuts I finally made it back to Australia to visit my family after configuring this pool from New York for a full year :rofl:

Now that I have had time to play with the Viron Connect it makes a little more sense how the channels etc. are all configured. But it has been SO long since I did the configuration.yaml stuff I have totally forgotten how I got there.

  1. So in my yaml I have the following code below (I think I might have copied it from you or did it get auto created when I added the sensor.pool_status?

  2. I configured a bunch of new favourites today, should they automatically be pulled into this code?

  3. Did anyone ever figure out how to control channels through a dropdown in Lovelace so we can simply select a state (i.e. Water Fountain - ON, OFF, AUTO. Same with any other channels?

  4. How are people getting 'Pool Temperature"? I see we can set the heater temp but I am not sure what is measuring the pool temperature as I just get “–” on the gauge.

  5. Anyone have some pre-written code I can copy? I am only in Australia for 3 weeks before heading overseas again.

  ############################
  ####Connect My Pool Core####
  ############################
sensor:
  - platform: rest
    name: Pool Status
    resource: https://www.connectmypool.com.au/api/poolstatus
    method: POST
    payload: '{ "pool_api_code": "xxxxxxx" }'
    force_update: true
    json_attributes:
    - pool_spa_selection
    - heat_cool_selection
    - 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

  ###############################
  ####Connect My Pool Sensors####
  ###############################
  - platform: template
    sensors:
      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: Heater 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_channels1_mode:
        friendly_name: Pool - Pump Mode
        value_template:   >-
          {{ ['Off', 'Auto', 'On', 'Low Speed', 'Medium Speed', 'High Speed'][states.sensor.pool_status.attributes["channels"][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] }}
      pool1_valves1_mode:
        friendly_name: Pool - Valve Mode
        value_template:   >-
          {{ ['Off', 'Auto', 'On'][states.sensor.pool_status.attributes["valves"][0]["mode"]|int] }}
      pool1_channels2_mode:
        friendly_name: Spa Blower 1
        value_template:   >-
          {{ ['Off', 'Auto', 'On'][states.sensor.pool_status.attributes["channels"][0]["mode"]|int] }}
      pool1_channels3_mode:
        friendly_name: Second Spa Pump - Current Channel Mode
        value_template:   >-
          {{ ['Off', 'Auto', 'On', 'Low Speed', 'Medium Speed', 'High Speed'][states.sensor.pool_status.attributes["channels"][0]["mode"]|int] }}
      pool1_valves3_mode:
        friendly_name: Second Spa Pump - Valve Mode
        value_template:   >-
          {{ ['Off', 'Auto', 'On'][states.sensor.pool_status.attributes["valves"][0]["mode"]|int] }}
      pool1_channels4_mode:
        friendly_name: Waterfall- 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: Water Feature - Valve Mode
        value_template:   >-
          {{ ['Off', 'Auto', 'On'][states.sensor.pool_status.attributes["valves"][0]["mode"]|int] }}

  ####################################
  ####Connect My Pool REST Command####
  ####################################
rest_command:
  poolaction:
    url: "https://www.connectmypool.com.au/api/poolaction"
    method: post
    content_type:  'application/json; charset=utf-8'
# Change the API to match yours. You might want to put this in your secrets file.
    payload: '{"pool_api_code": xxxxxxxxx","action_code": {{action_code}},"device_number": {{device_number}},"value": "{{value}}","wait_for_execution": false}'

#########################################
####### ASTRAL SWTICHES ########
#########################################

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
  waterfall_mode:
    name: Waterfall Status
    options:
      - "off"
      - "auto"
      - "on"
    icon: mdi:dome-light
  spa_first_blower:
    name: Top Spa Bubbles
    options:
      - "Auto"
      - "On"
      - "Off"
    icon: mdi:dome-light
  water_fountain:
    name: Water Fountain
    options:
      - "Auto"
      - "On"
      - "Off"
    icon: mdi:dome-light 
  pool_pump:
    name: Pool Pump Mode
    options:
      - "Auto"
      - "On"
      - "Off"
      - "High Speed"
      - "Medium Speed"
      - "Low Speed"
    icon: mdi:dome-light 

I am watch this with great interest…I’ve tried to implement some of it…but beyond my 48hours of HA experience. was able to get the first parts to work like status. but once i tried to add switching/status change…isn’t working for me.

be interested if someone is going to pull this together as an add-on/integration to take some of the programming out of it. or is it to variable with how people have implemented the devices on the connect10 to do that?

clear i’ve got more reading…be good if some of the code was condensed into packages with instructions for adding it to the various yaml files or Lovelace cards.

Thank you guys for the hard work…I’m sure I’ll be back with some questions. and posting my code for help soon

my set-up in the Connect 10
-Channel 1 Filter Pump (Viron Variable)
-Channel 2 Lights
-Channel 3 Gas Heater Power
-Channel 4 Blower 1 (Spa)
-Channel 5 Blower 2 (Runway Entry)
-Channel 6 Pump Spa Jets
-Channel 7 Pump for Heat Pump

Would ideally like 2 automations

  1. When an Amber Price spike occurs all pumps turn off
  2. When pool isn’t at temp and Amber price is below $X that HeatPump Pump Runs (Heat Pump turns on and off with flow switch and remains constantly on (poop temp is grabbed by Gas Heater on circuilation/filter pump)
  - platform: rest
    name: Pool Status
    resource: https://www.connectmypool.com.au/api/poolstatus
    method: POST
# Change the API to match yours. You might want to put this in your secrets file.
    payload: '{ "pool_api_code": "xxxxxx-xxxxxx" }'
    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: 120
    verify_ssl: true
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json

      
  - platform: template
    sensors:
      pool1_pool_spa_selection:
        friendly_name: Pool - Pool Spa Selection
        value_template:   >-
          {{ ['Spa', 'Pool'][states.sensor.pool_status.attributes["pool_spa_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_spa_settemp:
        friendly_name: Spa - Heater set temperature
        value_template:   >-
          {{ states.sensor.pool_status.attributes["heaters"][0]["spa_set_temperature"]|int }}
        device_class: temperature
        unit_of_measurement: '°C'

rest_command:
  poolaction:
    url: "https://www.connectmypool.com.au/api/poolaction"
    method: post
    content_type:  'application/json; charset=utf-8'
    payload: '{"pool_api_code": "xxxxxx-xxxxxx","action_code": {{action_code}},"device_number": {{device_number}},"value": "{{value}}","wait_for_execution": false}'
    verify_ssl: true

    
switch:
  - platform: template
    switches:
      pool_heater:
        value_template: "{{ is_state('sensor.pool1_heaters0_mode', 'On') }}"
        friendly_name: Pool Heater Switch
        turn_on:
         - service: rest_command.poolaction
           data: 
             action_code: 4
             device_number: 0
             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: 0
             value: 0
         - delay: 2
         - service: homeassistant.update_entity
           entity_id: sensor.pool_status

Switch doesn’t change anything…do i need to add anything to the automation.yaml or lovelace card to make it work?