My home solar energy generation and control system

  • Topic: Electronics 
  • Thread starter nsaspook
  • Start date
  • Tags Tags
    Linux
9 replies · 4K views · last reply
Science Advisor
Messages
1,569
Reaction score
5,242
TL;DR
Solar energy battery hybrid, control system with home assistant
Still working on some aspects of this DIY home energy management system but all of the major parts are operational.
I'm using Home Assistant as the interface to several custom designed PIC 8-bit controllers and a Linux expert system to integrate data into a central MQTT server. It monitors utility energy flows from the utility and locally generated electrical energy into the house to reduce external usage requirements for HVAC, computer processing and general power usage.

Most the the individual devices controlled and monitored in the house use Matter/thread as the connection fabric. Matter version 1.3 has been a great improvement over the original Matter 1.0 devices. Many of the original devices can get firmware upgraded to 1.3. This system is totally local for home device control, with no cloud control or monitoring of the energy devices with the exception of Home Assistant cloud for remote access and control. The cloud access in not needed but it is nice to see what's happening at home from anywhere in the world, securely.

Most of the original build and design is here: https://forum.allaboutcircuits.com/...ge-controller-datalogger.194146/#post-1826013

A few screen shots of the HA main control panel in my home electrical shop.
Monitor showing a Home Assistant energy dashboard in Chrome, with gauges for battery energy, load power, PV power and energy balance, a flow diagram of solar, grid, gas and battery, and a list of energy sources.

Monitor showing a Home Assistant energy dashboard with gauges and tiles: GTI 1, GTI 2 and GTI 3 power, off-grid power, self-sufficiency 6%, DL MPPT current 14.71 Amps, FM80 PV energy 3,679.7 Wh, and Solar Shutdown.

Monitor showing a Home Assistant dashboard in Google Chrome with solar and energy cards, including a PV Power History line graph, Eve Energy readings for current, energy, power and voltage, and a Comedi Trigger tile.

Photo of a monitor showing a Home Assistant dashboard in Chrome, with a pop-up power history graph for an Eve Energy device reading 71.60 W, and a PV Power History chart.


The Linux C energy control system logger.
Screenshot of a terminal window showing a dense table of columns and numeric values, likely a Linux console energy logger output, partly overlapped by a second window at the bottom.


Some of the MQTT JSON formatted data sent to the server from various energy interface device PIC18 controllers.
Terminal window showing JSON-formatted solar charge controller data with fields such as build_date, sequence, runtime, batteryVoltage, pvVolts, and gridIn, beside a column of inverter status lines.
 
  • Like
  • Wow
  • Love
Likes   Reactions: davenn, Rive, dlgoff and 2 others
The system also integrates the home automation and media with local and cloud access to the home AV server, security IP cameras and outdoor garden plant monitors.
Smartphone held upright showing the Home Assistant dashboard, with a camera feed of a lawn and driveway, CO2 readings of 375.0 gCO2eq/kWh and 56.49% grid fossil fuel, and house utility L1 at 2,580.0 Watt.

The Home Assistant Iphone APP running on the house local wireless network.
Screenshot of a phone running a camera app's Overview screen, showing three live camera feeds: a dark blue SUV and a red SUV parked in a driveway labeled 10_1_1_181, a grey car on a driveway beside a lawn labeled 10_1_1_186, and a black-and-white view of a doorway with a grey object, each marked Idle.

Screenshot of the Home Assistant iPhone app Overview screen showing Denon HT Receiver (DISH NET), Roku 2 XD (Roku), 55R646 with power controls, and a Home Theater card playing Artifacts by Steve Roach.

Phone screenshot of a Home Assistant style Overview page listing GW1100B sensors: absolute pressure 30.064 inHg, several soil moisture readings, indoor dewpoint 47.1 °F, indoor humidity 28%, indoor temperature 83.66 °F, relative pressure 30.064 inHg.


One last thing I'm playing with now is voice control using the Home Assistant Voice Preview Edition device.
https://www.home-assistant.io/voice-pe/
We will match and then surpass other voice assistants. Supporting languages that big tech ignores - while being private, open, and fully customizable. Running inexpensively on local hardware.
The voice device and a remote energy monitor (PIC18 Q84 design) running on the home CANBUS network.
Close-up of a green printed circuit board with a white plastic enclosure, a black surface-mount IC, LEDs, a red heat-shrink lead, and a black oscilloscope probe clipped to the board.

Building, testing the PCB and embedded software for the remote energy displays.
Two devices on a wooden desk above a keyboard: a square white voice device on the left and a white-cased blue LCD energy monitor on the right showing 4.1W, 8.3VA, EMon 3879.3Wh, 280.00Hr, 11.48BW, 0.5 Amps, 26.7 Volts.

All of the voice processing is local, no need for cloud server access (optional cloud processing in included with a sub to the HA cloud server, but I don't use it for that) for Speech-to-text. It's local, using faster-whisper processing on the home server and the internal FPGA on the Voice Preview Edition device.
https://github.com/SYSTRAN/faster-whisper


 
  • Like
  • Wow
Likes   Reactions: quarkz, Rive, BillTre and 2 others
....really well done:smile:

Though - based on my personal experiences - at this point you better start to make proper documentation too.
Not much later that these homebrew do-it-all projects reaches the point where they really can do it all and no interaction is needed anymore the owner tends to forget the fine details what keep it tickin' :doh:
 
  • Like
Likes   Reactions: Klystron, Borg and nsaspook
Rive said:
....really well done:smile:

Though - based on my personal experiences - at this point you better start to make proper documentation too.
Not much later that these homebrew do-it-all projects reaches the point where they really can do it all and no interaction is needed anymore the owner tends to forget the fine details what keep it tickin' :doh:
I'm professional electrical engineer with decades of experience building life-safety systems but thanks for the advice about documentation. This is mainly designed first in my head, documented for the build process and corrected with as-built corrections. I know the forgetting process on complicated projects. The entire project is backed up on archive servers (one remote from the main building) in the house and online with details of the software (documented using Doxygen), hardware flowcharts for interconnects, wiring diagrams, from the PCB BOM to the embedded software to C source in great detail. GIT is used to maintain version control of all documentation and software.
Block diagram of a home solar system: solar panels, relay, MPPT charge controller, 24VDC 220AH battery bank, inverter to AC, MODBUS controller, system controller linked by RS485 and RS232 to a remote control, and analog/digital I/O monitor.

Some early design charts.
Block diagram of a home solar energy system showing solar arrays, MPPT charge controllers, LiFePO4 and FLA battery banks, grid-tie inverters, a system controller, Home Assistant, Linux servers for MQTT, and a whole-house energy meter.

You're right, this is about the time to update the design database with the latest changes while they are still fresh in the head.
Block diagram in LibreOffice Draw of a home solar energy system, showing solar panel arrays, MPPT charge controllers, battery banks, inverters, a controller, and AC power connections.

I've got the master book and two grown kids with CS credentials to take over, Right.
 
  • Like
Likes   Reactions: Klystron, russ_watters, BillTre and 1 other person
The complex part of this project is data collection from many devices, all with completely different interfaces and protocols. Lot's of that required reverse-engineering weird, strange, odd-ball data formats, encoding methods, non-standard physical interfaces. All of that data is converted to JSON format for storage and distribution on the MQTT mosquito server process on the home computer center that's mainly powered by the solar energy control system.
Photo of a rack-mounted server and equipment cabinet with dense tangles of blue, white and grey network and power cables, including a rack server, a Yamaha unit and a TP-LINK switch.

Running mainly surplus HPE DL360 and DL380 enterprise servers.
https://www.hpe.com/psnow/doc/c04346229.pdf

Yes, it eats power and needs cooling but the energy control system can reduce that energy usage to near zero in full sun and reduce it by shifting saved battery energy directly into the server at night.
Stacked bar chart titled Individual devices detail usage, plotting energy in kWh against time from Apr 19, with coloured segments for Server Rack Energy, Server UPS Feed Power, Maxwell Aircon, HT Aircon and Untracked consumption.


The first step was getting Solar energy data from the charge controller. FLEXmax Charge Controller is a classic and bulletproof design but has a proprietary data interface. I'm not the only person that's needed to hack the protocol so it was easy to find design information online.

They use a 9N1 proprietary interface protocol that's been reversed engineered several times.
Most of the protocol and interface adapter information came from here.
https://github.com/jorticus/pymate

That software was written in Python so I re-implemented it using XC8 for the PIC18 series of controllers so I can pull important system data for logging to the local system without the expensive and limited Outback MATE remote display that has an ASCII port.
https://www.outbackpower.com/downlo...ment/mate/mate_serial_communicationsguide.pdf
By connecting directly to the charge controller I have complete control and access to the device.

Next step is AC utility power monitoring. For that two devices were used. One device was RS-485 with good documentation, easy
Photo of a Carlo Gavazzi EM540 three-phase energy meter mounted on a DIN rail, its blue LCD showing 0.128 TOT kW h and 0.00 kW, with wiring terminals below.

and the other device is the IAMMETER 3 and 1 phase wireless systems. Very good. I use three of these on the current system. https://www.iammeter.com/
All processing and communications is local with these devices. No cloud access is needed.
Wall-mounted DIN rail panel with a two-pole circuit breaker, terminal blocks, a WiFi energy meter with red and green status LEDs, and a split-core current transformer clamped on a black cable.


So I designed a few prototype 8-bit controller circuit boards and wrote the software in C to integrate the data to a common interface using CANBUS as the backbone.
Bare circuit board with surface-mount and through-hole parts, labelled OS1_10MHZ, 24VDC_PWR, TTL_SERIAL, MODBUS and CANBUS, beside a second unlabelled board, on a wooden table.

REV 1.1 PCB in black and gold, withFM80 interface, TTL serial, CANBUS and MODBUS interface channels with SPI LCD display capability.
Photo of a DIY setup on a workbench: a Mixmoonfree Power Inverter Remote display board, a blue LCD showing an energy monitor readout, two custom PCB boards, and a Microchip MPLAB PICkit 4 programmer connected by wires.

Testing a two board network. LCD screen SCM: FM80 in Sleep mode, Canbus online, Modbus online.
Circuit boards labelled Outback FM Interface v2.1 and CANbus, with a PIC18 microcontroller, optocouplers, status LEDs, a RJ45 socket and multicoloured ribbon cables.

Github software mateQ84 branch for those types of boards: https://github.com/nsaspook/Q84vtouch/tree/mateq84

Source code, schematic designs in Eagle/Fusion360 with documentation.
https://github.com/nsaspook/Q84vtouch/blob/mateq84/mateQ84.X/mate_a_sch.pdf
Source code example in C for the 8-bit controller. https://github.com/nsaspook/Q84vtouch/blob/mateq84/mateQ84.X/main.c
 
Last edited:
This is the last major sub-system. Called the Dump Load controller. This provides for AC-AC hybrid power coupling and energy time-shifting.

It's basically a completely dependent Solar energy system with charge controller, with a separate 5120 Wh battery but without solar panels. The power is supplied by a 1KW switching power supply that gets AC from an off-grid inverter (that also supplies computer rack power) powered from the separate solar panel charged battery 5120 Wh battery.
Close-up of a Mean Well HRPG-1000-48 switching power supply label showing AC input 100-199VAC 11A and 200-240VAC 6.5A, and DC output +48V 17A and 21A, with -V and +V terminal labels.


Renogy Rover Elite 40A MPPT charge controller with blue LCD showing 26.7 kWh, four navigation buttons, and terminal screws labeled with solar panel, battery and polarity symbols.


This is the dump load system controller. Two 8-bit controllers. One controller, a PIC18F1320, talks to the charge controller via MODBUS and shares that data with the main energy controller, a PIC18F47K42.
Open metal enclosure containing a green circuit board with blue capacitors, relays and a white connector, grey and orange ribbon wiring, and a grey DIN-rail style terminal block on the right.

Open metal enclosure containing a green circuit board with blue capacitors, ribbon cables, DIN-rail terminal blocks, and a blue LCD showing LOAD WH, INV WH and a date-time line.

EAGLE PCB layout editor showing a circuit board design titled DUMP LOAD CONTROLLER with red and blue traces, round capacitors, terminal blocks and IC footprints labelled LM2903, PIC18F and LTC6804-style parts.

The main controller monitors the state of charge of its battery and receives/sends control data and information from/to the Linux energy master controller using the system standard MQTT JSON data via Ethernet using a serial port interface.
Photo of a DIN rail inside an enclosure with a black Waveshare industrial isolated serial device server (Modbus gateway) mounted on it, with a blue Ethernet cable plugged into its top RJ45 port and red and blue status LEDs lit.


The main Linux controller looks at the total energy balance between both systems, the incoming solar power, the outgoing electrical energy, the expected total energy collection for that day and decides what to do. First priority is to top off the main energy battery from solar energy, when that's done, energy is directed via the switching PS to the dump load battery. Once those systems are at the calculated needed set-points for the day, solar energy is directed to grid tie inverters to feed AC power into the home.

The home energy flow levels are calculated using standard PID control feedback to keep a slightly negative net balance at full solar power generation, so the batteries are slowly drained until the energy set-points for later power shifting.
Dashboard of home energy monitoring: energy flow diagram linking Low-carbon grid, Solar, Gas, Grid, Home and Battery, plus gauges for Battery Energy 3,757.90 Wh, Energy Balance 67.83 Watts, Load Power 3.90 Watt, PV Power 73.00 Watt, and DL PV Current -0.02 Amps.

Early morning, all power to recharging batteries, positive energy balance. 5120Wh LFP batteries for 5000 to 10000 cycle charge/discharge lifetimes.

Screenshot of a home energy monitoring dashboard showing a bar chart of daily energy in kWh, a flow diagram of grid, home and battery, gauges for load power 1,163.23 Watt, PV power 857.00 Watt and GTI power -900.00 W, and a battery run time gauge of 17.67 Hrs.

Battery near full energy balance.

When the sun sets, the dump load controller is commanded by by the Linux program to return today's stored energy in it's battery pack to the house and the main solar battery is kept in reserve set-point unless the energy prediction (using a Home Assistant solar plugin https://www.home-assistant.io/integrations/forecast_solar/ ) from the next day forecasts we can also use it to dump energy into the house at via it's own grid-tie inverter system to the energy shift set-point.
 
  • Like
  • Wow
Likes   Reactions: Klystron, Rive and BillTre
This is the granddaddy of the current system from 15 years ago. Mainly from surplus parts, left-overs from work projects and decommissioned equipment.
Open control panel with wiring, terminal blocks, relays and a panel meter mounted on a dark backplate, with a blue circular component labelled 3 in the lower centre.

Then
Open grey metal cabinet with a control panel showing analog meters, a blue LCD display, a green circuit board, a white power supply, and dense red and white wiring to relay and terminal blocks.

Now
https://forum.allaboutcircuits.com/...ic-controlled-battery-array.32879/post-204585
https://github.com/nsaspook/mbmc/tree/new_solar
It's still running as a Zombie Attack backup power system. Uses a 12 VDC battery bank to be compatible with a car during emergencies, with a 2 KW off-grid inverter that's kept the forced air gas heat AC motor blower running in winter during a few blackouts in ice-storms.

The current system switching energy modes.

Screenshot of Home Assistant energy dashboard in Chrome showing a Notifications panel reading 'HA in Float, Max Energy Set', and a flow diagram with Solar 3.97 kWh, Low-carbon 13 kWh, Grid 3.05 kWh in and 33.3 kWh out, Battery 1.17 kWh and 1.68 kWh, and Home 34.7 kWh.
 
  • Like
Likes   Reactions: Rive and BillTre
New DAQ board design for a remote panel energy monitor. A 8-bit pic controller for a Orange pi 3 Linux using that machines SPI Master.
Green printed circuit board with surface-mount chips, resistors and capacitors, pin headers along the right edge and a row of pins along the bottom, mounted on a blue workbench beside soldering tools.
Green printed circuit board with a surface-mount microcontroller, a RJ45 Ethernet jack, a small crystal oscillator labelled 16MHZ, and pin headers, lying on a blue mat beside tweezers and a soldering iron.
Two monitors side by side: the left shows a PCB layout in a CAD program with labels C26, C16 and C17 beside surface-mount pads; the right shows a close-up photo of a green circuit board with a chip marked 74HC125.
Close-up of a green printed circuit board with a square surface-mount microcontroller chip, labelled headers, LED markings, a crystal oscillator labelled OSC 16MHZ, and silkscreen text including PVP_0 and 28455908A_V46_250504.
Photo of a bench hot-air rework station with a digital display reading 354 and CH1, CH2, CH3 buttons, beside a chrome heat gun, with a green circuit board in the foreground.

Close-up photo of a green circuit board being soldered: a grey surface-mount IC with leads along both long sides, and a soldering iron tip touching the pins.
 
I have the beta custom DAQ board for the Orange PI in operational testing. 8 24vdc, 2 5vdc digital inputs. 16, up to 24vdc low side switches, 7 12-bit ADC inputs and 1 8-bit DAC output. The analog and connections to the OPi3 are handled by a PIC18F47Q84 controller firmware. SPI2 is the SPI slave for the OPi3 Master controller. SPI1 handles the display and the two DIO devices that transfer data via SPI2 per Master requests for status and changes.
On the Orange PI and custom kernel driver was designed (still needs optimization to use CPU threads effectively) to interface with the Comedi DAQ API. This allows for specific hardware device functions to be abstracted into a common user API so different hardware DAQ frontends can be used with the same applications software.

https://github.com/nsaspook/mqtt_comedi/blob/main/secs_q84 v2_sch.pdf
https://github.com/nsaspook/mqtt_comedi/blob/main/secs_q84 v2_brd.pdf

Early Beta software: https://github.com/nsaspook/mqtt_comedi
Applications program: https://github.com/nsaspook/mqtt_comedi/tree/main/bmc
Q84 firmware: https://github.com/nsaspook/mqtt_comedi/tree/main/Q84/bmc_slave.X
Linux kernel protocol driver: https://github.com/nsaspook/mqtt_comedi/blob/main/daq_bmc/daq_bmc.c
Requires Linux kernel patches to add the needed device-tree and Kconfig to the new user protocol driver source into the standard kernel build process. Then add the new protocol driver spi_bmc instead of the system standard spi-dev in the Orange PI
device tree-config file.
Boot config file: https://github.com/nsaspook/mqtt_comedi/blob/main/daq_bmc/orangepiEnv.txt
Device-tree source file: https://github.com/nsaspook/mqtt_comedi/blob/main/daq_bmc/sun50i-h616-spi1-spibmc.dts
Cluttered workbench with two oscilloscopes, one showing a Rigol screen with digital waveforms on a large monitor, a bench power supply, a multimeter, a small blue LCD module, and a soldering station.

Photo of a green circuit board with a PIC microcontroller and wiring, with a MPLAB PICkit programmer connected below it and oscilloscope probes attached.
Terminal window output listing repeated Energy_Mqtt_BMC1 and Energy_Mqtt_BMC2 records with sequence numbers, ADC values, build dates and times, shown above a row of xterm taskbar windows.

BMC1 MQTT data. The ADC channel 0 and 1 are the raw voltage reading on the ADC pins for the RS232 line voltages (that have been normalized and scaled on the Q84 display to the +- 15 volts range)

Screenshot of a solar monitoring panel listing Server UPS 322.0 W, Shed GTI PV voltage 1.998 V, Shed Pole PV voltage 1.447 V, Sys Patio PV voltage 25.14 V, Sys Pole voltage 30.35 V and SYSTEM TOTAL 3.80 W, with the two Shed PV voltage rows circled in red.

DAQ testing RS232 raw ADC values displayed on the Home Assistant Shed PV voltage cards. The Sys voltages are live system values.

Close-up photo of a blue-backlit character LCD showing "OPI DAQ 1 V0.03" with rows of numbers and hex values such as A1 0x58c, A2 0x7aa and 0x0464 0x42 0 0 1.

Second line: The first number is the error count, second ADC conversions, third master data packet requests.
Third line: ADC channel 1 raw value, ADC channel 2 raw value.
Last Line: SPI2TCNT, SPI2INTF SPI2 registers and program state flags. The number 1, on the end means, spi_comm_ss.REMOTE_LINK is true.

Photo of a backlit character LCD showing: RS232 TX -10V:M, RS232 RX -1V:0, A1 0x59b, A2 0x7ba, B0 0xC0, B1 0x00.

RS-232 Jack status. Voltage and Mark/Space or Open line condition.

Last line: Input line buffer from the SPI2 and UART links.
C:
data_in2 = SPI2RXB;
serial_buffer_ss.data[0] = data_in2;
char_rxtmp = UART1_Read();
serial_buffer_ss.data[1] = char_rxtmp;

Line data scope shots:
Oscilloscope screen showing four digital waveform channels over time, with channel 1 yellow, channel 2 cyan, channel 3 magenta and channel 4 blue, plus hexadecimal decoded serial bus labels such as c0, d, 9, 81, 82, 84 and 85 on the traces.

MOSI -> MISO ADC data transactions.

Oscilloscope screenshot showing four digital waveforms on a Rigol display, channels 1 to 4 in yellow, cyan, magenta and blue, with timing axis from -14.4 to 65.6 microseconds.

One ADC value request transaction.

Siglent SDS 1202X-E oscilloscope screen showing a green square-wave trace on channel 1 with a cursor measurement reading ΔX = 192.0 us and 1/ΔX = 5.208 kHz.

Q84, all channels ADC conversion and buffered processing time.

Oscilloscope screen showing a yellow noisy periodic waveform with vertical spikes above it; readout reads 195.378 Hz, delta X 21.30 ms, 1/delta X 46.95 Hz, CH1 2.00 V/div.

Q84 ADC all channel update rate with the display update gap timing. We only monitoring slowly changing DC signals for this applications, so the variation in sampling rate is not important.