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

Trying hard to avoid sounding like ‘Clippy’, it looks like you are trying to change a device on a channel to a specific state. The issue, if anything here, is understanding that with anything on a channel the api allows you to cycle through the available states one at a time - not choose a specific state. In other words you can’t tell your spa blower to turn off, you have to send the ‘action number’ of 1, with the device number matching the channel you want to change, until the device is at the state you want. Seems insane I know, but it’s pretty ancient technology. If you get onto their website, or the touch screen if you have one, you will see that there is just a button marked “change” next to the devices you can control, but the power on/off button does nothing.

You do have the ability to fire up a favourite, as well as “all on” or “all off” or “all auto” (so I suspect that ability to directly control channels is there for the Viron, just not exposed in the api) but individually the devices on channels can’t be set to to something directly via the api. Kind of annoying, but that’s life!

It is of course possible that with a bit of coding you could create an automation that sends the cycle code, checks if the device is at the desired state, and just keeps going until it hits the desired state. Possible, but I wouldn’t do it - at least not without some sort of timer failsafe - as there is a risk it might go into a loop.

Oh well that would explain everything - wow that is terrible!

At this stage, I actually have no idea what Auto even does - I have not tried to set a time on the touch screen, so maybe it does that. But Auto on the Spa does nothing since there is no Auto for the spa, the blowers are either on or off… so it seems I. need to do what you say, cycle the states.

It works perfectly with the fountain “On” “Off” “Auto”, since it is a Valve, not sure why there are not valves on everything…

So sending the action number of 1 to cycle through, is there a specific HA card that does that or just a button you need to keep clicking?

Yep, “Auto” should mean the device is controlled by the timer schedule you create - personally I have one that just turns the filter on in the morning at 9am then off again after a few hours.

I haven’t bothered creating one, and a number of options out there eg here, but if I did I’d probably just use something like:

        toggle_spa:
          - service: switch.toggle
            data:
              entity_id: switch.spa_channel

Can I ask how people have got the API key from AstralPool? I’ve requested it through the website several times and have received nothing.

Regards,

Jason

That is strange! I requested it and got it 2 days later…

But the servers seem to be down right now, we wanted to use the spa tonight and now can’t.

Shakes Fist

Dang - they are still down. I suspect the guys at Fabtronics are out of the office due to the lockdown. Even so, you should be able to operate the pool locally eg with the control panel physically connected to the Viron, the remote control if you have one, etc…

Note I followed them up with a phone call and got the API key without a day or two after that.

If anyone from Astral Pool ever read this and are looking for idea on how to improve their API. It would be much improved if they reported:

PH Level
PH Last Update Date/time
ORP Status
ORP Level (not just the OK/Low)
ORP Set Point
ORP Last Update Date/time
Channel Status (actually whether the pump is currently running - not just the mode it is set to - ie is it on when it is in Auto mode)

I’d also like to get alerts from my Chlorinator - not sure if Viron Connect even knows about these though as it doesn’t show them in the web page. eg. Low Salt or when it has turned off the pump because of no water.

Regards,

Jason

+1 from me.

As an aside, with the chlorinator, I think the Viron Connect controller knows more than is exposed in the API. For example, using the direct bluetooth control for the chlorinator, it can directly choose off/low/medium/high/auto ie it does not have to toggle through them one at a time. The interesting thing is that Viron Connect - when using timers or choosing ‘auto’ - can also set the speed directly rather than having to step through them one after the other. Another interesting thing is I discovered yesterday is that if I changed the ORP set point on the Viron control panel it changed the set point on the chlorinator. Now not sure if I’d need to change that setting frequently but then again it might be handy when, for example, the pool cover is left on for an extended period…

…also, it appears that connectmypool.com.au has been impacted by the expired root certificate from Let’s Encrypt. It’s now coming up with a security alert when using a browser, the app is dead in the water, as well as access via curl etc. Basically, they need to get a new ssl certificate for the server.

I’ve sent a message to Fabtronics, and will update here if I get any further info.

Cheers
[interesting side note - if you ignore the warnings and get onto the website, you will see that you can still control the pool equipment - which means that the comms between the viron connect and the backend server is either ignoring the certificate error or is not encrypted (neither of which would be good), or it is talking to a different server (possible, if unlikely). Maybe I should put a sniffer on it…]

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.