Great stuff! There’s always room for improvement thou and I will update the instructions as and when.
UPDATE
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:
system_packages:
- chromium-chromedriver
- chromium
python_packages:
- selenium
init_commands:
- >-
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >
/etc/apk/repositories
- >-
echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >>
/etc/apk/repositories
- apk update
All of the updates have been included on my initial post.
Note: For the ones that have already installed it, make these changes only if you’re seeing the same error, if not leave as is.
I started seeing this error today.
I’ve edited the app daemon config and I’m
Still getting the error at the moment
And have you copied the new GetWatwrUsage.py config?
Apologies. Just added the lines in now that changed.
Appears to be working again.
I’m working on a modified version that combines your work with the original and places hourly data into influxdb.
I’ve then got the data into grafana.
Got it working but just working on how the influxdb sensors communicate back to HA
As the data is always between 12-24 hours behind there’s not really a perfect implementation.
So might just build a water dashboard and ignore the energy bit
Great stuff!
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:
Hey @Zeunas - thank you for doing this and I have finally gotten around to following your instructions to get this all going in HA!
Do I have to wait until the following days 11am to get an initial reading?
Glad I could help
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))
Thanks @Zeunas. I’ve updated the script and restarted. It seems to be working - the input_boolean turns off and can see today’s current usage correctly reflected in sensor.water_usage_x
.
The only way I have managed to get this into the HA Energy dashboard is to edit the customize.yaml
file adding a state_class
sensor.water_usage:
device_class: water
unit_of_measurement: L
state_class: total_increasing
In the energy dashboard configuration water usage now appears.
However, the data does not flow through to the dashboard…
Your help is greatly appreciated.
From what I found the template sensor name you create has to be the same as the name you set in the python script.
Otherwise a new sensor is created by appdaemon which is not connected to the water meter.
You shouldn’t require to customise the state_class of the utility meter, if you have set it up as such. You need to give the utility meter some time to cycle (it can take a couple of hours), it will eventually pull the information from the sensor.water_usage_x. If you really want to force test it, you can always use the below service and input the value you want, however bear in mind if in one day you use the force pull options more than once (input_boolean switch and calling the below service) it will eventually skew your usage trend, as your utility meter will stack up the values your force into it. You can always amend it under Statistics tab on the Developer tools, which will fix your Energy Dashboard but won’t fix it at Frontend.
What @rodgers86 is saying above is correct.
Tried both now.
Option 1
I’ve previously only used option1. Which eventually worked, but the documentation is terrible. Took ages to do something which should be simple.
Option 2. Much easier to set up as you can pretty much write what you need in SQL query format however it puts the time stamp as the state?!
It does put the correct data in the attributes though so I’ve amended the pyscript so that the state is the Value.
As you can see in picture my usage was
2023L until I amended the script.
Yes! I remember that now…not the greatest but it was the easiest to use. Well done finding a solution thou! My work around back then was to create another sensor to read from the attributes but yours is so much cleaner!
Ok @Zeunas - so I unpicked this from the customize.yaml file and the energy dashboard now has this as an error;
I guess I just don’t understand how this stuff should hang together but what is more confusing and probably unrelated is that the script keeps returning a usage value of 0. Checking on the Anglian website the figure should be 138L for yesterday. I’ve even tried restarting AppDaemon. Here is the log;
Any thoughts?
That’s strange, it should set the state_class automatically by setting the device class as water, in that case add it back to the customize.yaml state_class: total_increasing
I can see that you’re script is running at 8.38, it should be running after 11am, make sure that the first part of the script under “Starting APP” has the ‘datetime.time’ set to 11, as per below:
# 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,reading, state="on")
Script is fine. It ran at 8:36 because I forced it via the input boolean to show you the log entries…
Let’s wait for 11am or push the switch again? And let me know what you get. I think that at 8.36 the website might not have data for the script pull information from and it won’t pull from the previous day (2nd August for this example).
The system clock is an hour ahead in the logs so I assume it must be on UTC. You can see the script ran at 11:00:00 returning a Usage: 0, and again when I forced via the switch at 16:55 with the same result.
Interestingly this is what I see on the Anglian Website for the daily view;
Note nothing for yesterday… And this for the hourly view;
Which does have some data!!?
That’s indeed very strange! I believe only when you get the full 24h usage data it will then show on your Daily Usage but it seems for you that it takes longer for that to be available, try checking later to see if you have it and change the script to run shortly after. Alternatively you can also adapt it to take the info from the hourly section like rodgers86 did.
Did you @Zeunas opt for more detailed readings when the meter was installed or do you only get the daily usage stats?
@rodgers86 - would you be so kind as to share the script you developed to pull the hourly data?