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

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?

it should appear and work as a switch, be aware that it may take up to 30s for the command to be processed by the server.

Ive got the switch up on the interface (button card)…but definitely doesn’t change the heater on/off

I’m stumped.

my variables turn up fine…so I can see on the dashboard a change (if i make manual or with app). but pressing the button on HA doesn’t change it

Did you create the rest_command.poolaction anywhere?
I don’t see this in your copy/paste

edit: ok I do see it, but how did you enter those config, do you see your rest_command in the developer tools? did you check your log?

I have the feeling that you didn’t place the various config in the right spot.

Are you sure that the entity name is sensor.pool1_heaters0_mode ? it would be unusual.
For me it’s sensor.pool_heaters0_mode

I’m sure you are right…

I can see the rest_command pool in the developer tools under services

log doesn’t have anything

I made some small changes and added a lighting switch…which works fine…argh
Heater Switch comes right after and looks fine, but doesn’t work…however i did something and now reflects the active state…so that is a bonus

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


switch:

#########################################
####### ASTRAL POOL LIGHT SWTICH ########
#########################################
  - platform: template
    switches:
      pool_lights:
        value_template: "{{ is_state('sensor.pool1_lighting_zones', 'On') }}"
        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

  - 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

Check sensor.pool_heaters0_mode vs sensor.pool1_heaters0_mode and that it’s the right action code and device_number

For me it device_number 1 because unlike other entities, heater starts at 1 not 0

those settings all work perfect to bring in the parameters and current status
I tried changing it and it broke! Button just doesn’t work…but lighting one does!! lol

Screen Shot 2022-02-04 at 1.37.29 pm|490x499

I doubt it, because there can’t be a heater 0. It starts at 1

gotcha…yes…device number…rest was fine…thank you.

what is the process to get a switch i can use in an automation for a channel now? because the channels are a sequence…off,auto,on/speeds…moveing forward with each click.

I need an automation to know the state and advance till correct state, but there is significant delay at times

I’ve used this bit of code and it seems to work to advance the mode.

#########################################
####### ASTRAL POOL CHANNEL1 TOGGLE #####
#########################################
  - platform: template
    switches:
      pool_channel4:
        value_template: > 
        friendly_name: "Heater Pump - {{ states('sensor.pool1_channels4_mode') }}"
        turn_on:
         - service: rest_command.poolaction
           data: 
             action_code: 1
             device_number: 5
         - delay: 1
         - service: homeassistant.update_entity
           entity_id: sensor.pool_status
        turn_off:

I’m a little stumped how i would make the following automation(s) (given the way Channels cycle)

Pool Current Temperature = 30c → Turn off HeatPump Pump

Pool Current Temp = <30c and Amber Electricity Pice is <0.20 → turn on heatpump pump

Amber Price Spike = Yes → Turn off heatpump pump

Is there some way to script to confirm current state and toggle based on that result?

what you describe isn’t particularly complicated, it’s just an automation based on the criteria you want.
You create two automations : one for when to turn off the pool and one on when to turn it on.
for turning it off, the trigger is a numeric state of entity when above 30 or Amber Price above XX

The other to turn on is when pool temp goes < 30 and price is below 0.20

The action for each is to turn on or off the switch you created.

In the triggers, I would add that the value needs to be at that value for say over 5 minutes to avoid turning on and on the HP all the time.

Edit: not working…I don’t see in the visual editor how to toggle the switch that I made…but I can just reuse the code as the YAML in the action section.

Problem is that Pool temp has to change for Automation to activate and despite polling every 35 second and the pool status entity updating, the current pool temp sensor derived from the status entity doesn’t seem to update unless there is a change. or it isn’t updating…can trigger the automation by changing the temp state manual…but isn’t working in auto.

These are the Automations I came up with

Turn On with Price During the Day - If needed (below 30)

- id: '1643966502976'
  alias: Pool Heater On
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.pool1_temperature
    below: '30'
  condition:
  - condition: numeric_state
    entity_id: sensor.durst_home_general_price
    below: '0.25'
  - condition: state
    entity_id: sensor.pool1_channels4_mode
    state: 'Off'
    for:
      minutes: 2
  - condition: time
    after: 08:00:00
    before: '21:00:00'
  action:
  - service: rest_command.poolaction
    data:
      action_code: 1
      device_number: 5
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: homeassistant.update_entity
    entity_id: sensor.pool_status
  mode: single

why doesn’t sensor.pool1_temperature update every 35 seconds, when sensor.pool_status does?

this seems critical in why my automation won’t work

If you rely on a change state every 30s you’re not going to go very far

For a start electricity wholesale prices are set per 30 minutes interval, it takes several minutes for a heat pump to ramp up.

If you are setting things to react under a 30s change of condition, you will very likely kill your HP in no time