Integrating Anglia water usage for smart meters (UK)

THanks @yatik I can confirm that it now pulls in yesterday’s usage, great work!


Thanks for all this folks, really appreciate the work. Getting this in the log for starting the app.


If uncomment the force reading at the top of the script i get this

I have just updated the script but i’m getting the following error:

2024-02-17 20:47:05.212075 INFO WaterUsage: Request Login
2024-02-17 20:47:05.226017 INFO WaterUsage: Request Error: Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[id=“email”]”}
(Session info: chrome-headless-shell=121.0.6167.184); For documentation on this error, please visit: Understanding Common Errors | Selenium

2024-02-17 20:47:05.294652 INFO WaterUsage: Usage: 0.0

Any ideas?

If you are running on a raspberry pi / something slower / busy Home Assistant, then increase the time.sleep(x) → to something like 10-15 seconds.

Try logging into Anglian Water website, make sure there is a reading for yesterday (daily usage).
Also, you can change the execution time but Anglian water only seem to post updates for yesterday between 8-11pm.

Thank you @yatik. I’m using running in Promox on an i7 so resources are not an issue. which time.sleep do you recommend adjusting?

Increase them all by 2-3 seconds, it could be other factors… also check internet connection as all the script does is scrape the Website for data.
The other reason (weekend just gone 17-18 Feb), Anglian water were doing an upgrade.

Hi, so i can login and see details on the web site.
Readings are from 19th Feb to yesterday.
I was obviously a bit early for adding the integration.
When trying to add to the energy dashboard, i get the No Matching Statistics Found.
And un commenting the force_reading i get the image first posted about input_boolean.water_reading not found in namespace default.

If i comment it out again i get the nameError: name force_reading is not defined. If i comment the FORCED Callback section out, i have to comment out the self.listen_state as well.



Screenshot 2024-02-26 at 14.24.55
but

This is what i get trying to add the water to Energy dashboard

also getting this in the logs

2024-02-26 19:02:00.023189 INFO WaterUsage: starting process
2024-02-26 19:02:00.032045 INFO WaterUsage: starting request
2024-02-26 19:02:06.735279 INFO WaterUsage: Request Home page
2024-02-26 19:02:51.346501 INFO WaterUsage: Requested Home Page
2024-02-26 19:03:13.742273 INFO WaterUsage: Request Login
2024-02-26 19:03:26.887964 INFO WaterUsage: Login
2024-02-26 19:03:50.002040 INFO WaterUsage: Request Usage
2024-02-26 19:03:51.046865 INFO WaterUsage: Request Error: list index out of range
2024-02-26 19:03:51.424048 INFO WaterUsage: Usage: 411
2024-02-26 19:03:51.762079 WARNING AppDaemon: Excessive time spent in callback 'StartProcess() in WaterUsage', Thread 'thread.thread-1' - now complete after 111.759528 seconds (limit=80.0)

Ok, i appear to have it working.
When manually changing the time it runs to daytime for setting up.
curdt = (date.today() - timedelta(days=2)).strftime("%d-%b-%Y")
Also, i noticed when the sensor is created it is not always to sensor.water_usage_x as per the configuration file.
In my case it created the template (viewable under entities) as sensor.water_usage_3 which you need to put in the python file and helper. I was looking for _x and couldnt work out why it wasnt there.
The only issue i have now is statistics, but i guess i have to wait a few days or something.


I keep getting this message in the logs, anybody know how to get rid of the warning?

2024-03-05 21:56:00.274822 INFO AppDaemon: Loading app WaterUsage using class GetWaterUsage from module GetWaterUsage
2024-03-05 21:56:00.276621 INFO AppDaemon: Calling initialize() for WaterUsage
2024-03-05 21:56:00.346341 INFO WaterUsage: Starting Water Usage App
2024-03-05 21:56:00.350462 WARNING WaterUsage: WaterUsage: Entity input_boolean.water_reading not found in namespace default
2024-03-05 21:56:00.352155 INFO AppDaemon: App initialization complete

I have removed my old settings as could not get this working. Then I have re set it up with the new code as updated.
My logs keep showing the same error.

2024-03-06 17:55:56.886765 INFO AppDaemon: Calling initialize() for WaterUsage
2024-03-06 17:55:56.893018 INFO WaterUsage: Starting Water Usage App
2024-03-06 17:55:56.908367 WARNING WaterUsage: ------------------------------------------------------------
2024-03-06 17:55:56.909133 WARNING WaterUsage: Unexpected error running initialize() for WaterUsage
2024-03-06 17:55:56.909548 WARNING WaterUsage: ------------------------------------------------------------
2024-03-06 17:55:56.912497 WARNING WaterUsage: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/app_management.py", line 162, in initialize_app
    await utils.run_in_executor(self, init)
  File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 304, in run_in_executor
    response = future.result()
               ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/apps/GetWaterUsage.py", line 40, in initialize
    self.listen_state(self.StartProcessForced,force_reading, attribute="state", new="on", duration=10 )
                                              ^^^^^^^^^^^^^
