Daily Energy usage cost

Moderator: leecollings

garethiowc
Posts: 28
Joined: Sunday 03 December 2017 23:02
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Daily Energy usage cost

Post 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 8828 times
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Daily Energy usage cost

Post by McMelloW »

AT settings ==> meters/counters fill in the cost/kWh.
On the device click on log and then report
Greetings McMelloW
garethiowc
Posts: 28
Joined: Sunday 03 December 2017 23:02
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Daily Energy usage cost

Post 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?
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Daily Energy usage cost

Post 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.
Greetings McMelloW
dervogt
Posts: 26
Joined: Thursday 30 June 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Amsterdam
Contact:

Re: Daily Energy usage cost

Post 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
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Daily Energy usage cost

Post 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.
Greetings McMelloW
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Daily Energy usage cost

Post 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)
garethiowc
Posts: 28
Joined: Sunday 03 December 2017 23:02
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Daily Energy usage cost

Post 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)
Last edited by garethiowc on Monday 06 May 2019 22:10, edited 2 times in total.
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Daily Energy usage cost

Post 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.
garethiowc
Posts: 28
Joined: Sunday 03 December 2017 23:02
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Daily Energy usage cost

Post by garethiowc »

Thanks MikeF

just got the script working


apt-get install python-requests

source ~/.bashrc
Last edited by garethiowc on Monday 06 May 2019 21:57, edited 2 times in total.
garethiowc
Posts: 28
Joined: Sunday 03 December 2017 23:02
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Daily Energy usage cost

Post by garethiowc »

is the fixed cost the daily meter rental charge or am i understanding that wrong?
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Daily Energy usage cost

Post by MikeF »

garethiowc wrote: Saturday 31 March 2018 19:52 is the fixed cost the daily meter rental charge...
Yes
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Daily Energy usage cost

Post 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 ;)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
garethiowc
Posts: 28
Joined: Sunday 03 December 2017 23:02
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Daily Energy usage cost

Post 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 8502 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
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Daily Energy usage cost

Post 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 £.)
garethiowc
Posts: 28
Joined: Sunday 03 December 2017 23:02
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Daily Energy usage cost

Post 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 8478 times
clubeddie
Posts: 80
Joined: Saturday 19 March 2016 21:12
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Daily Energy usage cost

Post 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.
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Daily Energy usage cost

Post 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!
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Daily Energy usage cost

Post 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"
}
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Daily Energy usage cost

Post 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?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest