FM80 solar charge controller datalogger

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
The next step is data integration with the house automation systems.
First, the MQTT add-on for Home Assistant is added and configured for the broker.
1703997790676.png

Next, create HA sensor variables to capture the MQTT JSON payload from the broker as data is published from the mateq84 FM80 monitor.
C:
json = cJSON_CreateObject();
                cJSON_AddStringToObject(json, "name", "mateq84");
                cJSON_AddNumberToObject(json, "benergy", benergy);
                cJSON_AddNumberToObject(json, "acenergy", acenergy);
                cJSON_AddNumberToObject(json, "load", load);
                cJSON_AddNumberToObject(json, "runtime", runtime);
                cJSON_AddNumberToObject(json, "solar", solar);
                cJSON_AddNumberToObject(json, "batenergykw", bat_energy_kw);
                cJSON_AddNumberToObject(json, "batenergyscaled", bat_energy_scaled);
                cJSON_AddNumberToObject(json, "bamps", bamps);
                cJSON_AddNumberToObject(json, "bvolts", bvolts);
                cJSON_AddNumberToObject(json, "pamps", pamps);
                cJSON_AddNumberToObject(json, "pvolts", pvolts);
                cJSON_AddNumberToObject(json, "pwatts", pwatts);
                cJSON_AddStringToObject(json, "system", "FM80 solar monitor");
                // convert the cJSON object to a JSON string
                char *json_str = cJSON_Print(json);
Linux C program that captures CSV data from the CAN-FD network, re-formats that data into JSON format for publishing to the local MQTT broker (10.1.1.172 on the local house LAN).

Some are HA 'energy' sensors (the mateq84 system was designed to track Wh as the base unit) and some are for 'measurement' (volts, amps, watts,etc...).
https://www.home-assistant.io/docs/energy/faq/
Energy vs Power
It’s a common mistake to take Power as an Energy value, but the two are not alike.

Energy is a quantitative measurement of what it takes to produce work (e.g. heat water) while Power measures the speed at which energy is transferred.

Electrical Power is measured in Watts (W) and Electrical Energy is measured in kiloWatt-hour (kWh).

Think of this in a parallel to speed and distance: Power is the speed you are going and Energy is the distance driven.

Therefore Energy (kiloWatt-hour) is not an average of the Power you are consuming over a given period of time (the unit of the average power would be Watt or kiloWatt again). Energy is the integral (mathematical operation) of the Power function.

This difference is very important as you need to use the proper entities in our Energy Panel.
1703997994851.png
HA configuration code in YAML. https://en.wikipedia.org/wiki/YAML
https://www.home-assistant.io/docs/energy/

We then need to create a Dashboard to display the information from the monitor and HA generated statistics from that data.
1703999357205.png
1703999430346.png

Finally have all of that stable and working, so the next step is to make fancy Gen-* Energy Dashboards.:D
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Electric space heater switched on and off.

Fancy Energy Distribution gauge with some mock-up data for the grid.
1704066219758.png
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Next is to integrate the whole house electrical monitor into the the HA system. I'm using the IAMMETER three-phase wireless system to monitor the L1 and L2 legs of the utility split-phase connection in the main breaker box. The extra L3 CT is used to monitor generated and locally used AC power from solar.
All of my monitoring is local so I don't use the 'cloud' option.



1704661578014.png
One of my monitor projects uses the same type of DIN rail enclosure. https://forum.allaboutcircuits.com/...c-controlled-battery-array.32879/post-1490545

This is powered and the voltage is monitored from a dedicated 220VAC breaker (L1, L2, Neutral and Ground) on the main panel that's also used to connect a whole house surge protection device.
1704662280815.png
Remote data update period using default HA http connection. There are other (faster/better) methods to collect the data. https://www.iammeter.com/docs/own-system#3-upload-data-to-your-own-server
1704662312543.png
 
Last edited:

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Rebuilding some older systems for the new one.
https://forum.allaboutcircuits.com/...c-controlled-battery-array.32879/post-1463914

Rewrote some of the software on the original 24vdc monitor system to upload data via MQTT (serial data to the Waveshare POE module to my local MQTT broker that HA uses as the house data pool) to be used by Home Assistant.
Need to reconfigure the Hall current sensors for the battery and Renogy charge controller but the basic system is working to upload status data for limiting power delivery when used as a electrical power dump load.
1704775171351.png
1704775196288.png
Need to finish the enclosure with the display and a few control buttons.
1704775282939.png
DL for Dump Load sensors.
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
As expected the cold weather (<20F) gives a VoC error on the charge controller with the current 7 panel string set.
1705283621559.png
1705283670059.png
No power to the battery bank.
1705283721722.png
Easy solution with the 7th panel on the ground. Flip it over to bring the voltage into range and flip it back up once the MPPT drops the running voltage back to normal.
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Have almost completed the hardware testbed for the software.
Solar_bank_diagram.png
1706670931612.png
1706670974719.png
The two GTI inverters have power limiting from either a grid-power monitor that prevents sending power outside the house or the power can be controlled via MQTT commands via my software to power shift
energy from the batteries to the home grid after the sun sets.

SImple command set:

C:
void gti_cmds(void)
{
    if (Sready()) {
        mqtt_r = Sread();
#ifdef GTI_ECHO
        UART1_Write(mqtt_r); // debug echo
#endif

        switch (mqtt_r) {
        case 'Z': // zero power
            cmd_value = 0;
            break;
        case '+': // incr power
            cmd_value = gti_power + 100;
            if (cmd_value > 1000) {
                cmd_value = 1000;
            }
            break;
        case '-': // decr power
            cmd_value = gti_power - 100;
            if (cmd_value < 0) {
                cmd_value = 0;
            }
            break;
        case 'I': // idle power
            cmd_value = 5;
            break;
        case 'F': // normal operation
            cmd_value = 600;
            break;
        case 'M': // max unit rated power testing
            cmd_value = 1000;
            break;
        case '#': // execute command symbol
            INTERRUPT_GlobalInterruptLowDisable(); // 16-bit atomic update
            gti_power = cmd_value;
            INTERRUPT_GlobalInterruptLowEnable();
            break;
        default: // eat extra characters
            while (Sready()) {
                mqtt_r = Sread();
            }
            break;
        }
    }
}
A simple, two character command parser.

1706672052148.png
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
The C program that unifies all of these systems is now operational but not finished. The program gathers all the data from various wired and wireless systems and data formats, to an internal energy manager usable format with two main objectives. Frist, maximize the energy in the battery bank and inject excess into the internal house AC grid until the battery is full. Then it switches into the energy balance mode to keep the battery topped off and to send all excess solar energy into the house AC grid. After the solar days is done, the programs then switches to energy time-shift mode to use the stored battery energy at night to reduce grid energy imports. It never generated exports energy to the grid.


 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Finally have a bit of decent sunshine for testing using the backyard solar testbed.
1708724131070.png
1708724167877.png
Trying a little smoke testing on the cheap Chinese grid-tie inverters using the house sandbox'd electrical grid.
1708724239904.png
They start to get a little warm at 600W AC output but so far are working nicely.
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Fixed most of the bugs with the PID controlled energy monitor. I can define set-points that the system tunes to and will keep a slight positive power bias to keep batteries fully charged while Max power is delivered to the various AC and GTI house loads, much like a Tesla powerwall.
1709943074823.png
1709943096288.png
C:
/*
* converted to PI for solar power control
*/
double UpdatePI(volatile struct SPid * const pid, double const error) {
    double pTerm, iTerm;

    pTerm = pid->pGain * error; // calculate the proportional term
    // calculate the integral state with appropriate limiting
    pid->iState += error;

    if (pid->iState > pid->iMax) {
        pid->iState = pid->iMax;
    } else if (pid->iState < pid->iMin) {
        pid->iState = pid->iMin;
    } else {

    }

    iTerm = (pid->iGain * pid->iState); // calculate the integral term

    if ((pTerm + iTerm) > pid->iMax) {
        iTerm = 0.0f;
        pTerm = pid->iMax;
    }
    return pTerm + iTerm;
}

                if (bsoc_set_mode(PV_BIAS, true) && E.git_sw_status) {
                    char gti_str[16];
                    int32_t error_drive;

                    if (E.gti_delay++ >= GTI_DELAY) {
                        E.mode.in_control = true;
                        E.gti_delay = 0;
                        error_drive = (int32_t) E.mode.error; // PI feedback control signal
                        if (error_drive < 0) {
                            error_drive = PV_BIAS; // control wide power swings
                        }
                        snprintf(gti_str, 15, "V%04dX", error_drive); // format for dumpload controller gti power commands
                        mqtt_gti_power(client_p, TOPIC_P, gti_str);
                    }
                } else {
                    if (E.mode.in_control) {
                        E.mode.in_control = false;
                        ramp_down_gti(client_p, true);
                        ramp_down_ac(client_p, true);
                    }
                };

/*
* set mode to true to add GTI power to AC power for control power feedback
* target is the positive power bias to keep the battery(s) charged
*/
bool bsoc_set_mode(double target, bool mode) {
    bool bsoc_mode = false;

    if (E.mvar[V_PWA] >= PV_FULL_PWR) {
        bsoc_mode = true;
    }

    E.mode.gti_dumpload = (E.print_vars[L3_P]* -1.0f) + E.mvar[V_DPPV];
    E.mode.total_system = (E.mvar[V_FLO] - E.mode.gti_dumpload) + E.mvar[V_DPPV] +(E.print_vars[L3_P]* -1.0f);
    E.mode.gti_dumpload = (E.print_vars[L3_P]* -1.0f) - E.mvar[V_DPPV];

    /*
     * look at system energy balance for power control drive
     */
    if (mode) { // add GTI power from dumpload
        E.mode.error = (int32_t) UpdatePI(&E.mode.pid, E.mvar[V_BEN] + E.mode.gti_dumpload + PBAL_OFFSET);
    } else {
        E.mode.error = (int32_t) UpdatePI(&E.mode.pid, E.mvar[V_BEN] + PBAL_OFFSET);
    }
    E.mode.target = target;
    return bsoc_mode;
}
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
1715463392077.png
Battery BMS in float mode (FCM). System moving MAX energy to AC loads. A slightly negative control bias to slowly drain energy from the battery bank.
1715462847429.png
1715462898544.png
1715462960330.png

System back in BULK battery charge mode (BCM) where it keeps a slightly positive control bias of energy flow to the battery to keep it topped off.
1715463101119.png
 
View attachment 322107
Battery BMS in float mode (FCM). System moving MAX energy to AC loads. A slightly negative control bias to slowly drain energy from the battery bank.
View attachment 322103
View attachment 322104
View attachment 322105

System back in BULK battery charge mode (BCM) where it keeps a slightly positive control bias of energy flow to the battery to keep it topped off.
View attachment 322106
Hi there nsaspook,
I'm totally impressed with this system, I have yet to read the whole thread.
We have been summering in our off-grid RV site using propane and a 12 volt solar set up.
I just inherited an Outback VFX3524 inverter, but it had no MATE. I also acquired six 12v 100Ah gel batteries from a cosmetic warranty issue. Batteries are basically 100% electrically, but have some cosmetic issues for which the manufacturer replaced them under warranty, and didn't want to pay for shipping the damaged ones back.
So voila, I decided to upgrade our summer off-grid RV to 120 Vac!
1715974468705.png

This is my system, configured as 24 volt. I am using 4 old 265 watt Trina panels connected to a Renogy Rover Li 40 amp charge controller for the PV side of my system.
I now need a MATE or equivalent in order to connect a propane gen set to this system. I was looking at the pyMATE system, and I ran across your thread. Your efforts have been a lot more recent. Can I hack your work and your brain to build what I need?

Also, does this site allow PM's? I couldn't find a way to message you directly.
Cheers, Elroy
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Nice.
I'm sure my interface hardware system could be hacked for the VFX3524 inverter as the MATE interface is the same but the controller software (in C) is custom for my configuration and is not intended for a general use library. Adapting pyMATE would likely be much easier to get going unless you're up to speed with PIC18 xc8 embedded programming. Feel free to use anything from the archive or to ask questions.
https://github.com/nsaspook/Q84vtouch/tree/q84
 

Attachments

Nice.
I'm sure my interface hardware system could be hacked for the VFX3524 inverter as the MATE interface is the same but the controller software (in C) is custom for my configuration and is not intended for a general use library. Adapting pyMATE would likely be much easier to get going unless you're up to speed with PIC18 xc8 embedded programming. Feel free to use anything from the archive or to ask questions.
https://github.com/nsaspook/Q84vtouch/tree/q84
Thanks for the quick reply. I was hoping for a quick fix to my issue, but alas, life offers no shortcuts.
I'll have to do a little more research on which micro-controller to use with the pyMATE library. Not 100% sure on that yet.
Lot's to learn for an old fart like me, lol.
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Things are at the BETA stage with hybrid grid-tie system.
Linux server for Home Assistant and the main energy control program that combines all systems data and controls energy flow, storage and usage.
1718131356986.png
2 8-bit controllers.
Q84: FM80 charge controller, EM540 off-grid energy meter, CANBUS (FD) remote monitor and HA host interface.
1718130773683.png
K42: MQTT Grid-Tie inverter control and power buffer (dumpload) controller and monitor.
1718131068455.png
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Running close to full power with both energy banks fully charged. 10kWh of energy storage for utility backup, hybrid load shifting and buffer.
1724021969139.png
 

Thread Starter

nsaspook

Joined Aug 27, 2009
16,321
Upgrading the HVAC to be more energy efficient (and to work much better in the heat) in the work room using solar. Replacing a window unit with a mini-split for cooling, heating, heat pump and dehumidification.
https://dellahome.com/products/dell...nverter-system-with-1-ton-heat-pump-ja-series
You will need a R410A adapter for the vacuum pump guages to evacuate the refrigeration lines. This unit uses R32 but the fittings are the same as R410A: https://senville.com/r410a-adapter/

1726420369803.png
Using a 115VAC unit with my 4KW off-grid inverter and 10KWh battery bank.
1726420390586.png
Power disconnect outdoors from the separate AC breaker indoors. Disconnect boxes are required by code at the junction from the indoor ROMEX wiring to the watertight flex (vibration) whip to the AC.
1726420441825.png
Dryer vent for the feed-through. Sealed with expanding foam.
1726420511200.png
Wall bracket. Super quiet.

1726420569343.png
The indoor unit mounted on some 3/4 ply on the upstairs floor support with the whole house and shop vacuum systems.
1726420644119.png
Ice cold and so quiet, you can't hear it running at max cooling.
 
Last edited:
Top