Integrating an Anglia Water smart water meter

I live in the East of England and have a smart water meter from Anglian Water. Their website is great, and produces lovely charts of hourly usage, but there’s no API.

This short python script scrapes the website and logs the data into influxDB. Best to setup HA to run it say 9am every morning - if the terminal output is “Done!” then everything worked.

So this is a bit niche, but hopefully useful to somebody!

4 Likes

Ha, brilliant, there was no way I thought someone else would have already worked this out! Will give it a go, thanks!

It did start to look to see what tech they used, must be a mesh network of some sort, but couldn’t find much. I’m in Norwich, how about you?

If I had a pound for each person who also thought of integrating Anglian Water readings, I’d have two pounds, which doesn’t sound like much but it’s weird that it happened twice!

But seriously, I’m glad I’m not the only person to have thought about this, and will certainly be giving this a shot! Thanks!

3 Likes

The system looks like its Sensus Flexnet (from an old trial article)

I am guessing it runs in the 800Mhz band somewhere…

2 Likes

Has anyone set this up? i have just had a water smart meter setup and would like to monitor the usage in HA…

Is there a guide for this?

TIA

Anglian Water have just installed my smart meter, I can see hourly data in their app.
So hoping someone with coding skills is able to implement a HACS version of the above.

Can the SCRAPE sensor for home assistant be utilised in anyway with this?

2 Likes

This looks good but I’ll have to look at the install step by step. Funnily AW sent me an email today that I may have a leak - though it looks like a meter error that an alert in HA could have spotted earlier I wonder ??

Is * python packages: Selenium and influxdv - so ‘python3 -m pip install selenium InfluxDB-Python’ a terminal command ?

I sniffed the API calls of the Anglian water android app.
Login:

POST "https://my.anglianwater.co.uk/mobile/api/Login"
{
	"UserName": "",
	"Password": "",
	"RememberMe": true,
	"DeviceId": "4df1d021f752ff22"
}

And to get the hourly readings:

POST https://my.anglianwater.co.uk/mobile/api/GetMyUsagesDetailsFromAWBI
Headers:
Authorization AUTHTOKEN FROM LOGIN
{
	"SelectedStartDate": "10\/04\/2023",
	"SelectedEndDate": "12\/04\/2023",
	"ActualAccountNo": "",
	"PrimaryBPNumber": "",
	"EmailAddress": "",
	"ReadGranularity": "20",
	"OccupierCount": 2,
	"IsHomeComparision": false
}

and to refresh the access token:

POST "https://my.anglianwater.co.uk/mobile/api/GetAuthenticationByRefreshToken"
for some reason it sends the auth header on the access token refresh
{
	"EmailId": "",
	"DeviceId": "4df1d021f752ff22",
	"RefreshToken": "",
	"Status": 1
}
2 Likes

If anyone needs more info from my sniffing session I can provide. I just wanted to put this up in case I don’t get around to doing anything with the info

1 Like

Nice. Just what I was looking for. Thanks!

I am not getting anywhere with this one, all the other POST commands work but this one in particular is returning ““Message”: “Forbidden”” any idea why?

See below actual curl command I have built to test this:

curl -XPOST -H 'Authorization: XXXXXXXXX' -H "Content-type: application/json" -d '{"SelectedStartDate": "29\/05\/2023", "SelectedEndDate": "31\/05\/2023", "ActualAccountNo": "0000000000", "PrimaryBPNumber": "0000000", "EmailAddress": "[email protected]", "ReadGranularity": "20", "OccupierCount": "2", "IsHomeComparision": "false"}' 'https://my.anglianwater.co.uk/mobile/api/GetMyUsagesDetailsFromAWBI'

Getting the same error, don’t have the ability to intercept the HTTPs requests on the app as I don’t have a rooted device and don’t won’t to mess about with certificates and emulators. Any help would be appreciated.

I did try looking at the website instead and was able to retrieve information from this. It’s weird because it’s JS code. You also need to pass cookies.

URL https://my.anglianwater.co.uk/ViewUsage/GetMyUsage

Body:

granularity: Daily
startDate: 11.05.2023
endDate: 07.06.2023
minDate: Wed Apr 26 2023 00:00:00 GMT+0100 (British Summer Time)↵
maxDate: Wed Jun 07 2023 00:00:00 GMT+0100 (British Summer Time)
days: 28
readGranularity: 20

Result:

var myUsageDetails_days = [
{
    'groupDate': '11-May-2023',
    'time': '23:00',
    'usage': 0.000,
    'meterSerialNumber': 'XXXXXXXXXX',
    'isSynthesised': false,
    'monthYear': 'May  2023',
    'isSkipRecord': false
},
{
    'groupDate': '12-May-2023',
    'time': '23:00',
    'usage': 0.000,
    'meterSerialNumber': 'XXXXXXXXXX',
    'isSynthesised': false,
    'monthYear': 'May  2023',
    'isSkipRecord': false
},
{
    'groupDate': '13-May-2023',
    'time': '23:00',
    'usage': 0.000,
    'meterSerialNumber': 'XXXXXXXXXX',
    'isSynthesised': false,
    'monthYear': 'May  2023',
    'isSkipRecord': false
},
{
    'groupDate': '14-May-2023',
    'time': '23:00',
    'usage': 0.000,
    'meterSerialNumber': 'XXXXXXXXXX',
    'isSynthesised': false,
    'monthYear': 'May  2023',
    'isSkipRecord': false
}]

I have also recently had an Anglican smart water meter installed. I’m super interested in getting this going if only to see how much water I am using in the garden over the summer!

@dan12345 python script looks to be the best option right now.

Is there any updates on this? For the script, I suppose that we’d need to be running HA on a docker or run the influxdb on another VM to be able to install Selenium chromedriver right?

I have HA OS on a raspberry pi and I did try the script option but no luck, I assume it’s because I don’t have Selenium installed.

Still no luck with the post commands either. It would be really great to integrate these readings on HA

1 Like

I knew I was in over my head at this point…

Try installing each separately (selenium and influxdb). I eventually installed it on my Windows just to try the script and had the same issue, but then did the pip install for each separately and it worked.

There’s also a few modifications you have to make to the script (apart from your account details) as previous “find element” commands have been deprecated, see below the relevant section I have updated (just copy the below to replace everything between “PrintDebug(“logging in”)” and “button.click()” under “PrintDebug(“selecting hourly”)”:

PrintDebug("logging in")
sbox = driver.find_element(By.ID,'existUser')
sbox.send_keys(anglia_username)

sbox = driver.find_element(By.ID,'existPass')

sbox.send_keys(anglia_password)

button = driver.find_element(By.ID,'existingLogIn')
button.click()


PrintDebug("Selecting usage")

button = driver.find_element(By.ID,'btnViewUsage')
button.click()

PrintDebug("selecting hourly")
button = driver.find_element("xpath", '//*[@id="dbserialnumber"]/div/div[1]/div[1]/label/span')
button.click()

Thanks for the suggestion @Zeunas. My implementation is on HA Blue and I’m still getting the same error with the InfluxDB install;

Try “python -m pip install influxdb” instead

Thanks. That seemed to do the trick finding the files, however, I am now worried I could break something else as there is a warning message suggesting I should install in a virtual environment :thinking:

Ufff I really don’t know. I’d say you’d be safer to do it on VM. I did it on my windows PC as I open it everyday and the py file can run every time I start the PC, so it’s not like having an allocated VM just for that script.