Page 1 of 2

Daily Energy usage cost

Posted: Wednesday 28 March 2018 22:09
by garethiowc
Hi all,

So i've been able to graph my energy usage using the owl micro but i wondered if theres anyway i can get domoticz to automatically work out how much it's costing me.

i pay 14.89p per unit.

many thanks
Screen Shot 2018-03-28 at 20.55.14.png
Screen Shot 2018-03-28 at 20.55.14.png (19.13 KiB) Viewed 8829 times

Re: Daily Energy usage cost

Posted: Thursday 29 March 2018 10:22
by McMelloW
AT settings ==> meters/counters fill in the cost/kWh.
On the device click on log and then report

Re: Daily Energy usage cost

Posted: Thursday 29 March 2018 22:52
by garethiowc
ah awesome thank you :)

i also have a daily meter charge of 14.09p i don't suppose there's anyway to get that to add to the daily cost?

Re: Daily Energy usage cost

Posted: Friday 30 March 2018 10:54
by McMelloW
I use an average figure per kWh including tax, meter charge etc. This calculated according to the bills of the past few years.
Feel free to think of something clever and post it.

Re: Daily Energy usage cost

Posted: Friday 30 March 2018 12:57
by dervogt
good idea, if you got the energy bill of last year, you can probably just add a markup for the fixed costs like meter rent, delivery&transport costs etc to the price per unit

Re: Daily Energy usage cost

Posted: Friday 30 March 2018 13:01
by McMelloW
dervogt wrote: Friday 30 March 2018 12:57 good idea, if you got the energy bill of last year, you can probably just add a markup for the fixed costs like meter rent, delivery&transport costs etc to the price per unit
Even better if you have energy bills from a couple of years.

Re: Daily Energy usage cost

Posted: Friday 30 March 2018 18:39
by MikeF
Here's a simple python script I use which calculates energy cost based on cumulative energy today, and which allows for fixed and variable cost elements:
Spoiler: show

Code: Select all

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
energy_cost.py

Reads 'CounterToday' from Owl energy meter
Writes calculated cost to text device

This version is called from crontab

