Can anyone point me to a good way to do the following (maybe even some existing code)?
I have a rPI3, which I connected to my electric meter that counts how much power my heatpump consumes. There are 1000 impules for every kWh that has been consumed. The wires are connected to two GPIO pins. I have been able to get a C program to work (found here: https://blog.webernetz.net/stromzahler-mit-s0-schnittstelle-vom-raspberry-pi-auswerten/) which “detects the impules” and uses a counter in a file /var/strom/stromcounter. For every impules received, the counter is incremented by 1. As soon as the C program is stopped, counters return to 0, so no kind of database is used.
What I’d like to have now is a graph / graphs that displays the power consumption. As I am quite the openHab beginner, I’m not sure what the best approach would be. I guess I need to use some kind of persistance? How do I get the data into openHab? I do have a MQTT broker running, but I guess I would need to connect to that MQTT broker via my C code, or use something else (like a Python script or so?), to publish the counter to openHab? Or is it easier to keep the counter file and read that somehow in openHab?
The best thing would be if the data would be stored, so I can keep track of power consumption over time (not sure how accurate that will be over time though).
Do you know volkszaehler.org? This software is intended to track down any sort of consumption like water, electrical power, gas and so on. It’s easy to read the consumption through an item bound to http. If you don’t want to use the volkszaehler stuff, you could either read a file frequently to get the actual state or put the pulses to openHAB by using curl via openHAB RESTful API
I think I’d rather keep the functionality on my local machine (so it would for example keep working if the internet connection is down).
Would it not be better to use my already running MQTT instead of REST? How would you do it exactly, publish the data? And what to do with it afterwards?
I think it’s actually working with the GPIO binding.
Now for the calculation and graphing. I guess I will have to for example use a counter to count the interrupts, then use some kind of cron job to calculate the “current power consumption” for example every minute, store that in a number item and then store that value somewhere (RRD4J?) and also use that to get a graph of that data. Any more suggestions?
var Number gpio3InterruptCounter = 0
var Number tmp = 0
rule "GPIO Pin3 interrupt"
when
Item GPIOPin3 received update CLOSED
then
gpio3InterruptCounter = gpio3InterruptCounter + 1
end
rule "Cron job every minute"
when
Time cron "0 0/1 * * * ?"
then
var Number diff = gpio3InterruptCounter - tmp
tmp = gpio3InterruptCounter
postUpdate(Nibe_Tick_Counter_Electric_Meter, diff)
diff = diff / 16.6667
postUpdate(Nibe_Power_Consumption_Mean_Minute, diff)
end
Don’t ask me why I have to divide the interrupt counter by 16.66667… somehow that seems to be giving me the connect values.
I then use Grafana to display that item, which is “persisted” in a influxdb database (the yellow graph is the power meter of my heat pump):
Not sure what could be the problem. What GPIO pins did you connect your meter to? I connected my cable to the pins (Pin#5 / GPIO03 and Pin 09 / Ground) in the screenshot below.
Number Heizung_Tick_Counter_Electric_Meter "Heizung_Tick_Counter_Electric_Meter"
Number Heizung_Power_Consumption_Mean_Minute "Heizung_Power_Consumption_Mean_Minute"
Number Lueftung_Tick_Counter_Electric_Meter "Lueftung_Tick_Counter_Electric_Meter"
Number Lueftung_Power_Consumption_Mean_Minute "Lueftung_Power_Consumption_Mean_Minute"
my s0_counter_heizung.rules (same as for ventilation with PIN25)
var Number gpio17InterruptCounter = 0
var Number tmp = 0
rule "GPIO Pin17 interrupt"
when
Item GPIOPin17 received update CLOSED
then
gpio17InterruptCounter = gpio17InterruptCounter + 1
end
rule "Cron job every minute"
when
Time cron "0 0/1 * * * ?"
then
var Number diff = gpio17InterruptCounter - tmp
tmp = gpio17InterruptCounter
postUpdate(Heizung_Tick_Counter_Electric_Meter, diff)
//diff = diff / 16.6667
postUpdate(Heizung_Power_Consumption_Mean_Minute, diff)
end
and in sitemap:
Frame label="Wärmepumpe (ebus)" {
Text item=Vorlauf label="Vorlauf: [%.0f Grad]" icon="none"
Text item=Ruecklauf label="Rücklauf: [%.0f Grad]" icon="none"
Text item=Temperatur_Warmwasser label="Temperatur Warmwasser: [%.0f Grad]" icon="none"
Text item=Druck_Heizkreis label="Druck Heizkreis: [%.0f bar]" icon="none"
}
Hi, i changed to PIN3. After Rebooting the Raspi i got following Message in the Log file:
2017-12-23 14:51:30.082 [ItemStateChangedEvent ] - GPIOPin3 changed from OPEN to CLOSED
2017-12-23 14:51:30.145 [ItemStateChangedEvent ] - GPIOPin3 changed from CLOSED to OPEN
My sitemap is showing 0 Watts - i think GPIO is working now?
Is my sitemap definition wrong (Post above)?