Just in case anyone is interested in integrating Anglia water usage from smart meters in Home assistant, I have created a step by step instruction below based on a script kindly shared by @dan12345 (thank you Dan!) on this post. Dan’s script uploads the usage onto InfluxDB but I removed that bit as I only wanted to ingrate it with Energy Dashboard. I have made some adjustments to the script on deprecated functions and also changed to only pull daily readings, although I am sure it can be easily configured to pull hourly readings as per initial script
Instructions
Create a usage sensor and a utility meter (to allow adding the data on the Energy Dashboard):
Usage sensor configuration under configuration.yaml (make sure you restart HA after adding the below)
As per my configuration on the above snapshot my utility sensor is ‘sensor.water_usage’, and so HA knows the device is a water sensor and assigns the correct unit please add the below to ‘customize.yaml’
sensor.water_usage_x:
state_class: total_increasing
sensor.water_usage:
device_class: water
unit_of_measurement: 'L'
Install Appdaemon Add-on (to run the script) and add the below Options under Configuration:
Start Appdaemon so it installs all dependencies and creates “appdaemon” folder under “/config”
[Optional] Once the “appdaemon” folder is created you should be able to see the file /config/appdaemon/appdaemon.yaml. Make sure you add thread_duration_warning_threshold: 80 under appdaemon: as per below example:
Create a .py file with this name “GetWaterUsage.py” under the folder /config/appdaemon/apps
Copy script by @yatik into the same file (make sure you update the “App configuration” section with your details and usagesensor, in case the usage sensor you created above has a different name):
Once you’ve saved the above configuration, restart Appdaemon and once it’s loaded you should be able to see an entry on the Add-on logs saying INFO WaterUsage: Starting Water Usage App. Then it’s ready to run.
Notes
This script is set up to run every day at 11am, which is when the full daily usage of the previous day is available. (for some the daily usage might only be available later on the day, adjust runtime = datetime.time(11, 00, 0) accordingly)
Just reiterating what I am saying above, the reading you will be getting is from previous day (Anglia Water only provides readings of the previous day)
Some may say I don’t need a usage sensor and a meter sensor, one sensor should be enough to provide the readings and being able to link to the Energy Dashboard, but I tried so many configs and non worked as I wanted, so I just gave up and set it up this way. Feel free to adapt and if it works for you, let me know in the comments
You can also adapt the script as per initially set up by @dan12345 to pull the hourly readings, and make it run every hour or so - Not sure if Anglia Water has limits to the frequency of logins per day, so I wouldn’t recommend these changes.
The login on Anglia Water website is not very safe as you may know (no 2nd authentication method), so on the eventuality of them updating their website this script may become broken and I most likely won’t be able to fix it but would be happy to collaborate in case someone more savvy is able to.
I am far from even considering myself as a beginner on writing python, so you may notice I have over complicated a few commands, feel free to add your input on this.
No, the second sensor you need to create (the utility meter) should read from the water usage sensor, as per snapshot with the configuration of the utility meter. Also forgot to include that you should add the below to your customize.yaml (I’ll update the instructions again…) so HA knows it’s a water device and updates the unit of measurement automatically:
sensor.water_usage:
device_class: water
The above sensor is my utility sensor name, make sure you update with yours.
Suffice to say that I should have noted down all of my steps before writing my post
Great to hear! We might need some fine tuning along the way but yes currently working well for me.
The water_usage_x it’s required for the script to push the data into, and so the utility meter (once you create it) can then pull the information from. I am sure there’s a way to customize the water_usage_x in such a way that you won’t require a utility meter but haven’t been able to find a config that would work for me. “If it’s working don’t change it”.
Bear in mind that you only need to create the utility meter if you want to incorporate it under the energy dashboard, if not it’s not required.
I’ve created the utility meter. But it doesn’t seem to pull the data from the sensor and nothing is currently showing in the options for water meter on the energy dashboard configuration.
When the script runs. A new sensor is created that had the data. So that part is working for me!
Is your data pulling through as litres and showing as litres or m3?
In app deamon you can define attributes. So
I tried that. But no luck so far with that idea
It takes a while for it to cycle but eventually it will read the value from the sensor, you may have noticed that in the meantime. As for not showing on your energy dashboard options, that’s strange, have you added the below customization?
Can you show me the states attributes of that utility meter? Does it look like the below/
The sensor I created to pull the information from Appdaemon doesn’t have any units, only the utility meter. Once I added the above to customize.yaml the utility meter started showing the values in m3, but for the energy dashboard I don’t believe it matters if it’s L or m3.
I think it might have been partly due to the order of installing it all. And every time I retried there were still sensors and bits from the previous failed attempt.
So after removing it all and restarting HA a few times. I started again.
I also removed the x. So it’s just water usage on the template and the python script.
Just issued a new update as I was having an error where selenium couldn’t find chromedriver path. I have found that a few services were missing, so I have updated the ‘GetWaterUsage.py’ and the Appdaemon configuration as per below:
As for the below, I did something similar on my initial set up, also using InfluxDB. I tested two options but I can’t remember which one I preferred Both have their quirks but feel free to try out:
You can either change the runtime = datetime.time(11, 00, 0) under “Starting APP” section to an hour to run today and then change it back to 11am or you can replace the whole “Starting APP” section with the below config and create a Helper switch “input_boolean.water_reading” to force the update. The latter option is great for when you restar your HA at 11am and you miss the pull request timing, then you can flip this switch to force the update (just a recent update I added to my config ) I will add it to the instructions.
# Starting APP #
def initialize(self):
self.log("Starting Water Usage App")
runtime = datetime.time(11, 00, 0)
self.run_daily(self.StartProcess, runtime)
self.listen_state(self.StartProcessForced,"input_boolean.water_reading", state="on")
#Callback Function to Start the process
def StartProcess(self, kwargs):
self.log("starting process")
usage = self.GetUsage()
self.log("Usage: " + 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("input_boolean.water_reading")
usage = self.GetUsage()
self.log("Usage: " + usage)
try:
self.set_state(usagesensor, state = usage)
except Exception as e:
self.log("Set Sensor State Error: " + str(e))