RAVEn to MQTT over wifi

Saturday, July 10th, 2021 at 1:29 pm

I have written before about how I use a Zigbee dongle (the now discontinued RAVEn from Rainforest Automation) to get power consumption information from my smart meter. A bit over two years ago I also wrote about how it appeared that a failing power supply was interfering with the Zigbee connection and also confusing my UPS.

I think that my logic still holds for the UPS issues, but now I think I was wrong about it interfering with Zigbee…

Things improved when I rewrote my script to use a proper serial port library and then improved even more when I started to use that library correctly. However recently I noticed that there were still some gaps appearing in the power usage data, so I had another look.

My first action was to further cleanup my script so it both made more sense and to also report on more messages. I was only caring about InstantaneousDemand which is sent every 8 seconds, but it also often sends CurrentSummationDelivered and ConnectionStatus which I was ignoring.

Once I started logging ConnectionStatus I thought I might be seeing a pattern. At the times (for an hour or so every few days) that I stopped getting InstantaneousDemand messages, all that it was getting were ConnectionStatus messages, and the LinkStrength values were around 60 or 70, not the 100 it normally way.

So was something still interfering?

I couldn’t spot a regular pattern in the dropouts so I had no idea what possible interference there might be. The information about the RAVEn and other smart meter in-home displays mentions that placement of the device is important as Zigbee is low power. I had the RAVEn plugged into the back of my linux box which placed it about 10 metres from the smart meter with walls, furniture and the metal case in between. So what if I simply moved the RAVEn closer?

I had a long USB extension cable so it didn’t take long to relocate the RAVEn to be about 4 metres closer and not directly behind a metal box. After a week in this position I found that there was still the occasional reconnection, but nothing like the hours of no InstantaneousDemand messages that I was seeing before.

I could have just left the USB extension cable in place, but I didn’t like how it looked and didn’t want to add it to the mess of cables under the desk.

The RAVEn is a USB device that provides a USB serial port, on that port are XML messages. My script takes those XML messages and writes them to MQTT as JSON. Is there something else that I could plug the RAVEn into to do this, something that I can place close to the smart meter?

I’m a fan of using ESP8266 devices in the D1 mini form factor for my current home automation. Could I use one of these to build a RAVEn to MQTT bridge over wifi? Maybe, but with some caveats and possibly some effort and delay waiting for parts.

Other Arduino based options seemed just has hard so I turned to the old Raspberry Pi I had sitting around. I had previously used this to test out Kodi so I instead loaded up Raspberry Pi OS Lite and quickly found that I could transfer my existing perl script over, tweak it a little bit, and have it working.

The next hurdle with this as a solution was that it used wired ethernet and I don’t have wired ethernet in the room near the smart meter, I would need wifi if I wanted to have the RAVEn as close as possible.

What would it take to add wifi to this Pi? A USB wifi adapter can be used, but which one and how much would that cost? Would a cheap $8 adapter work, or would I have to get a $50 adapter? As well as not working, it might take a while for a cheap adapter to be delivered.

What about a newer Pi that included wifi? The Pi 3 B+ that I am using for Kodi has wifi even though I am using it on a wired connection, but that also costs towards the $60 mark, and seems to be out of stock.

Hold on, what about a Pi 3 model A+? This is smaller and cheaper than a B+, it also has wifi and the single USB port is fine for my single RAVEn. An online order and a few days later it arrived and was quick to get functional:

Rasperry Pi 3 model A+ in a Core Electronics Slim Case and a Rainforest RAVEn plugged in to the USB port

I needed a case for protection and liked the exposed look of the slim case from Core Electronics.

This has been running like this for about 36 hours now, taped the wall which puts it about 1 metre from the actual smart meter. Time will tell if this solves the reliabilty issues, but it is looking promising.

Of course this does seem like a bit of an overkill to use a whole Pi for this simple task. I might consider a Pi Zero, but I would need the W version (for wifi) and when you include the USB OTG cable the price is getting closer to that of the A+, and these are sold out everywhere I checked…

The final thing I want to mention today is that after I cleaned up my script I also wrote up some documentation and pushed it up to GitHub:

Just don’t yet look at my other repos as all you will see are two that were created seven years ago, only one of which has any code pushed to it. One of the items buried on my todo list is to clean up and push some of the other things I have written for my home automation setup…

Tagged with: , ,