OpenEnergyMonitor Community

Project emond: Energy monitor light

Looks like someone missed the discussion on the old forum so I am opening a new one here.

The basic idea of emond is to implement a low cost Smart Energy Monitor based on the RaspberryPi and use EmonCMS as server backend.

In short, emond is a simplified version of a combination of the emonTX, emonGLCD and emonBase modules. Everything runs on the RPi, no custom hardware required. All you need is an energy meter with pulse (SO) output and (optionally) an LCD display.

The device software I developed interfaces with the EmonCMS server where the data processing can be done just like with any other OpenEnergyMonitor project. The software is written in the good old C language.

These are the main features:

  • Instant power measurement using energy meter pulses
  • Daily and monthly energy calculation
  • Periodic saving of energy counters to persistant storage and restoring at restart
  • Filtering of short glitches and false pulses on the pulse counting GPIO line
  • Display of measurements on local LCD display (via integrated lcdproc client)
  • Transmission of measurements to EmonCMS (via WebAPI)
  • Full compatibility with “My Electric” appliance in EmonCMS and Android app
  • Easy customization of parameters via configuration file
  • Configurable WebAPI update rate limit

The source code and documentation is available on the Github emond page.

I started this project to play with the EmonCMS API and found it quite easy to get data into the system and process it later on the server. So with a simple energy meter at hand, the pulse counting and power calculation code was quickly done and I could start monitoring my electrical energy consumption from a web browser (and later also smartphone app). This system has been running at my home for more than 2 years now and it is working great for me. If time permits I would like to add multiple energy meter support and also support flow meters with pulse output (water, gas).


Great work, many thanks Ondrej! I use it to monitor my electricity consumption with a TSL250R to detect the pulse from the meter. Two minor changes to the code were needed: percentage deviation of pulse width does not work for short pulses (in my case 4 ms), so I set it fix to 1 ms. And the sensor is active high vs low in the code.

As this is an elegant and slim solution, I like the idea of attaching the pulses from the water and gas meters. Did you already venture into this?

Many thanks for this great code


Hi Marcus, thanks for your feedback. It’s always nice to hear that this software is also useful to others.

Active high/low pulse could be made configurable in emon.conf. The problem with pulse length deviation detection for short pulses is probably a rounding issue. I should have a look into this.

Unfortunately I am too busy at the moment with work and family to dedicate time to this. Last year I bought this cheap Liquid Flow Meter to measure the water I am using to water my garden, but I still have to install it. :flushed: When this is done I will have a look at adapting emond to flow meters. I think that the “false/spurious pulse” detection has to be disabled for these because flow meters don’t generate pulses with a constant length.

But if you want to give it a try yourself, code contributions are always welcome.


Cheer for the rapid feedback! Coding in C is not really my thing (I mostly use C# in VS) but I’ll give it a try by forking your code on GitHub. The idea is to flexibly scaling it up, e.g. by defining arrays for the relevant variables and adding more config params like unit, pulse level and de-bounce time. Since my water and gas meters are already equipped with counter outputs I have a good testing environment… :slight_smile:

Will report back on progress


Would like to first thank Ondrej for the great integration. Ive been using it on and off for few years now but with current electricity prices in Europe i started to set it up again for myself.

One thing i did try to add is hourly consumption here

Not knowing anything about C i am not sure if i did it correctly but some data is coming in to emoncms.

But i have this one error popping up “Error performing Web API request: return code=3”

I have 3 energy meters, 2 are the same make, 1 is an older one.
First started having this error only for one energy meter which is an older type than the rest but probably this would not matter.
Now this error is coming on all 3 and looks like it is related to the changes i did to add hourly consumption and it is happening when there is higher power usage, like switching on 1kW coffemaker etc.
Could it be related to some buffer running full or similar?
Any ideas how to mitigate it, maybe changing api update rate?

Hi Reigo,

to investigate this issue start by looking closer at the error message you get:

Error performing Web API request: return code=3

This is generated in webapi.c after calling curl_easy_perform(). According to libcurl documentation error code 3 means “The URL was not properly formatted.”

So you should look at the URL emond generates before passing it to curl_easy_perform() by enabling debug mode. This will print out urlbuf and it will surely give you a hint of what went wrong.

Thank you for the hints Ondrej.
Enabled debug in webapi. And got some results. At first all good.

Sending request: http://emonpi.local/input/post.json?apikey=&node=1&json={power:267,energy_hour:39,energy_day:12839,energy_month:12839}
Received response (2 chars): ok
Sending request: http://emonpi.local/input/post.json?apikey=&node=1&json={power:267,energy_hour:40,energy_day:12840,energy_month:12840}
Received response (2 chars): ok
Sending request: http://emonpi.local/input/post.json?apikey=&node=1&json={power:264,energy_hour:41,energy_day:12841,energy_month:12841}
Received response (2 chars): ok

Here i switched on some high power device and only difference is with power value.

Not ready to send Web API request
Not ready to send Web API request
Not ready to send Web API request
Sending request: http://emonpi.local/input/post.json?apikey=&node=1&json={power:1451,energy_hour:45,energy_day:12845,energy_month:12845}
Error performing Web API request: return code=3
Received response (2 chars): ok
Not ready to send Web API request
Not ready to send Web API request
Not ready to send Web API request
Not ready to send Web API request
Sending request: http://emonpi.local/input/post.json?apikey=&node=1&json={power:1451,energy_hour:50,energy_day:12850,energy_month:12850}
Error performing Web API request: return code=3

And after switching it off the error went away.
Maybe adding the hourly consumption variable i should also raise these values below? My thinking is maybe the url is now exceeding some limit.

   char urlbuf[128];
   char params[128];
   char json[64];

There is your answer: {power:1451,energy_hour:50,energy_day:12850,energy_month:12850} is exactly 63 characters, add one for the terminating NULL or two for cr-lf, and you’re in trouble with a buffer overflow.

The complete URL is 119 characters - OK, but a bit too close for comfort. Add your apikey (32 characters) and there’s a problem there too.