Energy Monitor

My hardware skills being next to non-existent am relying on bolting some pre-built hardware together. A good starting point is open energy monitor. project. Simplest scheme, using the existing Raspberry Pi that is hosting the Home Server is something based on:

Firmware for the Arduino is here: https://github.com/openenergymonitor/emontx-shield

Connect it all together, a new /dev/ttyXXX device should be created in the Pi, use udev rules to map it to /dev/ttyEnergyMon. Add a bunch of serial items:

Group Power<br>
Number Utility_Power1 "Power Generated"  (Power, Utility) {serial="/dev/ttyEnergyMon@9600,REGEX(s/(-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>)/$1/)"}<br>
Number Utility_Power2 "Power To Grid"  (Power, Utility) {serial="/dev/ttyEnergyMon@9600,REGEX(s/(-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>)/$2/)"}<br>
Number Utility_Power3 "Power N/C 3"  (Power, Utility) {serial="/dev/ttyEnergyMon@9600,REGEX(s/(-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>)/$3/)"}<br>
Number Utility_Power4 "Power N/C 4"  (Power, Utility) {serial="/dev/ttyEnergyMon@9600,REGEX(s/(-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>)/$4/)"}<br>
Number Utility_Power_VRMS "Power VRMS"  (Power, Utility) {serial="/dev/ttyEnergyMon@9600,REGEX(s/(-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>) (-<em>[0-9.]</em>)/$5/)"}<br>
Number Utility_Power5 "Power Usage"  (Power, Utility)<br>
Number Utility_Power6 "Power Exported"  (Power, Utility)<br>
Number Utility_Power7 "Power Imported"  (Power, Utility)

Create some rules to populate the virtual items:

rule "Power Usage"
when
    Item Utility_Power1 received update
then
    var Generated = Utility_Power1.state as Number
    var Exported = Utility_Power2.state as Number
    var Usage = Generated - Exported
    var Power_In = 0
    var Power_Out = 0
    Utility_Power5.postUpdate(Usage)
    if (Exported > 0) {
        Power_Out = Exported
    } else {
        Power_In = -Exported
    }
    Utility_Power7.postUpdate(Power_In)
    Utility_Power6.postUpdate(Power_Out)
end

Push all items to influxdb using persistence service:

Strategies {
    Every30s       : "*/30 * * * * ?"
    EveryMinute    : "0 * * * * ?"
    Every10Minutes : "0 */10 * * * ?"
    EveryHour      : "0 0 * * * ?"
    EveryDay       : "0 0 0 * * ?"

    default = everyChange
}

Items {
    Utility_Power1, Utility_Power2, Utility_Power5, Utility_Power6, Utility_Power7, Utility_Power_VRMS : strategy=everyChange,Every30s
}