/SolarUseOptimiser

This project allows for extending polling solar data from any system and sending it anywhere.

Primary LanguageC#MIT LicenseMIT

Solar Use Optimiser Service

Docker Image CI

Donate PayPal Buy Me A Coffee Daniel's Tesla Loot Box Referral

The intention of this service is to build upon the Huawei FusionSolar to ChargeHQ integration that I'd previously created and provide a framework for plugging in different data sources and different data targets. This will allow this service to be used for building out integrations of many different solar systems to many different types of consumption optimisation services. It will poll a solar system for how much solar power is being generated (and if possible determine the excess) and then push this onto the configured target (which could be ChargeHQ) to allow that target to regulate the power consumed by the target such as an EV charging or anything else that might be able to use variable power consumption rates. This allows for optimisation of the use of solar energy rather than grid supplied energy.

If you are using a Huawei system this service is 100% interchangable with the danwale/huaweifusionsolar2chargehq that provides the functionality hard coded between Huawei FusionSolar and ChargeHQ, this project decouples a few things to make it so it can easily extended to support other solar systems and potentially other targets (a custom Tesla charge rate control service for instance or any other brand...your imagination is your limiting factor).

Of course if you really like this service and want to thank me a donation would be much appreciated, see the various donation method buttons above or if buying a new Tesla product use my referral code to also get some credits: https://ts.la/daniel336154

Happy EV motoring, charging as cleanly (and cheaply) as possible!

Configuration

Note: You only need to include the GROWATT, HUAWEI or IoTaWatt sections if you have set the Routing.DataSource as Growatt or Huawei or IoTaWatt respectively.

Sample docker-compose.yml:

version: "3"

services:
  solar-use-optimiser:
    image: danwale/solaruseoptimiser:latest
    restart: always
    environment:
      - ROUTING__DATASOURCE=Huawei #use a name for the source of the solar data
      - ROUTING__TARGET=ChargeHQ #use a name for the target to send the solar data to
      - IOTAWATT__IPADDRESS= #insert the IP Address of the IoTaWatt Power Sensor device
      - IOTAWATT__POLLRATE=1 #in minutes how often to poll the sensor
      - GROWATT__BASEURI=https://server.growatt.com/
      - GROWATT__USERNAME= #insert Growatt username here
      - GROWATT__PASSWORD= #insert Growatt password here
      - GROWATT__POLLRATE=5 #in minutes
      - GROWATT__USEBATTERYDATA=true #true or false value, if a battery is present should its data
      - HUAWEI__BASEURI= #insert the base URI for the FusionSolar API you're setup on e.g.: https://intl.fusionsolar.huawei.com/
      - HUAWEI__USERNAME= #insert the username Huawei or your installer have provided
      - HUAWEI__PASSWORD= #insert the system code/password Huawei or your installer have issued
      - HUAWEI__STATIONNAME= #insert the plant/station name here
      - HUAWEI__USEPOWERSENSORDATA= #true or false value, if a power sensor is present should its data be collected and passed on
      - HUAWEI__USEGRIDMETERDATA= #true or false value, if a grid meter is present should its data be collected and passed on
      - HUAWEI__USEBATTERYDATA= #true or false value, if a battery is present should its data be collected and passed on
      - CHARGEHQ__APIKEY= #insert your ChargeHQ API Key here
      - SERILOG__MINIMUMLEVEL=Information # Use Debug if you want to see information on message payloads
      - TZ=Australia/Perth # If you want your logs to display in the servers local timezone rather than UTC set the TZ environment variable to suit
    volumes:
     - solaruseoptimiser-conf:/etc/solaruseoptimiser

volumes:
  solaruseoptimiser-conf:

Run the following command to run the service:

docker-compose up -d

If you want to watch the logs run the command:

docker-compose logs --follow solar-use-optimiser

pressing Ctrl+C will end this command following the logs

To stop the service run:

docker-compose stop solar-use-optimiser

You can configure the entire service using environment variables as shown above, but if you want to use a configuration file, you can put an appsettings.json in the mapped volume and it will take effect, environment variables will override any equivalent settings in a file:

{
    "Routing": {
      "DataSource": "Huawei",
      "Target": "ChargeHQ"
    },
    "IoTaWatt": {
        "IPAddress": "<IP Address of the Power Sensor>",
        "PollRate": 1
    },
    "Growatt": {
       "BaseURI": "https://server.growatt.com/",
       "Username": "<Username Here>",
       "Password": "<Password Here>",
       "PollRate": 5,
       "UseBatteryData": true
    },
    "Huawei": {
        "BaseURI": "https://intl.fusionsolar.huawei.com/",
        "Username":"<Username Here>",
        "Password": "<System Code/Password Here>",
        "StationName": "<Station Name Here>",
        "UsePowerSensorData": true,
        "UseGridMeterData": true,
        "UseBatteryData": true
    },
    "ChargeHQ": {
        "PushURI": "https://api.chargehq.net/api/public/push-solar-data",
        "ApiKey": "<ChargeHQ API Key Here>"
    },
    "Serilog" : {
        "Using":  [ "Serilog.Sinks.Console" ],
        "MinimumLevel": "Information"
    }
}

Data Sources

Huawei FusionSolar

If you have power sensor devices or grid meter devices, and/or Huawei batteries in your solar setup it is able to pull data from those devices to help send more accurate information onto ChargeHQ to make more informed decisions on the charging. If a Power Sensor exists it will use that over a Grid Meter, if you wish to just use the inverters production data and manage the buffer of "excess" solar power the premises needs you can turn off the extra data sources with toggles in the settings (they default to being enabled with a value of true). This extra functionality hasn't been tested extensively by myself because I don't have these devices in my setup but I've looked at the values from a user for a number of the device types and think this should work, let me know if it doesn't work for you and we can work together to get it fixed. There is no need to turn off the functionality if you don't have the devices, the software is smart enough to detect the devices the system has available to it

How to get a Huawei Username and Password

NOTE: Here is a link to the quick guide I created for Solar Installation Company Administrators for setting up the required account, pass this on to them when requesting an API account to be created and it will help them work it out: https://github.com/danwale/HuaweiFusionSolar-ChargeHQ-Integration/blob/main/docs/Huawei%20FusionSolar%20Northbound%20API%20Account%20Procedures.pdf.

In late 2022 Huawei changed the process for getting access to the API's, it now requires you to request an API account from the company that installed your Huawei solar system as the installer now has the responsiblity to create what they call a Northbound API Account that would be used. The limitation on the Huawei system is each installer company can only create a maximum of 5 of these Northbound API Accounts as it's intended that they are used by an integration point rather than individual users. To faciliate this shortcoming it's best to ask the installer to create a Northbound API Account for their entire company that will be shared by all users, this software will only pull the information relevant to the specific station/plant that is named in the configuration.

I've prepared a document (linked above) detailing how to setup a Northbound API Account for sending onto your installer in case they haven't seen this new functionality before and help guide them through the process. Things they'll need to setup for their account are:

  • System Name: This is a globally unique name for the Northbound API Account being created, I suggest they include their company name initials in the name to help achieve this, e.g. if the company was called The Best Solar Firm they'd use the System Name TBSF_ChargeHQ_Poller. If the name is taken when they try to save/create the new account it will show a dialog informing them that the System Name is already in use.
  • Username: Again this is globally unique so they should use a similar technique for naming the username, using the sample company name above they might use TBSFChargeHQ.
  • Password: This is the password for the account, this can be anything they pick but they need to be able to share it with their customers who ask them to use this account.
  • Account Expiry: There is a mandatory field for the expiry of the Northbound API Account, I would suggest they pick a date that exceeds the expected lifetime of the systems that could be relying on it, setting it as 2199-12-31 23:59:59 would guarantee that it's effectively set to never end (if your solar system lasts that long and your great great grand children are using it I'd be very surprised :))

The next step in the setup is to grant access to certain (or all) plants and what interfaces of the API and data points the account has access to. I would suggest that an installer would turn on access to all interfaces and data points and would add plants into the Northbound API Account as customers ask for the access to the API.

The installer would then provide the user with the Username and Password they created for the Northbound API Account and provide you with what your station/plant name is (though you can get this yourself from the FusionSolar Moblie App, if you click Devices in the app then select your inverter and then click Basic Info you'll get a screen that shows the Plant name)

Growatt

This is a new implementation of an IDataSource that pulls data from the Growatt solar data that is collected. Thanks to Richard Ramshaw for reverse engineering the API. It does rely on the you having the Current Power (AC) value populated when you login to the Growatt Portal to get the live produced current power value.

IoTaWatt

This implementation hasn't been tested, it's based on a simple powershell script that Dinesh Pannu created. https://github.com/dineshpannu/iotawatt-to-chargehq

Data Targets

Currently this is only pointing to ChargeHQ but it's designed so that other targets can be implemented.