New version of the Fusion sketch

Hi everyone,

Some of you may be familiar with the old "Fusion" sketch which I wrote some time ago. For those of you who haven't read about it my idea was to take Robin's MKII sketch and fuse it with the energy monitor and to send the results to an emonGLCD display. 

The original version had a number of correlation issues with some of the other methods and, as a consequence, I rewrote it and achieved a much better correlation. The sketches associated with this new version were published some time ago.

In the past few weeks I have been working upon the sketches once again. I wanted to extend the capability and be able to read the infra red pulse output from the Elster AC100 meter. Sadly, I didn't get that working. Instead, I decided to add additional temperature monitoring capability and to also add a feature whereby the results could be sent to the web.

The picture below shows the output on the GLCD display. The bold numbering is the grid power, the smaller numbering is the solar power (on a wet Monday afternoon) and the four temperature outputs are shown on the right hand side of the display. "3600" is the energy bucket and the black spot shows a net import of energy. This changes to a heating coil when the PV dump is running and a white ring when the tank is full of hot water.

All of the old features are retained: LED's that turn from red (importing) to green (net export) and a combination of the two when heating the water). The LED's turn off under low light conditions but maintain a heart beat each time data is received from the emonTX.

I have added a Nanode RF SMT to the hardware and have modified an existing sketch so as to take the emonTX data and route it through to emoncms. I have been working upon a dual transmitter to emoncms and to cosm but have yet to get this operational. Rather than continue I wanted to publish what I know works OK.

My feed is directed to emoncms and I have configured a dashboard as shown below. It's a promising New Years Day morning and my wife has been cooking breakfast. We can see the griddle on the oven pulsing on and off while the kettle is simultaneously boiling (my contribution to breakfast is making the tea). The displays at the top show real time visualisations of grid and solar power together with the energy bucket and the top and bottom temperatures of the water tank. The probes on the tank are not invasive so give only an indication of temperature rather than what will come out of the shower. Lets hope that the PV dumper increases the temperature of the water tank. 3 degrees C is the outside temperature on the front of the house.

I also have dials which show the grid and solar power for the day. These normally reset at midnight.


The bottom of the display shows a zoom of grid and solar power on the left hand side and bar charts day by day on the right.

The cms display was written using the web site tool. If anyone is interested, there are probably ways to share the code or the framework of the tool.


Shown below is the schematic. There is a minor modification from the previous one in that the IO lines for the red and greed LED's are switched around. The rest is as before.


Should you wish to add temperature sensors beyond the one in the GLCD, you can add them and simply plug them into the temperature sensor port. The software will look for up to three of them.

The emonTX sketch has undergone a huge amount of change: as I mentioned before, the measurement algorithm has been reworked so as to comply with the OEM published versions. It runs over a six second window with a minor jump out to sum the results and send them into the wireless network. The MKII sketch runs in the background and in tandem with the energy monitor.

I did some trials to speed up the code. I took it about as far as it would go without resorting to integer mathematics. If I am honest, I found that speeding the code (taking more samples per mains cycle) didn't make very much difference beyond a certain point. Just to be sure, I ran some trials in VBA using various amounts of under sampling of waveforms with varying amounts of distortion and my simulations yielded the same conclusion: it doesn't make that much difference, to my mind at least.

So, what we have is reasonably slim code which draws upon some of what Robin has done together with what else is needed to measure solar channels and the odd temperature here and there. We can turn off un required features such as LED displays, apparent power calculation, transmission to the GLCD, power displayed on the serial monitor, etc. if we want to make some bits quicker. Best to play around a bit and see what suits.

What else is in there?

This version of code includes a simulator whereby the user can generate voltage and solar and grid currents with any amplitude and phase offset. A useful tool to debug code without needing transformers or a solar energy system. 

There is also a feature to sweep phasecal independently of the grid and solar channels. This is a useful feature to allow you to characterise the phase lead/lag or each channel and work out which one correlates best with your reference.

If you use the emoncms software there is a mode where fixed data can be sent from the emonTX to the base station (and on to the web) so as to allow you to unravel which node id is which.

I've also added a feature which allows the solar offset error to be removed from the transmitted data. It's really tough to get accurate power measurements on each channel across a wide spectrum of power. What is accurate at one end may be off at the other. With this feature, power which is repeatable but below a certain threshold is considered an offset error and a solar power value of zero is transmitted in the RF.... a kind of additional switchable high pass filter.

There's a load of other stuff which helps with the debugging as well: seeing all samples captured, seeing the energy bucket content periodically and the raw power calculation results. Most of this probably wont be needed... but is there just in case.

In terms of accuracy, I have run this against the usual loops of wire

and plug in energy monitor. It stands up pretty well against both of these for resistive loads and equally well when the power factor drops with some garage machines. It isn't quite as good when clamped around the power cables on the consumer unit as it's still a little off compared to the enviR monitors. Perhaps a little more calibration is in order... another day!


If somebody can show me how to make my cms dashboard public I will gladly share it!

Anyway, feel free to having a play, code should be included at the end...



MartinR's picture

Re: New version of the Fusion sketch

Looks good Ian.

I had a similar issue with the hot water temperatures reading 15-20 degrees below the real water temperature when the sensors were on the outside of the tank. In the end I managed to get the sensors into the thermostat tubes for the immersion heaters and now they read correctly (I assume!). Only works if you have top and bottom immersion heaters though.

Series530's picture

Re: New version of the Fusion sketch

Hi Martin,

I'd seen your post in that regard and took the immersion heater apart. It was a tough call to get anything down the tube of ours and we only have a single heater anyway. In the end I have attacked them to the outside of the tank with copper tape and then wrapped insulation over the top of them. It does something of a job and indicates a trend if nothing else.


PaulOckenden's picture

Re: New version of the Fusion sketch

Shame you couldn't get the Elster reader working. I'd imagine a lot of us have that particular meter installed.



MartinR's picture

Re: New version of the Fusion sketch

It was a bit of a squeeze, I think they are probably a standard size as all the thermostats seem to be the same. There was just enough room at the end of the tube for the DS18B20 so I attached 3 very thin wires that would just go between the thermostat and the outer tube.

Series530's picture

Re: New version of the Fusion sketch

Hi Martin,

I bought the external versions of the temperature monitors and this adds a metal cap and some water resistant wiring. I did consider pulling them apart but it would have been a cross fingers and hope that I didn't break them. Even then I would have had an issue dealing with the lower stat - no place to put the monitor.


Hi Paul,

The fact that I could get the Elster working frustrates me just as much as it does you. Goodness knows I tried all kinds of ways. I was working with Dave Berkeley's Elster sketch and the moment I tried to un attach the interrupt on the reader it simply would not come back. Suggestions, if anybody has some, are very welcome.


calypso_rae's picture

Re: New version of the Fusion sketch

Hi Ian,

To get the correct value for Power Factor, I think you need to change the voltage term in this line:

              sqV= filteredV * filteredV;                 //1) square voltage values

to the relevant phase-shifted equivalent.  This will then be the same value as is used in your instP calculation. 

This is a long-standing emonLib bug which has been recently highlighted on another thread.  The code in my phasecal checker tool is correct in this regard.  You should be able to use this tool on your current sensors to establish the optimal phasecal value for each of them. 

For each sensor, there will hopefully be a phasecal value which gives a PF close to 1.0 when using the tool.  With this same PC value, your standard sketch should display a similar PF value when a resistive load is applied.  For this to occur, the same voltage term needs to be used throughout ;)



Series530's picture

Re: New version of the Fusion sketch

Thanks for that information Robin. It may explain a number of peculiarities that I have always seen and never quite figured out while running code from this site. 

I have a phase cal checker tool built into my sketches. I just need to enable it and sweep through. it uses the same code as the measurement algorithm. It will be interesting to see what effect the correction has upon the results that they give.

BTW, I now have a simultaneous feed to emon cms and Cosm working and will update this and correct and retrial the VI sections of the sketches later today.


nbown's picture

Re: New version of the Fusion sketch

It's working a treat, much closer for the figure i been seeing


I'm just going to try to add the temp output from the GLCD to the emoncsm


Thanks again

Series530's picture

Re: New version of the Fusion sketch

I enabled the option to measure KVA yesterday and sent the vrms value of the mains to emoncms. When I did this I discovered that my VCAL value was well off (I've had KVA turned off for some time now so didn't notice the problem).  I've now corrected this cal value for my sketch and will continue to monitor it against a plug in energy monitor.

Correcting this error pulled the results in nicely - we're now within 2.6% of the enviR at 460W of grid power and about 4% when up around 3.5KW and this is broadly in line with what I expect to see. I may try a phasecal sweep at some point just to be 100% sure that I am using the right numbers.


My emoncms dashboard can be seen here :


I have no idea how a user can pick up my feed information or integrate this into their own dashboards.


I also decided to dump the link to cosm on the nanodeRF sketch. I was finding an occasional hang and the only way around it was a reboot by pulling the nanodeRF power. I've reverted to using the GIThub sketch with a few mods for my apikey and some twinkly lights so that I can see what is happening.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.