How to get correct kWh/W values from Pulse

all credit goes to pb66 and BMJ on a thread I found, but it works brilliantly
the previous thread - Dual electricity rate in emonCMS - #5 by pb66

ive written out the combined steps from the previous post that I went through (hope it makes sense);

in the web interface add the virtual device (login → emonhub → edit config as below → save

add this to interfaces section:

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

 
add this to the nodes section

[[14]]
nodename = cron_TOU
[[[rx]]]
names = cost,peak, off-peak
datacode = 0
scales = 1,1,1

 
log on via ssh (e.g. via putty to the ip of the pi

User: "pi" | Password: "emonpi2016"

rpi-rw (changes the pi to read write mode so you can write the cron)

sudo crontab -u root -e

create a crontab
mine are 00:00-05:00, 13:00-16:00, 20:00-22:00
my off-peak rate is 7.83p, and peak is 16.04p
basically multiples of the two lines below
1st line sets current cost to 7.83p, the second line returns it to 16.04
obviously you need to find out your tarrifs and times (ideally test by checking meter at changeover times)

00 0 * * * /bin/bash -c 'echo -e "14 7.83 0 1\r" > /dev/tcp/localhost/50011'
00 5 * * * /bin/bash -c 'echo -e "14 16.04 1 0\r" > /dev/tcp/localhost/50011'

00 13 * * * /bin/bash -c 'echo -e "14 7.83 0 1\r" > /dev/tcp/localhost/50011'
00 16 * * * /bin/bash -c 'echo -e "14 16.04 1 0\r" > /dev/tcp/localhost/50011'

00 20 * * * /bin/bash -c 'echo -e "14 7.83 0 1\r" > /dev/tcp/localhost/50011'
00 22 * * * /bin/bash -c 'echo -e "14 16.04 1 0\r" > /dev/tcp/localhost/50011'

in order to test you can just initiate one of the commands from the cli, which will populate a current value immediately

/bin/bash -c 'echo -e "14 16.04 1 0\r" > /dev/tcp/localhost/50011'
rpi-ro 

(coverts back to read-only mode)

you should see a new input called “cron_TOU” in the inputs section
if you are missing the inputs on the device then reboot the pi

sudo reboot

mine looks something like this:

###overview
cron basically creates a virtual input on device 14 and sets/updates current cost as an input
the nodes section gives this on the virtual device cron_TOU
then configure the pulsecount interface (i used as per below):

##first a total cost accumulator
reset to original - (if doing something already e.g. logging raw pulses, kwh, etc)
total pulse to pulse increment “total pulse” (pulses since last update)
x input “cron_TOU:cost” - (multiply by cost)
x “0.001” - (convert to kW)
log to feed “pulse total cost” - (log the incremental cost increase)
accumulator “total cost accumulator” - (accumulates a total ever-increasing cost)

##then a peak cost accumulator
reset to original
Total pulse count to pulse increment “peak pulse” - (find the incremental number of pulses)
x input “cron_TOU:peak” - (multiply by zero when off-peak - i.e. total cost increment is zero’d out when off-peak)
x input “cron_TOU:cost” - (multiply by the current cost to calculate current incremental cost)
x “0.001” (convert from pulses to kw - my meter is 1000 pulses per kw)
accumulator "peak cost accumulator) - logs an accumulating current cost

##then an off-peak cost accumulator
reset to original
total pulse count to pulse increment " off-peak ulse"
x input “cron_TOU:off-peak” - (multiply by zero when peak - i.e. total cost increment is zero’d when peak)
x input “cron_TOU:cost” - (multiply by the current cost to calculate current incremental cost)
x “0.001” (convert from pulses to kw - my meter is 1000 pulses per kw)
accumulator "off-peak cost accumulator) - logs an accumulating current cost
it should look something like below

###Graphing
viewable via the eye icon in feeds and then add the others (ill try and upload an example) - in my example I used the following feeds:
total cost accumulator
peak cost accumulator
off-peak cost accumulator

you should see flatlines for the times when tariff not applicable
the total cost accumulator should be the sum of both peak and offpeak (i.e. no flatlines)

After 24hrs you should be able to view cumulatively
in graph select
time period 1 day
delta
set the type to barchart in the drop-down

in an ideal world another cron would exist to reset the accumulator at midnight and you could then view todays cost as well as previous days (i.e. without deltas

lo and behold pb66 has delivered again - my thanks again (previous thread)

###resetting the graph at midnight (to avoid using delta
this allows for a graph of the current daily accumulating cost
please note i think probably best to log two graphs. One which resets and one which doesn’t. This Then means you can use deltas on the one which doesnt reset to show e.g. cost last week, cost last month, cost last year simply via deltas.
unfortunately you can’t just add the non-resetting accumulator below the resetting one as it will receive the input of the accumulation (i.e. reset to original and create a section just for the cumulating one)

###Steps
overview
create a new input that is logged to the accumulator feeds at midnight setting a value of zero.

[optionally create the interface names] - this will add friendly names to the inputs

[[99]]
nodename = cron_RESET
[[[rx]]]
names = reset
datacode = 0
scales = 1

(for some reason my input shows as r instead of reset - not sure why but never mind)

login as ssh
rpi-rw (changes the pi to read write mode so you can write the cron)

sudo crontab -u root -e

add a line to crontab (this will send a reset to the new feed at midnight)

00 00 * * * /bin/bash -c 'echo -e "99 0\r" > /dev/tcp/localhost/50011'

save this.

then trigger the new input via cli:

/bin/bash -c 'echo -e "99 0\r" > /dev/tcp/localhost/50011'

node will appear in inputs but only show rssi
reboot pi

sudo reboot

in inputs edit the new input [spanner icon]
add a “log to feed” for each of the accumulators [specifically choose the existing feeds rather than creating new ones!)
total cost accumulator
peak cost accumulator
off-peak cost accumulator
save

it should look something like below:

wait till midnight and the graph should look something like below:

###Further improvements
one thing i noticed when rebooting the pi completely (e.g. power cut) is that the input of the current cost is lost
thanks again to pb66 who had an immediate answer to my shoolboy error.
i needed to record the input to a feed so it would be maintained following reboot

so here are the changes i have just made to fix this:

  1. In the inputs (in my case cron_TOU), for the individual inputs of cost, peak, off-peak, add an input to each of “log to feed”, “create new”, name (I used the names - “current cost”, “is_peak” and “is_offpeak”), type: phptimeseries.

  2. manually triggered a value to be set (and therefore logged to the new starting value)

  3. go back to the pulsecount and replace each “x input” with the relevant “* feed”

  4. i copied the first total cost section to create a new accumulator (not to be reset at midnight) for use with deltas (i.e. cost last month, cost last week etc

leaving a process list that looks like this:

1 Like