Skip to content

Instantly share code, notes, and snippets.

@M0LTE
Last active July 8, 2024 18:29
Show Gist options
  • Save M0LTE/c13177c2a1784f86016c21040c5ee7d1 to your computer and use it in GitHub Desktop.
Save M0LTE/c13177c2a1784f86016c21040c5ee7d1 to your computer and use it in GitHub Desktop.
Thames Water smart meter consumption data

Goal

Read water consumption data from my Thames Water meter, so that I can feed it into Home Assistant, my smart home system of choice, for consumption monitoring.

Approaches

Read it via RF

This is most desirable; it's already smart.

However, this is not possible, it's encrypted and the keys aren't publicly available.

Read it via an API

There is an open data portal here: https://data.thameswater.co.uk/ but it's nothing to do with domestic water consumption, so is not relevant to this effort.

Read it via the website

Three-day old hourly data is available via the website (login -> my water use).

Consumption data is picked up for display by the UI from the following endpoint:

https://myaccount.thameswater.co.uk/ajax/waterMeter/getSmartWaterMeterConsumptions

A minimal working request to this is as follows:

curl "https://myaccount.thameswater.co.uk/ajax/waterMeter/getSmartWaterMeterConsumptions?meter=METER_ID_HERE&startDate=05&startMonth=07&startYear=2024&endDate=05&endMonth=07&endYear=2024&granularity=H&premiseId=&isForC4C=false" \
  -H "cookie: b2cAuthenticated=true; JSESSIONID=xxx; OAUTH=xxx; LoggedIntoMyAccount=1" \
  -H "referer: https://myaccount.thameswater.co.uk/mydashboard/my-meters-usage" \
  -H "x-requested-with: XMLHttpRequest"

More cookies than that are set, but only those four are required. The referer and x-requested-with headers are also required.

Obtaining the values for JSESSIONID and OAUTH is non-trivial- the flow between the login screen and the server returning either of those cookies is quite indirect and messy.

I have made a small start; the login form POSTs to https://login.thameswater.co.uk/identity.thameswater.co.uk/B2C_1_tw_website_signin/SelfAsserted?tx=StateProperties=SOMEVALUE&p=B2C_1_tw_website_signin with data request_type=RESPONSE&email=YOUR_ACCOUNT_EMAIL&password=YOUR_PASSWORD, and the server does a 302 redirect into the flow which results in those cookies being set.

Alternative approach

Install a secondary water meter which I own and control.

Plea

This situation stinks.

Thames Water, if you are reading this, please give consumers some way to read their own smart water meter consumption data preferably by adding a documented way of getting domestic water consumption data to your open data portal (https://data.thameswater.co.uk). We shouldn't have to jump through these hoops in this day and age.

Prior art

A thread here: https://community.home-assistant.io/t/thames-water-data/497603; nothing conclusive

Looks like someone did a Selenium-based scraper: https://github.com/papadeltasierra/thameswater - it clicks buttons and outputs to a CSV file - not quite what we're after but might be a useful start

This scraper is not relevant since it's just about the discharges API: https://github.com/mossc001/Thames_Water_API_to_Home_Assistant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment