Monitoring Solar Consumption With A ESP32/8266 and LED Lights


Since having a PV (Photo Voltaic) solar array installed on my roof earlier in the year I have become a more aware of the energy consumption of my house.

In my post ‘Making Data Driven Decisions With A PV Array, Home Assistant and MQTT‘ I am leveraging consumption data to make decisions in my house, and this has only continued since the time I authored this post.

But, I often ask myself 2 simple questions at home

  1. How much power is my house generating?
  2. Is electricity free? In another words, am I exporting to the grid and if so, how much?

Both of these questions I can answer, but it involves either using a phone or laptop leveraging some customer Home Assistant Lovelace cards I made.

Home Assistant LoveLace Card – Custom gauges for ‘Grid Feed In’ & ‘PV Generation’

Is there a way I could understand this without the need of my phone or laptop?
Yes, there is! Tri-Colour Emitting Diodes or RGB LED’s

In this post I am going to illustrate how with less than $30AUD worth of parts you can visualise power consumption in your solar array in the form of lights that change colors.

Worth noting, in order to visualise consumption and feed-in, you will need to have a means to measure this. I am using a SMA Energy Meter to measure, but the same principal applies to any solar PV system.

This article will illustrate how to
– Push messages from Home Assistant to a MQTT Topic via MQTT StateStream
– Leverage an Arduino compliant MCU (Microcontroller) to read messages from a MQTT topic
– Drive RGB LED’s based on the values of MQTT Topics

Bill of Materials
– 2 x 5MM 4Pin RGB Tri-Colour Emitting Diodes Common Anode/Cathode LED Lights ($5 AUD for 10)
– 1 x Wemos D1 Mini/Mini Pro 16MB ESP8266/ESP12 WiFi NodeMCU ($7 AUD)
– 6 x 300ohm resistors ($3 AUD for 50 units)
– 1 x length of heat shrink ($3 AUD)
– 22 gauge cable between Wemos and LED’s, approx 5m ($3 AUD)
– Plastic transparent plugs ($2 AUD)

Total Cost = $23

Tools used
– Soldering Iron
– Drill and drill bits

An RGB Back Story – How do you make colours?
With RGB LED’s containing 3 channels using PWM or Pulse Width Modulation allows the MCU to adjust the duty cycle to the LEDs so we can get the desired colors. This is very similar to a HTML colour code, these 3 values in effect allow you create a variety of colours.

PWM-and-Color-Table




Step 1: Gather a Suitable MicroController
I choose rather than running cable from my telco rack to use a dedicated MCU. An ESP8266 / ESP32 are my devices of choice in these applications. Cheap, have WiFi and are Arduino compliant.

I am using a Wemos D1 Mini. It has enough I/O for my 2 LED’s and speaking of LED’s these are 4 pin RGB Tri-Colour diodes, meaning with PWM (Pulse Width Modulation) allowing myself to vary the intensity of any given LED from 0-255, there is an ability to make almost any color.

Wemos D1, a LED and my wedding ring for a size reference.

Step 2: Wire everything up

Each LED has 4 legs, the longest leg, being the cathode to ground.
Solider the anode to ground and for each leg, put in-line a 300ohm resistor. Because the ground is common, this can be looped from one LED to another. I use heat shrink over ever solider connection and then use a cable sheath to give that neat look

10PCS 5mm RGB LED Common Cathode 4pin Red Green Blue LED Round Tricolor LED  Light Emitting Diode 5 mm Tri Color Transparent|Light Beads| - AliExpress



PWM-and-Color-Table
howtomechatronics.com/tutorials/arduino/how-to-use-a-rgb-led-with-arduino/
Tutorial IoT Wemos ESP8266 Kontrol LED RGB Firebase
Soldiering each RGB LED with a 300ohm resistor
The finished LED hardness.

On the Wemos side I had decided to solider a trip of headers for the PWM outputs but soldiering directly on the board for the ground. Why, no real reason, and I probably would have solidered directly on to the PCB next time round, given it keeps the profile lower.

Meaure twice, drill once. Note the desk does taper out. It is 100% square to the edge.

Insert the LED hardness and get to coding. Right now we have wired this up physically but there is no code to either drive the LED’s or to read data from my Smart Meter / Home Assistant.

Leave a Comment