Dual electricity rate in emonCMS

Hi All,

We’ve got an electricity supplier which offers two prices: cheaper at night and more expensive during the day. Is there any way to control consumption (i.e. KW/h) for each type of rate? My first idea was to have two different feeds, one for night and another for day consumption, but I haven’t found a way to implement this in emonCMS. Is there a way to discriminate by hour?

BTW, I’ve got an emonPI and I am using emonCMS.org (I could also use my emonPI emonCMS instance).

Best regards,

I would recommend exploring the local emoncms as there are significantly more tools to make the task easier.

That being said it is possible on emoncms.org and you are half way there thinking about 2 seperate feeds. The missing component is a signal to switch from peak to off-peak. I have a little script running on my emonbase that sends twice a day to mark the start and end of peak period.

Once you have at least one single input that alternates between 0 and 1 as the tariff changes you can use that input to multiply with your main import feed before saving to peak_import and off-peak import feeds.

Thanks for your answer!
I understand the generation of an input that alternates between 0 and 1. That would solve things.
On the other hand, from your message I deduce that the local emonCMS in my emonPI would be more powerful than the hosted emonCMS … Is there a simpler option if I follow that direction?


I’m interested in this topic as well. Where I live (Ontario, Canada), there is an off-peak rate, a mid-peak rate, and an on-peak rate, each active during different parts of the day. I’d like to be able to record and display on a dashboard the cost of energy consumed based on the time of day.
That said, I’m not very familiar with the programming skills necessary to make this idea a reality. Is anyone able to set me in the right direction on how to access those parts of a local emoncms that I could modify to achieve this?

Apologies @jpuigsegur, I thought I had replied to you and only just found the unfinished and unposted draft, I must of been distracted and forgot to come back to it.

@BMJ it is possible with both the local emoncms schedule module and the cron method to have multiple tariff periods.

I will finish off what I was writing and hopefully post further on this tomorrow if I can (over the weekend otherwise), as it’s been a long day today.

It’s difficult to say whether it is “simpler” and there are other differences that may make one method more suitable than the other. Whilst I have used the schedule module in emoncms for some tasks I still use the cron method for this particular job because

  • It was already set up prior to the schedule module being written and has worked well.
  • emoncms.org does not have the schedule module (yet???)
  • I use multiple emoncms’s and this method serves all with the same data
  • The timezone can be set independently of emoncms, this means I can still use my local UK “DST” timezone in emoncms despite my meters tariff times being UTC. This won’t be important if your tariffs are on the same timezone as your emoncms user account and follow DST, you can probably get around this in the schedule module by setting up a more complex schedule with different times set for DST summer and DST winter periods…
  • There are some other benefits like easily adding time based service charges if calculating monetary totals
  • You can also schedule a change of rate like a price increase and have it applied automatically

The schedule module has the great advantage of being web based so you do not need to ssh in via a console, which means you can edit the schedule from outside your LAN without opening a port (or making another arrangement eg dataplicity). Since meter based time periods are unlikely to change the appeal of that maybe limited and also for that exact same reason I prefer to keep my “permanent tariff periods” in cron were I am unlikely to edit them whilst playing with other schedules.

Here is an example cron entry

# Since my Economy7 tariff daily time periods do not follow DST use UTC.
15 0 * * * /bin/bash -c 'echo -e "14 6.949 0 1\r" > /dev/tcp/localhost/50011'
15 7 * * * /bin/bash -c 'echo -e "14 15.807 1 0\r" > /dev/tcp/localhost/50011'

In this example the timezone is defined as UTC so that I can still use a local timezone and the tariff periods still track UTC, I have watched the display on my meter and have confirmed “off-peak” starts at 00:15 and ends at 07:15, so they are the time settings at the start of each of the 2 events (mm hh * * *).

At each event a single packet is sent to a socket opened by emonhub by adding the following to the interfacers section of emonhub.conf

        Type = EmonHubSocketInterfacer
            port_nb = 50011      # sets the port to listen on, cron must point to this port.
            pubchannels = ToEmonCMS,      # only required in the emonpi variant of emonhub

The packet is in the form nodeId unitPrice peakStatus offpeakStatus, ie at 00:15 a packet is sent as node 14 setting the unit price to 6.949p and setting peak status to 0 and off-peak status to 1.

Those last 2 “status” values are the filters for the peak and off peak feeds, by multiplying each incoming increase in kWh by each “status” before adding to the feeds only one will get thorough, the other is zeroed.

The packet can be in many different forms, this is just an example to show how to set it up rather than, specifically what to set up.

The schedule module isn’t officially documented (AFAICT) but there is a guide on the old forum in the EmonCMS multi rate scheduler discussion and further info on this topic can be found on the EmonCMS multi rate energy billing support and emoncms time-of-day filter process threads too.

Another consideration I had hoped top test for but haven’t had the time, is whether the schedule modules events are applied using the current time or the timestamp of the input data. When timestamped data arrives late due to a network outage for example we want to be sure the energy used is logged to the tariff applicable at that time not the tariff that is current if it has changed since. The cron method ensures the tariff period is applied correctly, even if data is buffered for hours or days. I would hope the same can be said for the schedule module but I do not know for sure, this is less likely to be a concern if all is on one machine or if using the emonPi variant of emonhub as data is no longer buffered beyond 30sec (by default).

Thanks @pb66 for the straightforward explanation on using cron to input time-of-use rates. I think I’ll be able to implement that.

I’d also be interested trying out the scheduler, but I see that it’s location in GitHub (linked to in one of the threads you referenced) is currently empty. Is it available anywhere else?

The Schedule Module is no longer optional, it is part of the main emoncms repo.

(It seems to have gone against the flow of “a more modular approach” that led to the dashboard module being removed!!)

Thanks, @pb66 for your help. I was able to write a crontab entry --pretty much a copy of your example – and it is communicating with EmonHub. I get an entry like this in the log:

2017-01-26 21:09:01,188 DEBUG cron 5 NEW FRAME : 14 .087 0 1 0
2017-01-26 21:09:01,190 DEBUG cron 5 Timestamp : 1485482941.19
2017-01-26 21:09:01,190 DEBUG cron 5 From Node : 14
2017-01-26 21:09:01,191 DEBUG cron 5 Values : [0.087, 0, 1, 0]
2017-01-26 21:09:01,191 DEBUG cron 5 Sent to channel(start)’ : ToEmonCMS
2017-01-26 21:09:01,192 INFO cron Publishing: emon/cron_TOU/cost 0.087
2017-01-26 21:09:01,205 INFO cron Publishing: emon/cron_TOU/offpeak 0
2017-01-26 21:09:01,231 INFO cron Publishing: emon/cron_TOU/midpeak 1
2017-01-26 21:09:01,235 INFO cron Publishing: emon/cron_TOU/onpeak 0
2017-01-26 21:09:01,237 INFO cron Publishing: emon/cron_TOU/rssi 0
2017-01-26 21:09:01,239 INFO cron Publishing: emonhub/rx/14/values 0.087,0,1,0
2017-01-26 21:09:01,241 INFO cron Publishing: emonhub/rx/14/rssi 0
2017-01-26 21:09:01,243 DEBUG cron 5 adding frame to buffer => [1485482941.18843, 14, 0.087, 0, 1, 0]
2017-01-26 21:09:01,244 DEBUG cron 5 Sent to channel(end)’ : ToEmonCMS

A strange thing is happening though - I’m not seeing my four values show up on the Inputs screen of emoncms under this node:

Any idea of what to make of this?

Here are my entries in the EmonHub config file:

Under Interfacers (a copy of your example, but I changed “subchannels” to “pubchannels”):

Type = EmonHubSocketInterfacer
port_nb = 50011 # sets the port to listen on, cron must point to this port.
pubchannels = ToEmonCMS, # only required in the emonpi variant of emonhub

And under Nodes:

nodename = cron_TOU
names = cost,offpeak,midpeak,onpeak
datacode = 0
scales = 1,1,1,1

Another odd thing is that when I have my main node connected, my cron node never stays on the Inputs screen for very long. At the minute mark, it will show up when the cron task runs, but after another posting from my Arduino node takes place, it vanishes.

I think both of these are related to an unresolved issue with the emoncms mqtt input, there are several threads on this and is sounds very much like what I experienced when adding a Gas pulse node recently too. For some reason emoncms will not create new inputs from mqtt once up and running, so if you try rebooting your emonPi it should appear, fingers crossed.

My bad, of course it would be pubchannels, I’ve corrected my post to avoid future confusion :slight_smile:

That did it! I had tried restarting Emonhub but didn’t think to restart the whole system. Thank you.

Hi all,

I just finished seting up my updated emonPI to record dual electricity rate using schedule module. It took some time since I had to flash another card with the newest emoncms version.

With the schedule module it is fairly easy. Since our dual rate works with UTC and the emonPI also works in UTC only the following two schedules are necessary:

  1. Night: 00:00-10:59, 21:00-23:59
  2. Day: 00:00-10:59, 21:00-23:59
    The schedule module also allows to specify different periods Summer and Winter but in my case it is not necessary.

Then I used the If !schedule ZERO processors to generate two different feeds.

Thanks for all the answers!