If you already have the data from the Energy going into a field named
electricity then you re 90% there. As Tom said, if your WeeWX field (ie
electricity) contains the number of kWh consumed in an archive period (I assume this is five minutes) then using the tag
$month.electricity.sum in a WeeWX report template will display the month-to-date electricity usage. If the
electricity field holds a cumulative kWh value (ie the electricity used in a five minute archive period is the difference between successive values) then the
$month.electricity.diff tag will display the month-to-date electricity usage. These tags will actually return a formatted string, if you want to do some maths on the month-to-date usage value then owe need to do things a little differently. There are a couple of different ways you could do this but the easiest approach for some simple maths is to include some in-line python code in a WeeWX report template. Let's say the cost of electricity is 20 cents per kWh, the
electricity field contains the archive period electricity usage and you want to display something like:
Usage this month: 283 kWh
Cost this month: $ 56.60
In this case you would add the following lines of code to your template (untested):
#set $mtd_cost = round($month.electricity.sum.raw * 0.20, 2)
Usage this month: $month.electricity.sum
Cost this month: $ $mtd_cost
The first line of code obtains the month-to-date electricity usage (ie the sum) as a number (.raw gives us a number instead of a string) which we multiply by 0.2 (the cost of 1kWh) and then round the result to two decimal places. This value is assigned to the variable mtd_cost. The second line displays the month-to-date usage in kWh, I expect that rather than displaying 283 kWh it probably displays something like 283.134356. No problems, we just need to let WeeWX know that the field electricity contains values in kWh - we will come back to that later. The third line displays the month-to-date cost in dollars using the value we calculated in the first line. WeeWX has no knowledge of currency so we have to manually format the cost ourselves through use of the round() function in the first line and the dollar sign literal (the first dollar sign) in the third line (note the space between the dollar signs on the third line, this is important).
This code has a couple of limitations. As I mentioned, unless we let WeeWX know that the electricity field contains values in kWh the automatic formatting of $month.electricty.sum won't work properly. Secondly, if your Efergy ever has a hiccup, or for some reason there is no data in field electricity for the month, the tag $month.electricity.sum.raw will return the python value None and the calculation in the first line of code will return an error and the template will abort.
To tell WeeWX that field electricity contains values in kWh add the following code to the bottom of /home/weewx/bin/user/extensions.py or /usr/share/weewx/user/extensions.py (depending on how you installed WeeWX):
# override the default units for group_energy and set to kWh
weewx.units.USUnits['group_energy'] = 'kilo_watt_hour'
weewx.units.MetricUnits['group_energy'] = 'kilo_watt_hour'
weewx.units.MetricWXUnits['group_energy'] = 'kilo_watt_hour'
# set default format and label for kilowatt hours
weewx.units.default_unit_format_dict['kilo_watt_hour'] = '%.1f'
weewx.units.default_unit_label_dict['kilo_watt_hour'] = ' kWh'
# define conversion functions for energy
weewx.units.conversionDict['watt_hour'] = {'kilo_watt_hour': lambda x: x / 1000.0}
weewx.units.conversionDict['kilo_watt_hour'] = {'watt_hour': lambda x: x * 1000.0}
# assign database field electricity to group_energy
weewx.units.obs_group_dict['electricity'] = 'group_energy'
The above code:
(1) tells WeeWX to override the units used for energy from the default Wh to kWh
(2) sets the default formatting and unit label for fields in kWh to one decimal place and 'kWh' respectively
(3) defines conversion functions allowing conversion between Wh and kWH and vice versa (not strictly required in your case but handy to have since we are in here)
(4) tells WeeWX that the field
electricity belongs to
group_energy (which we have already set to use kWh by default). Refer to the section
Assigning a unit group in the Customisation Guide for a little more background.
To handle the condition where $month.electricity.sum.raw is None we need to change our in-line python code. Change the first line:
#set $mtd_cost = round($month.electricity.sum.raw * 0.20, 2)
to something like:
#if $month.electricity.sum.raw is not None
#set $mtd_cost = round($month.electricity.sum.raw * 0.20, 2)
#else
#set $mtd_cost = '---'
#end if
Now if $month.electricity.sum.raw returns the value None we simply display --- as the month-to-date cost otherwise we calculate it as before.
That is probably a lot to take in, especially if you are not familiar with python and WeeWX. See how you go and post back here if you have any issues or further questions.
Gary