Skip to content

Solar Integration

David Albrecht edited this page Apr 14, 2023 · 11 revisions

This documentation is for software version 0.2.0 and earlier. Click here to see this page in the latest docs.

Solar / Net Monitoring Integration

Have a source of power generation? Follow these steps to get this project setup for net monitoring.

Net monitoring is a specific type of setup where your solar panels (or windmill/generator) are tied into the grid, and you send excess power back into the grid.

These steps are intended to be followed for grid-tied solar PV systems. If your PV system is not grid tied, there is still some valuable information here, but you'll have to extract the parts that are necessary for your specific implementation. Since grid-tied is arguably one of the most common, I am focusing the project's efforts on it.

Also note: You don't HAVE to follow these steps if you have solar. These steps are only provided so that you can use the default project dashboard that I've supplied along with this project. The individual CTs readings are stored in the database by default and you can also create your own dashboard in Grafana with your own queries. See the database structure section of the Wiki for more information.


Step 1: CT Orientation

In a grid tied system, current can flow in both directions from your mains' perspective. First and foremost, we need to define what positive and negative mean.

  • A positive reading on a CT that is monitoring your mains should mean that you are importing power from the grid.

  • A negative reading on a CT that is monitoring your mains should mean that your are exporting excess power back to the grid.

You need to ensure that all CTs used in this project are reporting POSITIVE readings without any power production occurring.

The easiest way to do this is to check at night when your solar panels aren't producing any power. If you prefer the CLI, you can start the software in terminal mode and make sure the Watts readings are all positive for all the CTs you are using.

Or, if you prefer to use Grafana to check, you can import this dashboard to view the individual CT readings.

If you find any CTs with negative readings, simply reverse the way that the CT is clamped onto the conductor in your panel. Please remember to exercise extreme caution - the mains are always live!

Note: The CT measuring your solar inverter output should also read positive during solar production.

Double check that all your CTs are reporting positive values AT NIGHT before proceeding. Having CTs with the incorrect orientation is the number one reason that this process will fail!


Step 2: Minor Code Adjustments

I am hesitant to refer to specific line numbers in this section because the numbers may change in the future as I continue to maintain this project. Therefore, I will use hyperlinks to the latest master version of the code at the time of writing. The line numbers may change in the future, but the general idea and changes will be the same.


Change #1: Specifying the CTs used for Production

In power_monitor.py, find the results variable here.

This variable contains settings for each CT, so we'll need to change the CT's type. For example, if CT3 is measuring your solar inverter's output, change the 'type' to 'production', like this:

'ct3' : {
        'type'      : 'production',
        'power'     : real_power_3,
        'current'   : rms_current_ct3,
        'voltage'   : rms_voltage_3,
        'pf'        : power_factor_3
    },

Doubling a CT's measurement for 240V circuits

Now, if your solar inverter has two output legs (very common in USA to have a 240V split-phase output inverter), you might need to make one more change. If you are only monitoring one of the inverter's output legs, you'll have to double the measurement. If you are monitoring both of the inverter's output legs, you don't need to do this. Or, if your inverter has only one output, you don't need to do this.

To double the reading from the single CT, simply add a * 2 to the power and current variables for the specific CT measuring your solar inverter. To continue my example above with CT3, here's how that section in the results variable will look when I'm done:

'ct3' : {
        'type'      : 'production',
        'power'     : real_power_3 * 2,
        'current'   : rms_current_ct3 * 2,
        'voltage'   : rms_voltage_3,
        'pf'        : power_factor_3
    },

If your inverter has two output legs and you have a CT on each one, make sure you change both CT's type's to production like we did above.

Important: Do not change any of the indentation or punctuation when making these changes. Python syntax is defined in part by indentation level, so if you mess with the indentation, you'll probably get a syntax error when starting the software after these changes. The same goes for the puncutation marks.


Change #2: Assigning the CT(s) to the solar_power and solar_current variables

In power_monitor.py, find the solar_power variable here.

In each of the three variables in this section (solar_power, solar_current, and solar_pf), change the number inside the brackets so that it matches the number of the CT that is monitoring your solar inverter output.

Continuing with my example of CT3 as the one on my solar inverter output, my section would look like this:

solar_power = results['ct3']['power']
solar_current = results['ct3']['current']
solar_pf = results['ct3']['pf']

Note the lowercase ct, and also note that the # sign (comment) has been removed from the beginning of the line. You can ignore the previous three lines where the variables are set to 0 and just leave them as is.

If you are using two CTs to monitor each output leg of your solar inverter (assuming it's a split phase 240V output), the section would look like this instead. Let's assume you're using CT2 and CT3:

solar_power = results['ct2']['power'] + results['ct3']['power'] 
solar_current = results['ct2']['current'] + results['ct3']['current']
solar_pf = results['ct3']['pf']

The power factor for solar output should not be summed. You can average the power factor values together if you want, or access the value of the other CT's power factor through the raw_cts measurement in the database. See the Database Structure page in the Wiki for more info.


Change #3: Correcting the polarity of the current reading for the mains

In power_monitor.py, find the if grid_0_power < 0: section here.

The number in the variable - 0, in grid_0_power - is a direct correlation to the CT number. We just need to make sure the grid_#_power and grid_#_current variables match the numbers that are installed on your electrical mains.

For example, if CT0 and CT1 were installed on your mains, the section would look like this:

if grid_0_power < 0:
    grid_0_current = grid_0_current * -1
if grid_1_power < 0:
    grid_1_current = grid_1_current * -1

Change #4: Correcting the net power calculation

By default, the software is setup so that home_consumption_power is the sum of all 6 CTs. Since you're setting up solar, we need to change this.

In power_monitor.py, find the section starting with home_consumption_power here.

By definition, your home's consumption is the sum of the power flowing through the mains and the solar power produced. In my example, CT3 was on my solar inverter and CTs 0 and 1 were on my mains. The solar power is already contained in the variable solar_power, so we can remove the grid_#_power variable that corresponds to your solar PV system CT number. So, for my particular setup, I will remove grid_3_power because that is the CT number on my solar inverter, and I'll remove the other grid_3_power variables except for 0 and 1, like this:

home_consumption_power = grid_0_power + grid_1_power + solar_power

Make a similar removal for the home_consumption_current variable in this same section:

home_consumption_current = grid_0_current + grid_1_current - solar_current

Make sure you remove the extra remaining + signs after removing the variables from the equation!

Make a similar removal for the net_current variable in this same section:

net_current = grid_0_current + grid_1_current + solar_current

Finishing Up

Save the power_monitor.py file, then restart the software. If you're running the software as a service already, restart it with:

sudo systemctl restart power-monitor

If you haven't setup the service yet, stop the software if it's currently running with Ctrl-c and then restart it with python3 power_monitor.py.

Check the status of the software (if running as a service) with:

sudo systemctl status power-monitor

If it failed to start, you probably have a syntax error. Double check that you did not change any of the indentation levels, delete any punctuation marks, or leave extra + signs in the equations we modified.

Clone this wiki locally