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

I think the issue is - Let's Encrypt's Root Certificate is expiring!

Quick fix should be to disable verify_ssl

e.g.

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": "XXXXXX-1234567","action_code": {{action_code}},"device_number": {{device_number}},"value": "{{value}}","wait_for_execution": false}'
    verify_ssl: false # INSTEAD OF TRUE

In terms of resolution, how frequently does HA update its certificate CA store? and are you running the latest version of HA?

Yep, and the CA store probably gets updated along with everything else depending on the host you are running HA on - but in this case it would not make a difference. Personally I’m running the latest stable versions of everything, but if you check out the certificate being provided by the server it is valid up to 31 Dec, but the intermediate certificate has expired (Expired: Thursday, 30 September 2021 at 5:21:40 am Australian Eastern Standard Time), and the root certificate for that is going to die just after midnight (Expires: Friday, 1 October 2021 at 12:01:15 am Australian Eastern Standard Time). Again, Fabtronics just need to update the certificate on their server. Good suggestion re disabling ssl, and maybe I might do that if they don’t resolve this quickly, but I’m a paranoid little duck so I’ll leave it for now.

Just started working for my brothers, maybe they renewed?. Cert says from 29th Sept '21

Yay. Yes, I think that Let’s Encrypt has extended the validity of the intermediate and root certificates.

Hi All, I have been following along with this for a little bit and I have to say that this is fantastic and all the hard work has mostly been done. I have discovered that inside the box of the controller there is 2 button inputs. One can be setup to recall a favorite that can be setup via the touchscreen and the other defaults back to the “All Auto” mode. It would be nicer if you could decide what these buttons do but they are fixed at these functions and apparently can not be set as a toggle function, so button one will always recall favorite 1 rather than toggle it on and off. Anyway I was most likely going to add something like a D1 Mini to it so I can activate those 2 settings alongside the excellent work already done in this thread. Just thought I would pass this info on if you were not already aware.

Cheers.

Hi Mark. Yep, definitely possible and in fact before I started mucking around with the API I had already done that and yes I also used a D1 mini (with a two channel relay) and esphome. I just plugged a usb charger into one of the continuous power sockets, and put the mini with dual relay into a small jiffy box I had lying around (most likely from Jaycar). Things to note:

  • although the connectors you need to hook up to are not dangerous, there is 240V in there, so highly recommended to turn the power off before removing the front plate
  • the box I used provides some protection from bugs etc, and of course it is protected inside the controller box, but an IP65 box or similar might be better
  • I intentionally installed a wifi AP at the back of the house so coverage for me is really good - but you might want to check that first before bothering
  • I needed to use an 800ms delay when toggling the switches
  • now that I can control the pool via the API, including activating any ‘favourite’ I want, I probably won’t bother using this feature although it was a fun project… it is perhaps a little quicker to activate using this rather than via the api, but not significantly

    The cables actually were actually left in a horrible mess by our sparky when installing - I’ve sorted them a bit but tidying them up properly is on my list of things to do eventually!

FWIW Here’s my code:

# Control pool settings
switch:
  - platform: gpio
    pin:
      number: D7
    id: relay1
    name: "Favourite"
    icon: "mdi:pool"
    on_turn_on:
    - delay: 800ms
    - switch.turn_off: relay1
    interlock: [relay2] 
  - platform: gpio
    pin:
      number: D6
    id: relay2
    name: "All Auto"
    icon: "mdi:pool"
    on_turn_on:
    - delay: 800ms
    - switch.turn_off: relay2
    interlock: [relay1] 

Thank you so much for this.
Its taken 18 months but finally something good has come out of lockdown. :grinning:

I got the functions for the lights (Pool, garden and Patio) working from the viron into HA.
I’ll do the pump in the morning but I’m ok if that stays with the viron as its set and forget.
I’m happy to be able to retire another app.

I’ve started to play with getting the scrape pool health stats using the parsehub I’ve got the scrape working and my json results are

{
“ORPstatus”: [
{
“name”: “ORP Status:”
},
{
“name”: “OK\n4 hours 28 minutes ago”
}
],
“phLevel”: [
{
“name”: “Ph Level:”
},
{
“name”: “7.5\n4 hours 35 minutes ago”
}
],
“ORPsetPoint”: [
{
“name”: “ORP Set Point:”
},
{
“name”: “750”
}
]
}

How were you able to select the pH, and ORP details without it taking the last updated part with it. ?

With the curl command are you able to help me by breaking down the [magic stuff]
I’m assuming one is the parsehub api, another would be the project api id but I’m not sure if that’s right.

Final question I only have the channels (i.e pump, pool lights, and the custom garden lights and patio lights.)