NameError: name 'force_reading' is not defined

2024-03-06 17:55:56.917026 WARNING WaterUsage: ------------------------------------------------------------

configuration.yaml has this under template:

  - sensor:
      - name: "Water usage"
        unique_id: water_usage_x
        icon: mdi:water
        state: "0.0"

apps.yaml

hello_world:
  module: hello
  class: HelloWorld
WaterUsage:
  module: GetWaterUsage
  class: GetWaterUsage

getwaterusage.py has my details that I can log in to anglian water with and “usage sensor=sensor.water_usage_x”


Any help with this would be appreciated as I have been going around in circles.

Probably uncomment the force_reading variable at the top of the script. (remove # in front of it)

Thank you, I had previously tried this with no luck so reverted back. Turns out the last time I logged in to Anglian Water’s website was before their change and I needed to agree to their terms. After that, all now working!

I have now got this working correctly for the Daily meter reading. I see some have tried to get it working hourly which i would like to try to. However, my knowledge on these integrations is not great.

Is this still working for anyone as i have trying for 3 days now and i just get an error stating it cant find the element “log in”

Ran into an issue running the script through appdaemon (even though it work the first time) but managed to resolve it so figured id post hear in case it can help others.

log error:

2024-04-07 19:11:48.399377 WARNING WaterUsage: ------------------------------------------------------------
2024-04-07 19:11:48.399809 WARNING WaterUsage: Unexpected error in worker for App WaterUsage:
2024-04-07 19:11:48.399965 WARNING WaterUsage: Worker Ags: {'id': '790bb3eccec04f2c95e0aaa260e33aed', 'name': 'WaterUsage', 'objectid': '66772e6935d54c1f85e0b13c157cbe66', 'type': 'state', 'function': <bound method GetWaterUsage.StartProcessForced of <GetWaterUsage.GetWaterUsage object at 0x7f556b048050>>, 'attribute': 'state', 'entity': 'input_boolean.water_reading', 'new_state': 'on', 'old_state': 'off', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'__entity': 'input_boolean.water_reading', '__attribute': 'state', '__old_state': 'off', '__new_state': 'on', 'attribute': 'state', 'new': 'on', 'duration': 10, '__thread_id': 'thread-1'}}
2024-04-07 19:11:48.400117 WARNING WaterUsage: ------------------------------------------------------------
2024-04-07 19:11:48.400747 WARNING WaterUsage: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1045, in worker
    funcref(
  File "/config/apps/GetWaterUsage.py", line 57, in StartProcessForced
    self.log("Usage: " + usage)
             ~~~~~~~~~~^~~~~~~
TypeError: can only concatenate str (not "int") to str

2024-04-07 19:11:48.400882 WARNING WaterUsage: ------------------------------------------------------------

managed to resolve the issue by making sure usage was defined as a string before concat on lines 46 & 57 using str():

  #Callback Function to Start the process 
  def StartProcess(self, kwargs):
    self.log("starting process")
    usage = self.GetUsage()
    self.log("Usage: " + str(usage))
    try:
      self.set_state(usagesensor, state = usage)
    except Exception as e:
      self.log("Set Sensor State Error: " + str(e))

  #FORCED Callback Function to Start the process 
  def StartProcessForced(self, entity, attribute, old, new, kwargs):
    self.log("starting process")
    self.turn_off(force_reading)
    usage = self.GetUsage()
    self.log("Usage: " + str(usage))
    try:
      self.set_state(usagesensor, state = usage)
    except Exception as e:
      self.log("Set Sensor State Error: " + str(e))

still have not managed to get the entity to be readable on the energy dashboard yet however but have not spent much time looking into the issue.

Very very early stages as I still need to understand how to register a device with Anglian Water, but:

image

Repo: GitHub - pantherale0/haanglianwater: Home Assistant integration for Anglian Water

Device ID is supposed to be a random 8 byte hex string, which for the most part works, however I need to be able to perform a registration request before the API will allow me to retrieve data from the usage endpoint.

EDIT: Device registration is working, leave the Device ID field blank when setting up the integration, it will also import historical usage into a statistic for you to use in the energy dashboard :slight_smile:

5 Likes

nice1 at @11harveyj but when I do let it empty I get an error
image

this is version 2024.4.0a1

if I add a key manually I get