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

Yep - I started playing with ‘multiscrape’ - it’s an enhancement to the standard scrape tool and needs to be added in separately eg via HACS - but the nice thing is it does one scrape of a page and pulls all the info out. I came against a roadblock trying to get the authentication side working to get past the initial page to then get to ConnectMyPool where all the good stuff is… so I’ll try again sometime soon.

Should be fine, actually. The rules are for reading the status info - it restricts that to once every 60 seconds unless you send a pool action command (such as turn pump on), in which case the restriction is removed for 5 minutes. In other words you can send a number of API action commands in a row without an issue. At some point I’d like to change things so after you send a command (or group of commands), it then requests an update on the status so the info on the gui changes almost instantly rather than waiting up to 2 minutes (or whatever you have set the timer to). If we did that, then could extend the timer to 5 mins or longer as it would only be needed to keep things in synch should/when things are changed via the physical control panel etc.

I only mention it because it had thrown me, and I remembered earlier you said:

If you have only the three channels then it probably would be:

[states.sensor.pool_status.attributes[“channels”][0] - is the pump
[states.sensor.pool_status.attributes[“channels”][1] - is the garden lights
[states.sensor.pool_status.attributes[“channels”][2] - is the patio lights.

Cheers

if you wanted to specify the channel number instead of channel object id in array you could use jsonpath to lookup by channel_number. Something like this

$.channels[?(@.channel_number == "1")]

Thanks - is fine. Once the penny dropped that it was the object id, all was good with the world. :wink:

So - continuing saga on getting pH info. Now trying multiscrape. The following I think is close to working, but I don’t think it’s authenticating correctly. Thought I should post it in case someone else has some time to give it a go.

multiscrape:
  - resource: 'https://connectmypool.com.au/Account/Chemistry.aspx'
    scan_interval: 60
#    authentication: digest
    form_submit:
      submit_once: True
      resource: 'https://connectmypool.com.au/Front/Login.aspx'
      select: "#ucLogin1_txtUserName"
      input:
        username: username-here
        password: 'password-here'
#        extra: field
    sensor:
      - select: "#lblPHMeasure"
        name: multiscrape-pH1
#        value_template: "{{value}}"
      - select: '#lblORPMeasure'
        name: multiscrape-ORP
      - select: '#lblORPSetPoint'
        name: multiscrape-ORPset
      - select: '#lblPHLast'
        name: multiscrape-LastUpdate

I think I found this “feature” tonight, all my off, on, auto setpoints have been configured in each automation for the input_select for the channels (i.e. Garden and patio lights) but if turn a channel on and later change to auto I might get off or auto. If I have it “on” and set it “on” it might turn it “off” as a result. So I make a change in HA and watch the result on the connectmypool app.
Is that what you were trying to explain above?

I created favorites on the viron today
I have one called “all lights” for the pool lights, garden and patio lights.
But I didn’t select the pool pump. So when you activate it, that favorite it will turn the lights on but even though the filter is on auto it will turn it off.
I have another called “aux lights” with just the garden and patio lights with the same issue it turns off the non selected channel in the favorite.

I don’t mind as the lights will only be called to go on at night and I only run the pump during the day (1. because the solar panels help cover the cost and 2. so the neighbours don’t complain about the sound at the night)

Looking at the options for favourites it looks like it only have one option “on”

So I’m going to figure out how to have scenes that call the “aux light” or “all lights” function and when I want to turn them off it actually calls the “all auto” function to reset them, which would then turn the filter pump from off to auto and run the timer again in the morning.

Just wanted to confirm
In the json-attributes should there be a
– favourites.

thanks again.

OK so I chose to put the 0, 2 and 3 as it aligned with my json channel output.
I guessing it an array.
I think channel 1 is for my solar pump or solar controller - why my pool builder went for a separate system but powered by the viron is a mystery for another time. I wouldn’t mind looking into moving that over and get the temp and heating components working but that’s now way off topic.

So unless that gap [1] is causing the template error In HA logs, then I’m still at a loss to understand the error. The development tool looks fine and I can change the channel attributes to “on” “off” and “auto” and its updates to what’s expected.

thanks again for responding and providing feedback on this.

Pretty much. Think of it as a momentary switch, and every time you press it (either via the physical control panel or by activating a switch you create in HA) it simply cycles to the next available setting for the device that is on that channel.

Yeah - another gotcha for the favourite. It appears to assume anything you don’t enable in a favourite should be turned off. In theory it should be possible to create a script that:

  • you call to change a device on a channel to a specific state; then
  • checks what the status is for the device; if it matches the desired state then quit otherwise
  • cycles the channel to the next state; then
  • checks what the status is for a device; if it matches the desired state then quit otherwise rinse & repeat

That way you could have a switch that changes a device on a channel to a specific state no matter what it is currently set to. Kinda ugly, and not quick (would need to include a delay between commands), but might be the best we can do with the current API.

Good idea is to be certain. Again, just go to the developer tools in Lovelace, and check the state of ‘sensor.pool_status’. You should see the list of available channels in the state attributes. With the controller/connectmypool app turn things on/off and you should see the mode attribute change for each channel so you can in turn confirm exactly which is which.

…and finally, another reason for this sort of error would be a typo. Make sure that your yaml is correctly formatted (sometimes it will pass the automatic check, but not be right), and that the names for the sensors are correct - in my code I used “sensor.pool1_channel” not “sensor.pool_channel” so if you’ve changed that to singular just make sure you did that everywhere…

Cheers

Thanks again for the detailed responses

Here is the pool status dev tool results

pool_spa_selection: 1
heat_cool_selection: 1
temperature: 0
active_favourite: 255
heaters: []
solar_systems: []
channels:
  - channel_number: 0
    mode: 1
  - channel_number: 2
    mode: 1
  - channel_number: 3
    mode: 0
valves: []
lighting_zones:
  - lighting_zone_number: 0
    mode: 1
    color: 10
friendly_name: Pool Status

So channels 2 and 3 do update in the dev tools when changes are made in the app.
The odd thing is if I look at the sensor.pool_channels2_mode its set to Auto.
If I look at sensor.pool_channels3_mode is unavailable so it looks like its something to do with that.
I’ll keep scratching around. its got to be something simple.
I’ve noted I changed the Pool1 to pool so will double check that.

thanks again

Yep. The numbering is based on object id, so based on what you noted above:

you would have:

[states.sensor.pool_status.attributes[“channels”][0] # which is channel 0
[states.sensor.pool_status.attributes[“channels”][1] # which is channel 2
[states.sensor.pool_status.attributes[“channels”][2] # which is channel 3

So with your current code

when you’ve been changing what you though was channel 2, you were actually changing channel 3, and when you were trying to change channel 3 with your code you couldn’t because it didn’t exist, but it would change in dev tools when changed via the controller… :wink:

I had channels [] 0, 2, 3. As I thought that lined up with the json numbering. Then after your last post I went channels [] 0, 1, 3.
I meant to write 0,1,2 but missed it. Then last night after my post I looked at it again and :man_facepalming:. So updated to channels [] 0,1,2 and restarted and the errors stayed away.

Untill this morning but I have another error before it that makes. The error is that the API call is timing out every so often and that has a knock on effect. That’s no way an issue with the code, it’s not the only cloud service that is timing out around the same time.

My new ISP might be cheaper but I’m finding a few quirks with their upstream routing.

So onward and upward.

I want to look at the favourite stuff next and see if it can short circuit the circular nature of the channel select.

Do you know if I have to add - favorites to the Json attributes?

Again thanks for your help on this.

Check out the previous messages in this thread, in particular the one showing how I did:

input_select.pool_set_fave

etc - basically I use input select to choose from a list of various favourites. That is then translated via automations to send the rest command that matches the number for the favourite you want to execute.

I had a similar requirement for my cameras (PTZ presets) instead of creating automations I used lovelace buttons - initially with a single button that uses the input_select dropdown to select a number before pressing the button.

Then i changed to individual buttons as I only had 4-5 preset PTZ camera locations

Lovelace code for a button would be something like

type: button
tap_action:
  action: call-service
  service: rest_command.poolaction
  service_data:
    action_code: 8
    device_number: 255
  target: {}
name: All On
icon: mdi:pool

type: button
tap_action:
  action: call-service
  service: rest_command.poolaction
  service_data:
    action_code: 8
    device_number: 128
  target: {}
name: All Off
icon: mdi:pool

## or with input select I created a momentary switch to call the rest action
type: button
tap_action:
  action: call-service
  service: switch.poolaction
  service_data:
  target: {}
name: Submit
icon: mdi:pool

switch was something like

  - platform: template
    switches:
      poolaction:
        value_template: > 
          {% if is_state('switch.poolaction','on') %} # think theres a better way to do this
            off
          {% endif %}
        unique_id: 232343cb7e79-84dfdfdfad18f79
        friendly_name: Pool Favs
        turn_on:
           service: rest_command.poolaction
           data: 
              action_code: 8
              device_number: {{ states('input_select.poolfav') }}
        turn_off:

So I am still having trouble activating my jets because they are on channels rather than Valves. So the On/Off/Auto drop down does not work.

Does anyone have any suggestions on how I can get this to work in HA? Is there a script that can be written so when I select ‘On’ in the state dropdown it sends a command to toggle until it find on?

If not, perhaps there is a button that can be clicked that will show the three states and reply with the current state?

I no longer have access to my brothers login to test but reading above and looking at documentation, seems like channels can’t be set but rather you can cycle through channel modes or use favourites.

Using a lovelace button ) Insert ‘Manual’ and paste code below you might be able to use this button to cycle modes and have a button per channel to cycle by changing the device_number: for each channel

type: button
tap_action:
  action: call-service
  service: rest_command.poolaction
  service_data:
    action_code: 1
    device_number: 1
  target: {}
name: Jet 1 - Cycle Mode
icon: mdi:water-plus

or could use an input select in lovelace alongside the button

type: button
tap_action:
  action: call-service
  service: rest_command.poolaction
  service_data:
    action_code: 1
    device_number: {{ states('input_select.channelnumber') }}
  target: {}
name: Channel Mode - Cycle
icon: mdi:reload

Could go a step further but will require you to add a sensor for each channel and then potentially show the status in the ‘name’ in above to include {{ states(‘sensor.pool1_channels0_mode’) }}

e.g.

type: button
tap_action:
  action: call-service
  service: rest_command.poolaction
  service_data:
    action_code: 1
    device_number: 1
  target: {}
name: "Channel Jet 1 - ({{ states('sensor.pool1_channels0_mode') }})"
icon: mdi:water-plus

e.g. for adding a new channel per sensor - keeping in mind the number between [] e.g. [0] or [1] is the array index ID and not the channel number

      pool1_channels0_mode:
         friendly_name: Pool - Channel 0 Mode
         value_template:   >-
           {{ ['Off', 'Auto', 'On', 'Low Speed', 'Medium Speed', 'High Speed'][states.sensor.pool_status.attributes["channels"][0]["mode"]|int] }}
      pool1_channels1_mode:
         friendly_name: Pool - Channel 1 Mode
         value_template:   >-
           {{ ['Off', 'Auto', 'On', 'Low Speed', 'Medium Speed', 'High Speed'][states.sensor.pool_status.attributes["channels"][1]["mode"]|int] }}

Rather than using array ID you might be able to use channel id in sensor by changing to something like

      pool1_channels0_mode:
         friendly_name: Pool - Channel 1 Mode
         value_template:   >-
           {{ ['Off', 'Auto', 'On', 'Low Speed', 'Medium Speed', 'High Speed'][states.sensor.pool_status.attributes.channels[?(@.channel_number == "1")]["mode"]|int] }}
      pool1_channels1_mode:
         friendly_name: Pool - Channel 2 Mode
         value_template:   >-
           {{ ['Off', 'Auto', 'On', 'Low Speed', 'Medium Speed', 'High Speed'][states.sensor.pool_status.attributes.channels[?(@.channel_number == "2")]["mode"]|int] }}

EDIT: Thinking about the above some more there might be a 30-60 second delay between showing the channel status 'e.g. Low Speed after pressing it though this line from the manual sounds promising Note after an instruction has been sent all API calls are not time throttled for a period of 5 minutes. If I understand that correctly when a poolaction is sent none of the API are throttled for 5 minutes so you could add an update sensor on press like under the switch examples at the top of the thread, e.g. (if tap action buttons support it, add):

  - service: homeassistant.update_entity
    entity_id: sensor.pool_status

What would be ideal is to call the above (homeassistant.update_entity for sensor.pool_status) every time rest_command.poolaction is called. I believe a HA script would allow you to do this and then call the script which calls the restcommand and update… or using a switch: for channel like (valves and heaters) which is probably the simplest but make it momentary e.g. put this in your switch.yaml file or in configuration.yaml under switch: (where you valve, heater and light switchers are):

#########################################
####### ASTRAL POOL CHANNEL1 TOGGLE #####
#########################################
  - platform: template
    switches:
      pool_channel1:
        value_template: > 
          {% if is_state('switch.pool_channel1','on') %}
            off
          {% endif %}
        unique_id: 81343ccd1e79-82ccsds2ae276
        friendly_name: "Channel 1 (Jets) - {{ states('sensor.pool1_channels0_mode') }}"
        turn_on:
         - service: rest_command.poolaction
           data: 
             action_code: 1
             device_number: 1
         - delay: 1
         - service: homeassistant.update_entity
           entity_id: sensor.pool_status
        turn_off:

PS> As mentioned above, this is untested as I no longer have access to the connectmypool.com.au portal

Just realised you can’t use a variable like {{ states('sensor.pool1_channels0_mode') }} in the friendly_name: :frowning: :frowning: I think you could create a HA lovelace sensor button instead that shows the state of the sensor and calls the service switch.turn_on for the switch created above which includes the update_entity - I’ve shared this with my bro to test

type: button
tap_action:
  action: call-service
  service: switch.turn_on
  service_data: {}
  target:
    entity_id: switch.pool_channel1
entity: sensor.pool1_channels0_mode
show_state: true

UPDATE: my brother confirmed this is working with a small delay 2-4 seconds. Could try removing the - delay: 1

One thing that I have noticed in regards to setting a specific state on the Channels - when you switch between ‘POOL’ and ‘SPA’ mode, the Viron10 sets the states instantly without needing to press any buttons, so that means it is technically possible to execute an automation or set a state on a channel.

Has anyone else noticed this? When I click pool, the jets set from OFF to ON, the Lights come on, the Heater turns on and the Pool Filter pump sets to HIGH.

When I click Auto again, everything goes back to Auto.

Is it possible its using a favourite? My brother did say when he cycles through channel for Filter Pump it stops heating when it moves to ‘Off’

Yes, this is what mine does as well.
Pool mode is based on favorite 1 and Spa mode is favorite 2 from what I have found.

When I switch to spa mode, it starts the spa jets and turn the heater on. My issue is that when I change back to pool mode, it either turns everything off, or starts the filter pump depending on how Favorite 1 is set. Seems to be the same as what you are saying. Would like Pool mode to return to “All Auto”

I am still waiting for my API Key.

I am also thinking of using the 2 customisable switch’s, I am thinking of connecting a Wemos D1 running ESPHome using 2 relays, I could then use this to activate these to activate the 'All Auto" once back in pool mode. Unless these is a way to do this with the API.

Hi all,
I’ve just about got everything I wanted working by using favourites for everything.

I’m trying to see if there is a way with the “pool lights” button card can I do a hold_action to then call up the input select for the colour options.

        - type: button
          tap_action:
            action: call-service
            service: rest_command.poolaction
            service_data:
              action_code: 8
              device_number: 4
            target: {}
          hold_action:
            action: call-service
            service: input_select.select_option
            service_data: input_select.pool_light_colour
          name: Pool Lights

my pool light options are;

 pool_light_colour:
    name: Pool Lights Colour
    options:
      - "Red"
      - "Orange"
      - "Green"
      - "Blue"
      - "White"
      - "Magenta"
      - "Cyan"
      - "Disco"
      - "Rainbow"
      - "Ocean"

I’m guessing its target function but I have no idea on the syntax for that.
If I’m way off and it can’t be done, I’ll break it back out to two cards.

thanks again for for your help

Wow that’s great on HA. I gather I need the Connect 10 Internet Gateway. About $580 right?

BTW given HA runs locally - can you connect directly to the connect 10 gateway device rather than having to go via the connectmypool.com.au - surely it would be much more responsive being locally connected. I gather @smck83 @remsta you’ve investigated this previously… anyway very cool.