First get to know your energy meter recalculation factor. Find the [imp/kWh] marking on your energy meter. Then divide 1,000 with the number you find.
Example 1. If it is marked with 10,000imp/kWh the recalculation factor is 1,000/10,000 = 1/10
Example 2. If it is marked with 500imp/kWh the recalculation factor is 1,000/500 = 2
Once you have the recalculation factor you can use that to calculate the consumed Energy and present Power usage
Energy [kWh], multiply your received number with the recalculation factor for your energy meter. You will likely want it in [kWh], thus the dividend 1,000.
Energy = count ⢠(recalculation factor) / 1,000
Power usage [kW] you need to divide the difference in detected pulses with the elapsed time [s].
Power = â count ⢠(recalculation factor) ⢠60 ⢠60 / â t / 1,000
To get the consumtion of the day you take the last and the first âEnergyâ of the and subtract it
What I get the device is just a counter. So i guess to get the todays consumption you will need to subtract the last and the first input of the day and so on.
A skeleton on how to do it in appdaemon (assuming you have a counter defined). This hasnât been tested (or even loaded) so it will have errors, but will get you started.
What you do with energy and power calculations is up to you.
import appdaemon.appapi as appapi
import datetime
#
# App to calculate energy use
# Args
# recalculation_factor
# energy_counter_sensor
class EnergySensor(appapi.AppDaemon):
def initialize(self):
try:
self.recalc_factor = int(self.args["recalculation_factor"])
if self.entity_exists(self.args["energy_counter_sensor"])
self.log("{} does not exist".format(self.args["energy_counter_sensor"]))
return
midnight = datetime.time(0, 0, 0)
self.run_daily(self.midnight_cb, midgnight)
except KeyError as e:
self.log("Argument not found : {}".format(e), level="ERROR")
except ValueError as e:
self.log("recalculation_factor must be an int : {}".format(e), level="ERROR")
def midnight_cb(self, kwargs):
if self.previous_day_end:
self.previous_day_start = self.previous_day_end
self.previous_day_end = self.get_state(self.energy_counter_sensor)
if self.previous_day_start:
energy = calculate_energy(self.previous_day_start)
power = calculate_power()
def calculate_energy(self, energy_counter):
return energy_counter * self.recalc_factor / 1000
def calculate_power(self):
seconds_in_day = 60 * 60 * 24
return (self.previous_day_end - self.previous_day_start) * self.recalc_factor / seconds_in_day / 1000
It depends a lot on what you intend to do with the information. The simplest would be to use set_state to set the state of a sensor, but you could also use call_service to send it to a service.
2017-11-17 18:48:30.046600 WARNING Traceback (most recent call last):
File "/var/opt/homeassistant/appdaemon/appdaemon/appdaemon.py", line 901, in read_app
importlib.reload(conf.modules[module_name])
File "/usr/lib/python3.4/importlib/__init__.py", line 149, in reload
methods.exec(module)
File "<frozen importlib._bootstrap>", line 1153, in exec
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1467, in exec_module
File "<frozen importlib._bootstrap>", line 1572, in get_code
File "<frozen importlib._bootstrap>", line 1532, in source_to_code
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/var/opt/homeassistant/appdaemon/conf/apps/wattcount.py", line 18
if self.entity_exists(self.args["energy_counter_sensor"])
^
SyntaxError: invalid syntax
I want to show to total daily usage in a graph, and maybe todays total usage as a widget?
And i want to show the current usage as a widget.
You just need a sensor that wonât update by any other means. I think you can create a template sensor to do that.
Alternatively, you can store it in an input_number by calling the input_number set_value service.
Or another way would be to write the data to a file, and read the data from the file with the file sensor. The advantage of this is that you would have the data available outside of HA, so you could use whatever graphing program you like to look at it.
I have the very same sensor and use the âcommand line sensorâ with a small python script. That works pretty well since several months. The problem is that I canât use Hass.io as I can not run any python scripts there as far as I know. If you want I can share the script with you by mail.
I have the same sensor and would be so glad to get the script to try implementing it. I used to run Domoticz but changed to HA yesterday. Thanks!
//Rich
Iâm using a tmp file to store the values and 3 small python scripts for current, daily and monthly consumption. You will need TellCore to read the sensor:
Iâm on the usual Homeassistant in Virtual Environment. Can I use your new approach in HA? or do I need to use the older script files? The link seems to be dead âThe requested URL /read_power.zip was not found on this server.â
Regards Richard
Yes! That should work as well. I removed the old version from the server as the new seems more usable. You might need to install TellCore if you have the normal HomeAssistant!