"""

import requests
import json

# Domoticz variables - change for your installation

fixed = 0		# fixed cost in pence
unit = 13.94 	# unit cost in pence

OwlIdx = '<xxx>'
costIdx = '<xxx>'
DomoBaseURL = 'http://<domoticz url:port>/json.htm?type=devices&rid='
DomoWriteURL  = 'http://<domoticz url:port>/json.htm?type=command&param=udevice&nvalue=0&idx='

# End of Domoticz variables

def domoticzread(idx, var):
   url = DomoBaseURL + idx
   response = requests.get(url)
   jsonData = json.loads(response.text)
   result = jsonData['result'][0][var]
   return result;

kW = domoticzread(OwlIdx, 'CounterToday')
kWh = kW.split()[0]
cost = round((float(kWh) * unit + fixed) / 100 ,2)
cost = "£" + str(cost)
#print kW, cost

url = DomoWriteURL + costIdx + '&svalue=' + cost
r = requests.get(url)

Change the Domoticz variables section to suit your installation. This assumes that your Owl device maintains a variable 'CounterToday' - check the json output for your device.
I run this once a minute from crontab - I would have liked to use lua (so this would update every time the Owl device updates), but I couldn't work out how to extract 'CounterToday'.

Here is an example of my output:
Image
(of course this can be changed for other currencies)

Re: Daily Energy usage cost

Posted: Saturday 31 March 2018 17:49
by garethiowc
MikeF you hero :D

this is exactly what i was thinking of but just didn't have the knowledge to put it together.

so i would copy the code you have supplied and save it to a file called energy_cost.py

Once i have made the changes i would run:

Code: Select all

crontab -e
choose nano and add the following line to the bottom of the file:

Code: Select all

*/1 * * * * /usr/bin/python2.7 /sbin/energy_cost.py >> /var/log/energy_cost.log 2>&1



sorry where would i find the json for the device?

i can see the following in the logs

Code: Select all

2018-03-31 16:46:43.495 RFLink: 20;E5;OWL_CM180;ID=003D;WATT=00f1;KWATT=00026bad;
2018-03-31 16:46:43.497 (RFLink Gateway) General/kWh (Power Monitor)

Re: Daily Energy usage cost

Posted: Saturday 31 March 2018 19:04
by MikeF
Hi garethiowc,

First of all, make sure you change the lines in 'Domoticz variables' section of the code to your values - you'll need to find the idx of your Owl device, and also set up a text sensor in Domoticz, and get its idx.

Once you've got the Domoticz idx of your Owl device, type the following into your browser (replacing the angle brackets with your values):

http://<Domoticz ip:port>/json.htm?type=devices&rid=<Owl idx>

(e.g., http://192.168.0.63:8080/json.htm?type=devices&rid=240)

- this is the json output. If you can see a line like this:

Code: Select all

"CounterToday" : "9.211 kWh",
then you should be good to go.

Your crontab steps look OK.

Re: Daily Energy usage cost

Posted: Saturday 31 March 2018 19:48
by garethiowc
Thanks MikeF

just got the script working


apt-get install python-requests

source ~/.bashrc

Re: Daily Energy usage cost

Posted: Saturday 31 March 2018 19:52
by garethiowc
is the fixed cost the daily meter rental charge or am i understanding that wrong?

Re: Daily Energy usage cost

Posted: Saturday 31 March 2018 22:18
by MikeF
garethiowc wrote: Saturday 31 March 2018 19:52 is the fixed cost the daily meter rental charge...
Yes

Re: Daily Energy usage cost

Posted: Sunday 01 April 2018 22:50
by EdwinK
Trying to get this to work with Toon (Eneco), but only get 0.01 pence costs. Of course I wouldn't mind that ;)

Re: Daily Energy usage cost

Posted: Sunday 01 April 2018 23:04
by garethiowc
Screen Shot 2018-04-01 at 22.00.26.png
Screen Shot 2018-04-01 at 22.00.26.png (32.14 KiB) Viewed 8503 times
all working great here :D thank you so much MikeF

i had to specify the python3 path to get it to work in cron using the following

*/1 * * * * /usr/bin/python3.5 /sbin/energy_cost.py >> /var/log/energy_cost.log 2>&1

added a log output for errors when the cron job runs

next thing to work out would be a weekly and monthly cost output :D

Re: Daily Energy usage cost

Posted: Sunday 01 April 2018 23:39
by MikeF
EdwinK wrote: Sunday 01 April 2018 22:50 Trying to get this to work with Toon (Eneco), but only get 0.01 pence costs. Of course I wouldn't mind that ;)
Have you checked that you've got a variable 'CounterToday' (or change it to something similar) that's producing values to a similar order of magnitude (e.g., 6.392 kWh)? and that your fixed / variable costs are similar? (Of course, you can input these in cents, and change the script to display in € rather than £.)

Re: Daily Energy usage cost

Posted: Monday 02 April 2018 0:22
by garethiowc
"CounterToday" : "6.6 kWh",
"CustomImage" : 0,
"Data" : "167.985 kWh",
Does any one know if the data sting will reset monthly or just keeps counting?
Screen Shot 2018-04-01 at 23.21.11.png
Screen Shot 2018-04-01 at 23.21.11.png (23.38 KiB) Viewed 8479 times

Re: Daily Energy usage cost

Posted: Monday 02 April 2018 7:20
by clubeddie
garethiowc wrote: Monday 02 April 2018 0:22
"CounterToday" : "6.6 kWh",
"CustomImage" : 0,
"Data" : "167.985 kWh",
Does any one know if the data sting will reset monthly or just keeps counting?

Screen Shot 2018-04-01 at 23.21.11.png
Data is Just counting, so not usable for monthly costs.

Re: Daily Energy usage cost

Posted: Tuesday 03 April 2018 10:37
by MikeF
I guess you could get the script to save the cumulative Data value at the beginning of each month
- if 'day' = '01' and 'time' = '00:00' then write Data to uservariable 'MonthStart'
and then subtract MonthStart from current value of Data every time the script runs...

Haven't tried it though!

Re: Daily Energy usage cost

Posted: Tuesday 03 April 2018 20:14
by EdwinK
This is what I have within the device:

Code: Select all

{
   "ActTime" : 1522779214,
   "AstrTwilightEnd" : "22:20",
   "AstrTwilightStart" : "05:12",
   "CivTwilightEnd" : "20:53",
   "CivTwilightStart" : "06:38",
   "DayLength" : "13:06",
   "NautTwilightEnd" : "21:35",
   "NautTwilightStart" : "05:56",
   "ServerTime" : "2018-04-03 20:13:34",
   "SunAtSouth" : "13:05",
   "Sunrise" : "07:12",
   "Sunset" : "20:19",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "Counter" : "3532.785",
         "CounterDeliv" : "0.000",
         "CounterDelivToday" : "0 kWh",
         "CounterToday" : "5.709 kWh",
         "CustomImage" : 0,
         "Data" : "1744933;1787852;0;0;517;0",
         "Description" : "",
         "Favorite" : 0,
         "HardwareID" : 35,
         "HardwareName" : "Toon",
         "HardwareType" : "Toon Thermostat",
         "HardwareTypeVal" : 34,
         "HaveTimeout" : false,
         "ID" : "1",
         "LastUpdate" : "2018-04-03 20:13:13",
         "Name" : "Electra",
         "Notifications" : "false",
         "PlanID" : "0",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "SubType" : "Energy",
         "SwitchTypeVal" : 0,
         "Timers" : "false",
         "Type" : "P1 Smart Meter",
         "TypeImg" : "counter",
         "Unit" : 1,
         "Usage" : "517 Watt",
         "UsageDeliv" : "0 Watt",
         "Used" : 1,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "199"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}

Re: Daily Energy usage cost

Posted: Tuesday 03 April 2018 23:39
by MikeF
EdwinK wrote: Tuesday 03 April 2018 20:14 This is what I have within the device:

Code: Select all

{
...
         "CounterToday" : "5.709 kWh",
...
}
My python script uses CounterToday, so if for instance your unit cost is 14.89 and fixed cost is 14.09 (garethiowc's example), then you should get:
cost = (5.709 * 14.89 + 14.09 ) / 100 = 0.99

Can you check your values and your script again?