My adaption of the code looks like this in the template sensors.
[states.sensor.pool_status.attributes[“channels”][0] - is the pump
[states.sensor.pool_status.attributes[“channels”][2] - is the garden lights
[states.sensor.pool_status.attributes[“channels”][3] - is the patio lights.

I’m not sure if I should have changed the values of the channels to line up with the channel. it seems to be working but i’m getting these logs entries.

  • emplateError(‘UndefinedError: ‘mappingproxy object’ has no attribute ‘channels’’) while processing template ‘Template("{{ [‘Off’, ‘Auto’, ‘On’, ‘Low Speed’, ‘Medium Speed’, ‘High Speed’][states.sensor.pool_status.attributes[“channels”][0][“mode”]|int] }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.pool_channels0_mode’
  • TemplateError(‘UndefinedError: ‘mappingproxy object’ has no attribute ‘channels’’) while processing template ‘Template("{{ [‘Off’, ‘Auto’, ‘On’][states.sensor.pool_status.attributes[“channels”][0][“mode”]|int] }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.pool_channels2_mode’
  • TemplateError(‘UndefinedError: ‘mappingproxy object’ has no attribute ‘channels’’) while processing template ‘Template("{{ [‘Off’, ‘Auto’, ‘On’][states.sensor.pool_status.attributes[“channels”][2][“mode”]|int] }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.pool_channels3_mode’
  • TemplateError(‘UndefinedError: ‘mappingproxy object’ has no attribute ‘channels’’) while processing template ‘Template("{{ [‘Off’, ‘Auto’, ‘On’][states.sensor.pool_status.attributes[“channels”][2][“mode”]|int] }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.pool_channels2_mode’
  • TemplateError(‘UndefinedError: ‘mappingproxy object’ has no attribute ‘lighting_zones’’) while processing template ‘Template("{{ [‘Off’, ‘Auto’, ‘On’][states.sensor.pool_status.attributes[“lighting_zones”][0][“mode”]|int] }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.pool_light_status’

any advise would be greatly appreciated.

Thanks again for your hard work and efforts on this one.

I literally just selected the pH reading… I suspect that’s not of much help, but hey - it worked for me. :wink: Seriously though, the pH is “#lblPHMeasure” and the last update is “#lblPHLast”. I will note though that I’ve actually given up on parsehub - it was/is really great but I was finding that it would stop working randomly so the info would not update. I don’t know if it’s because I was using the free version or because it was a two step process (run the scrape command, then download the results), or for some other reason, but I thought rather than try to trace back the issue - now that I know it is possible to do it - to try to use the native scrape tools in HA. That’s where it currently is for me, just waiting for some time to actually spend on it… If you want to keep going with parsehub, feel free. With the curl command the first bunch of numbers is the project token - if you log on to the website and look at the project details it will show you what that is. The second is your api key - if you go into your account details, you’ll see that info.

Yep, at face value that looks right. Maybe go into developer tools in lovelace, and look at ‘sensor.pool’ to see the attributes to confirm the channel numbers are what you think they should be. You should have something like:

pool_spa_selection: 1
heat_cool_selection: 1
temperature: 18
active_favourite: 255
heaters:
  - heater_number: 1
    mode: 0
    set_temperature: 28
    spa_set_temperature: 0
solar_systems: []
channels:
  - channel_number: 0
    mode: 1
  - channel_number: 2
    mode: 0
  - channel_number: 3
    mode: 0
valves: []
lighting_zones:
  - lighting_zone_number: 0
    mode: 1
    color: 7
friendly_name: Pool Status

If all seems correct, then it might be a typo in the yaml code.

At this point I should make a full disclosure - I am happily controlling my filter pump (on channel 0) and booster pump (on channel 1), but my two swim jets on channels 6 and 7 currently won’t talk to me. Still trying to work that one out!

Cheers

Ah. Penny has dropped I think. I’ve worked out why I couldn’t control my jets, and it may be why you may be having issues. I have for example 4 channels. In the control box they are in 1,2, 7, and 8. This translates in the API to channels 0,1,6, and 7. eg:

channels:
  - channel_number: 0
    mode: 4
  - channel_number: 1
    mode: 0
  - channel_number: 6
    mode: 0
  - channel_number: 7
    mode: 0

In the YAML code though, the numbers are in sequential order based on how they appear. In other words I need to use:

[states.sensor.pool_status.attributes["channels"][0]["mode"]|int]
[states.sensor.pool_status.attributes["channels"][1]["mode"]|int]
[states.sensor.pool_status.attributes["channels"][2]["mode"]|int]
[states.sensor.pool_status.attributes["channels"][3]["mode"]|int]

Just a small gotcha. :wink:

Thanks for the follow up. I’ll check it out tonight. I think I’m ok because I don’t use the channels that far down. Its probably something simple.

As for the scrape tool I’ve started doing some reading on that myself. Can’t guarantee it will go anywhere. But the parsehub does feel clunky and another thing that might complicate the solution and troubleshooting in future. So looking for something in and around HA would hopefully help with troubleshooting.

I’ll get onto creating a favourite so I can create a one API call button for a scene to turn the garden and patio lights on and use the existing all auto and all off favorites to return it back. I figured individual calls for each channel will take time due to the API call rules.

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.