HI,
I was linked to this project a while ago when I was first planning on using a Pi to monitor the flashing LED on my power meter but couldn't see an easy way to do it directly, without an 'emonTx' node. I managed to get the Pi graphing the power usage using some code from https://github.com/yfory/power but the graphing wasn't great and only worked for the current day.
At this point I came back here to see if there was any way to get the data into EmonCMS, I didn't find anything so I started playing around with the API and realised how easy it would be!
I've got my Pi up and running now logging data from the power meter directly, it counts the pulses over 60 seconds, converts it into a wattage and sends it via JSON to emoncms. I figured someone else might find this useful so I've put the code on github for easy access.
I'm not a programmer and the code's not exactly elegant but it works nicely, if anyone has any improvements I'm all ears!
Here's the code: https://github.com/kieranc/power
For an extra bonus, here's a picture of the circuitboard attached to the power meter:
https://www.dropbox.com/s/24ybv1xr6xdtsu8/2013-02-09%2015.31.19.jpg
Maybe I'll work out a better way of attaching it one day... :)
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Many thanks, - Love the clamp !
I used a reflective IR (on a gas meter)
http://farm4.staticflickr.com/3195/3127811725_326b94485e_b.jpg
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Thank you for sharing this.
The clamp definitely rules.
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Thanks for the code! I'm using a variation on this with an LDR and edge detection of the pulse in python, but it seems to work fine. :)
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
I could not for the life of me get edge detection to work in python. As far as I could work out the new kernel patch which enables interrupt handling breaks python's ability to receive them. Is your pi up to date?
See here: http://code.google.com/p/raspberry-gpio-python/issues/detail?id=9
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Well, when I say "edge detection" what I mean is to "detect" the edge of the incoming pulse. I have the LDR connected to an Arduino Nano, and from there to USB on the RPi. The Arduino spits out any values lower than 1000 (out of a max of 1024) via serial, which Python listens to in a loop. So all I do is set a bit when the incoming light value drops lower than a threshold (in my case 980), and then when the light values goes *above* that threshold, register the pulse.
So it's really a poor mans way of detecting the trailing edge of a light pulse from the resistor. But, other than my RPi crashing once per day, it works pretty much perfectly for detection from my meter. I can share the code you if want to see it, but it's very basic. :)
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Ah fair enough, I wanted to avoid a perpetual loop on the Pi, it has little enough CPU power as it is!
The arduino is more than capable of detecting a falling edge quite easily, but it's also not really a problem having it run in a loop continually, it has nothing else to do.
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Yeah unfortunately in order to read the serial I pretty much have to run in a perpetual loop (in python), although it doesn't use up that much CPU. Eventually I'd like to use both the Arduino and the RPi in combination to read and detect everything in my house, so the inputs would be wired to either one depending on usage. I could probably move the edge detection from Python into the Arduino sketch actually, since right now it's just spitting out everything via serial, but this is outside the topic of this particular thread. :)
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
I've only recently come across this community, but I'm excited to get started building my own monitoring systems. I have a pulse meter for my incoming electricity and another pulse meter for my solar generation. Both these boxes are situated next to each other and it would be great if they could be monitored directly into the Raspberry Pi (I can situate this alongside the meters too)
However, I have no idea what components I need or whether this is even possible. Could you point me to the best place to find out this information?
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
I've been trying to coax this information out of the forums and experimenting on my own for the last week or so. The information presented here, along with any ideas and advice would be appreciated. My intent was to run a C++ script and the GPIO libraries of WiringPi to detect the pulses and send the resulting data to Emoncms.
So far, not a lot of help has been offered, and I'm finding the learning curve on setting up Emoncms to be a bit of a challenge.
If you have interest, I'd be more than happy to share my progress via this topic thread.
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
It would be great to hear your progress so far. I'm starting to get an idea of what I need, and I don't think I'll be using the optical pulses, but rather use a clamp round the cables. It seems that gives a more accurate result?
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
I don't think that there is anything more accurate than the pulses that a revenue-grade utility meter uses to track the power through it's registers. Having said that, there may be reasons you would want to use current transformers and voltage sampling for your system. Direction of energy delivery may be one of them.
In my case, I'll be using logic from the meter directly, not sensing the blinking of an irLED. I'll have access to the direction logic and can use that in the calculations to add, subtract and otherwise process the numbers I need for display.
If your meters have some method of displaying whether they are importing or exporting, along with the pulses, then you may want to continue with your original design. A CT-based system will use the phase relationships of the detected current and voltages to integrate the energy direction and calculate the power delivered. There is no reason that it will be significantly less accurate than the utility meters. although overall, I think it is somewhat more work to build, install, calibrate and maintain than one which uses the logic directly.
One advantage of the CT-based system is that you will get more granularity in your resulting readings, making for smoother graphs and displays. Direct readings from pulses are always going to be in one watt-hour steps, and any power displays will be calculated from that last watt-hour, not the current level (if that's important).
Another is if you are interested in power factor and real-vs.-apparent power calculations.
Overall, I'm mostly interested in keeping track of power generated-vs-power consumed, and at the end of the day (and month) whether I bought power from the utility or added to my net energy credit to be consumed another day.
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Hi,
I'm trying to get this to work with the recent read-only raspberry pi images.
When I start the monitoring script I get told that no handlers could be found for the logger.
Is anyone else able to get it to work / involved in a working way of routing pulses to emoncms?
Cheers
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Hi,
I'm planning to use Raspberry pi to monitor and send information about the energy consumption to consumers via SMS or email.
Please, advice me on how should I proceed!!!
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Hi forum
can anyone explain where i have gone wrong, i have i install log, this is of a fresh image and the code is from the link at the 1st entry https://github.com/kieranc/power
pi@emonbase ~ $ rpi-rw
Filesystem is unlocked - Write access
type ' rpi-ro ' to lock
pi@emonbase ~ $ sudo apt-get install python-dev python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version.
python-pip is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 29 not upgraded.
pi@emonbase ~ $ sudo pip install apscheduler
Downloading/unpacking apscheduler
Downloading APScheduler-3.0.3.tar.gz (74Kb): 74Kb downloaded
Running setup.py egg_info for package apscheduler
Downloading/unpacking setuptools>=0.7 (from apscheduler)
Downloading setuptools-18.2.tar.gz (630Kb): 630Kb downloaded
Running setup.py egg_info for package setuptools
Downloading/unpacking six>=1.4.0 (from apscheduler)
Downloading six-1.9.0.tar.gz
Running setup.py egg_info for package six
no previously-included directories found matching 'documentation/_build'
Downloading/unpacking pytz (from apscheduler)
Downloading pytz-2015.4.tar.bz2 (157Kb): 157Kb downloaded
Running setup.py egg_info for package pytz
Downloading/unpacking tzlocal (from apscheduler)
Downloading tzlocal-1.2.tar.gz
Running setup.py egg_info for package tzlocal
Downloading/unpacking futures (from apscheduler)
Downloading futures-3.0.3.tar.gz
Running setup.py egg_info for package futures
Installing collected packages: apscheduler, setuptools, six, pytz, tzlocal, futures
Running setup.py install for apscheduler
Found existing installation: distribute 0.6.24dev-r0
Uninstalling distribute:
Successfully uninstalled distribute
Running setup.py install for setuptools
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin
Running setup.py install for six
no previously-included directories found matching 'documentation/_build'
Running setup.py install for pytz
Running setup.py install for tzlocal
Running setup.py install for futures
Successfully installed apscheduler setuptools six pytz tzlocal futures
Cleaning up...
pi@emonbase ~ $ sudo apt-get install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
git is already the newest version.
git set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 29 not upgraded.
pi@emonbase ~ $ git clone https://github.com/kieranc/power.git && cd power
Cloning into 'power'...
remote: Counting objects: 83, done.
remote: Total 83 (delta 0), reused 0 (delta 0), pack-reused 83
Unpacking objects: 100% (83/83), done.
pi@emonbase ~/power $ ls
gpio-irq-demo.c monitor.py power-monitor README.md Schematic.jpg
pi@emonbase ~/power $ sudo cp power-monitor /etc/init.d/
pi@emonbase ~/power $ sudo chmod a+x /etc/init.d/power-monitor
pi@emonbase ~/power $ sudo update-rc.d power-monitor defaults
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'power-monitor' missing LSB tags and overrides
pi@emonbase ~/power $ gcc gpio-irq-demo.c -o gpio-irq
pi@emonbase ~/power $ sudo /etc/init.d/power-monitor start
Starting power monitor...
pi@emonbase ~/power $ python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
sudo /home/pi/power/power-monitor start
Starting power monitor...
pi@emonbase ~/power $ python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
sudo /home/pi/power/power-monitor start
Starting power monitor...
pi@emonbase ~/power $ python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
sudo /home/pi/power/po
pi@emonbase ~/power $ sudo /home/pi/power/power-monitor start
Starting power monitor...
pi@emonbase ~/power $ python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
pi@emonbase ~/power $ cd\
>
pi@emonbase ~ $ sudo /etc/init.d/power-monitor start
Starting power monitor...
pi@emonbase ~ $ python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
cd /etc/init.d/
pi@emonbase /etc/init.d $ ls
alsa-utils ifplugd ntp sendsigs
apache2 kbd ntp-backup single
bootlogs keyboard-setup plymouth skeleton
bootmisc.sh killprocs plymouth-log ssh
checkfs.sh kmod power-monitor sudo
checkroot-bootclean.sh lightdm procps sysstat
checkroot.sh mosquitto raspi-config triggerhappy
console-setup motd rc udev
cron mountall-bootclean.sh rc.local udev-mtab
dbus mountall.sh rcS ufw
dphys-swapfile mountdevsubfs.sh README umountfs
emonhub mountkernfs.sh reboot umountnfs.sh
emonPiLCD mountnfs-bootclean.sh redis-server umountroot
fake-hwclock mountnfs.sh rmnologin urandom
feedwriter mtab.sh rpcbind x11-common
halt mysql rsync
hostname.sh networking rsyslog
hwclock.sh nfs-common screen-cleanup
pi@emonbase /etc/init.d $ sudo power-monitor start
sudo: power-monitor: command not found
pi@emonbase /etc/init.d $ sudo su
root@emonbase:/etc/init.d# sudo /etc/init.d/power-monitor start
Starting power monitor...
root@emonbase:/etc/init.d# python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
root@emonbase:/etc/init.d# reboot
Broadcast message from root@emonbase (pts/1) (Thu Aug 20 19:13:34 2015):
The system is going down for reboot NOW!
root@emonbase:/etc/init.d# Connection to 192.168.1.94 closed by remote host.
Connection to 192.168.1.94 closed.
Justins-MBP:~ justin$ ssh pi@192.168.1.94
pi@192.168.1.94's password:
Linux emonbase 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
pi@emonbase ~ $ rpi-rw
Filesystem is unlocked - Write access
type ' rpi-ro ' to lock
pi@emonbase ~ $ sudo /etc/init.d/power-monitor start
Starting power monitor...
pi@emonbase ~ $ python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
pi@emonbase ~ $
pi@emonbase ~ $ sudo /etc/init.d/power-monitor start
Starting power monitor...
pi@emonbase ~ $ python: can't open file '/root/power/monitor.py': [Errno 2] No such file or directory
pi@emonbase ~ $
pi@emonbase ~ $ cd /home/pi/power
pi@emonbase ~/power $ sudo python monitor.py
Traceback (most recent call last):
File "monitor.py", line 32, in <module>
from apscheduler.scheduler import Scheduler
ImportError: No module named scheduler
pi@emonbase ~/power $
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
I got to same point, got round it by uninstalling apscheduler and reinstalling an earlier version 2.1.2 under sudo.
still having problems getting it to run though.
steve
Re: Direct monitoring of power meter pulse using Raspberry Pi & an LDR
Some time ago there was activity in this thread.
Did you guys get anywhere on this?
Is there any nice, simple way to get pulse counting running on the Pi direct and post it to emoncms?
//GF