Sign inSign up

jsprnl/pyfusionsolardatarelay

By jsprnl

•Updated over 1 year ago

Fetch from Huawei FusionSolar Northbound or Kiosk API and relay it to InfluxDB, PVOutput.org & MQTT

Image
Monitoring & observability
2

5.6K

jsprnl/pyfusionsolardatarelay repository overview

⁠Huawei FusionSolar (Northbound OpenAPI and/or Kiosk) to InfluxDB, MQTT, PVOutput and Home Assistant relay

This is a python project intended to fetch data from the FusionSolar Northbound OpenAPI or public kiosk, and relay it to InfluxDB/VictoriaMetrics and/or PVOutput.org and/or MQTT and/or Home Assistant (hass). Both inverter and grid meter metrics can be retrieved from FusionSolar's API.

Additionally this project can also fetch and relay utility grid energy usage data from the Dutch Kenter metering service for commercial transformers.

Multiple parallel fusionsolar kiosk configurations are supported, and multiple devices on the same Northbound OpenAPI account are supported. Also, multiple parallel meters from Kenter's service are supported as well. You can configure where metrics should be published per configured device. Additionally, the project also supports publishing metrics from discovered devices over the Northbound API, which have not been individually configured in the environment variables. Please refer to settings the configuration options in this document for more explanation.

GitHub release License

⁠Installation

This project is mostly used as a Docker container and fetches its config from environment variables. The file main.py can also be started from a python3 environment, after running pip install -r requirements.txt and renaming .env.example to .env. PyFusionSolarDataRelay will then load the environment files from this file, overriding any environment variables already set.

Check out examples/docker-compose.yml⁠ for a docker configuration example.

Docker

⁠Breaking changes in the latest release

In version 2.0.0 the environment variables used by this project changed names and structure. Please review the configuration section in README for updated variable names. Additionaly, functionality to write electrical energy usage from utility grid has been removed.

⁠About Huawei FusionSolar Northbound OpenAPI mode

FusionSolar is Huawei's online monitoring platform, the Northbound API exposes metrics from devices supported by this platform. This project specifically supports inverter and grid meter device types. To use the Northbound API (also called OpenAPI) please ask your installer to create an API account for you, with read access to the relevant inverter and grid meter (if applicable) metrics.

⁠About Huawei FusionSolar Kiosk mode

FusionSolar features a kiosk mode. When enabled, a kiosk url is generated which is publically accessible. The kiosk web app fetches its data from a JSON backend. It is this backend where this project fetches the PV data. Fetching data from the kiosk mode can be beneficial to those without direct access to the official API and/or the inverter Modbus-TCP. For instance when the inverter is logging to fusionsolar over a direct cellular connection configured and fitted by an installer unable to provide API access rights to third parties.

⁠About PVOutput.org

PVOutput.org⁠ is a free service for sharing and comparing PV output data. PVOutput dashboard screenshot

⁠About InfluxDB

InfluxDB⁠ is an open source time series database on which dashboards can easily be built. For instance using Grafana⁠

⁠About MQTT

MQTT is an OASIS standard messaging protocol for the Internet of Things (IoT). It is designed as an extremely lightweight publish/subscribe messaging transport that is ideal for connecting remote devices. MQTT can be used to relay the PV data to various home automation software such as Home Assistant⁠

⁠About Home Assistant

Home Assistant (hass) is an open source home automation platform. Hass features an energy dashboard in which energy generation, storage and usage data can be combined in a dashboard giving a total overview of energy flow. Using MQTT, the power and energy generation data from Huawei's FusionSolar Kiosk can be fed into Home Assistant. This project can then act as a data source for the solar production section of the HASS energy dashboard.

Hass can easily be connected to an MQTT using the MQTT integration, which can be set up using the hass web interface. Once hass is connected to MQTT, PyFusionSolarDataRelay publishes a HASS MQTT device discovery topic so that home assistant automatically recognizes the devices for which measurements are relayed. No configuration in home assistant sensors is required.

Once everything is configured, solar data will flow as follows:

[FusionSolar (Kiosk/Northbound) API] --> [PyFusionSolarDataRelay] --> [MQTT Server] --> [Home Assistant]

For those of you using Docker, a docker-compose.yml file is provided here⁠ in order to get these different components up and running quickly.

⁠About Kenter's klantportaal.kenter.nu

Kenter provides measurement services for commercially rented grid transformers. This project can fetch energy usage data from this API and post it to InfluxDB. MQTT/PVOutput is not supported for posting Kenter data, as Kenter's latest measurement data is usually 3 days old and PVOutput imposes challenges on having the datapoint timestamps between grid usage and PV output synchronous.

⁠Configuration parameter documentation

ParameterDescriptionDefault
debug_modeEnables verbose loggingFalse
fetch_on_startupStarts API fetching and processing on startup one, then schedule cron jobsFalse
site_descriptive_nameDescriptive name for complete site. Use lowercase, and no special characters. This will be used for MQTT topics and InfluxDB record tagssite01
fusionsolar_kiosk_module_enabledCan be True or False, determines if fusionsolar kiosk API functionality is enabledTrue
fusionsolar_kiosk_fetch_cron_hourHour component for python cron job to fetch and process data from fusionsolar.*
fusionsolar_kiosk_fetch_cron_minuteMinute component for python cron job to fetch and process data from fusionsolar0,30
fusionsolar_kiosks__0__descriptive_nameDescriptive name for PV system for which this kiosk entity provides data. Use lowercase, and no special characters. This will be used for InfluxDB record tagsinverter01
fusionsolar_kiosks__0__enabledTo disable individual kiosk configurations. Can be True or FalseTrue
fusionsolar_kiosks__0__api_urlLink to the fusionsolar kiosk data backend, multiple records supported by adding an extra param with __1__ etc.Click url⁠
fusionsolar_kiosks__0__api_kkidUnique kiosk ID, can be found by looking the kiosk URL and then taking the code after kk=GET_THIS_FROM_KIOSK_URL
fusionsolar_kiosks__0__output_influxdbWrite to influxdb if influx module enabled. Can be True or FalseTrue
fusionsolar_kiosks__0__output_mqttWrite to mqtt if mqtt module enabled. Can be True or FalseTrue
fusionsolar_kiosks__0__output_pvoutputIf pvoutput_module_enabled then write this pv metric to pvoutputFalse
fusionsolar_kiosks__0__output_pvoutput_system_idSystem ID for PVOutput.org, should be numeric0
fusionsolar_open_api_module_enabledCan be True or False, determines if fusionsolar OpenAPI functionality is enabledTrue
fusionsolar_open_api_urlLink to the fusionsolar OpenAPI data backend.Click url⁠
fusionsolar_open_api_user_nameUsername for FusionSolar Northbound OpenAPI.
fusionsolar_open_api_system_codePassword for FusionSolar Northbound OpenAPI.
fusionsolar_open_api_cron_hourHour component for python cron job to fetch and process data from fusionsolar.*
fusionsolar_open_api_cron_minuteMinute component for python cron job to fetch and process data from fusionsolar*/5
fusionsolar_open_api_mqtt_for_discovered_devWrite KPI's to MQTT for devices discovered over the API without a matching dev_idTrue
fusionsolar_open_api_influxdb_for_discovered_devWrite KPI's to InfluxDB for devices discovered over the API without a matching dev_idTrue
fusionsolar_open_api_inverters__0__descriptive_nameDescriptive name for inverter. Use lowercase, and no special characters. This will be used for InfluxDB record tagsinverter01
fusionsolar_open_api_inverters__0__enabledTo disable individual OpenAPI inverter configurations. Can be True or FalseTrue
fusionsolar_open_api_inverters__0__dev_idUnique device ID nr, can be found by inspecting ./cache/fusion_solar_openapi_devices.json or inspecting stdout logs after startup
fusionsolar_open_api_inverters__0__output_influxdbWrite to influxdb if influx module enabled. Can be True or FalseTrue
fusionsolar_open_api_inverters__0__output_mqttWrite to mqtt if mqtt module enabled. Can be True or FalseTrue
fusionsolar_open_api_inverters__0__output_pvoutputIf pvoutput_module_enabled then write this pv metric to pvoutputFalse
fusionsolar_open_api_inverters__0__output_pvoutput_system_idSystem ID for PVOutput.org, should be numeric0
fusionsolar_open_api_meters__0__descriptive_nameDescriptive name for grid meter. Use lowercase, and no special characters. This will be used for InfluxDB record tagsmeter01
fusionsolar_open_api_meters__0__enabledTo disable individual OpenAPI meter configurations. Can be True or FalseTrue
fusionsolar_open_api_meters__0__dev_idUnique device ID nr, can be found by inspecting ./cache/fusion_solar_openapi_devices.json or inspecting stdout logs after startup
fusionsolar_open_api_meters__0__output_influxdbWrite to influxdb if influx module enabled. Can be True or FalseTrue
fusionsolar_open_api_meters__0__output_mqttWrite to mqtt if mqtt module enabled. Can be True or FalseTrue
kenter_module_enabledCan be True or False, determines if data is fetched from Kenter's klantportaal.kenter.nu APIFalse
kenter_api_urlKenter API url for fetching transformer grid measurementsClick url⁠
kenter_token_urlKenter API url for fetching auth tokenClick url⁠
kenter_clientidUsername for Kenter's APIuser
kenter_passwordPassword for Kenter's APIpasswd
kenter_fetch_cron_hourHour component for python cron job to fetch and process data from Kenter.8
kenter_fetch_cron_minuteMinute component for python cron job to fetch and process data from Kenter0
kenter_days_backKenter's klantportaal.kenter.nu does not provide live data. Data is only available up until an X amount of days back. May vary per transformer.1
kenter_days_backfillHow many additional days before days_back to process on startup0
kenter_metering_points__0__descriptive_nameDescriptive name for transformer. Use lowercase, and no special characters. This will be used for MQTT topics and InfluxDB record tagstransformer01
kenter_metering_points__0__connection_idConnectionId as shown in meter list on startup stdout (EAN code)XXX
kenter_metering_points__0__metering_point_idMeteringPointId as shown in meter list on startup stdoutXXX
kenter_metering_points__0__channel_idSee kenter API docs, 16180 is delivery for allocation with transformer correction factor for billing, 10180 is delivery kWh from an individual meter16180
kenter_metering_points__0__output_influxdbWrite to influxdb if influx module enabled. Can be True or FalseTrue
influxdb_module_enabledCan be True or False, determines if InfluxDB processing is enabledFalse
influxdb_is_v2If True the InfluxDBv2 methods are used. If False InfluxDBv1 methods are usedTrue
influxdb_hostHostname of the influxdb serverlocalhost
influxdb_portPort of influxdb server8086
influxdb_v1_db_nameDatabase name for InfluxDBv1, only required if influx2=Falsefusionsolar
influxdb_v1_usernameUsername for InfluxDBv1, only required if influx2=Falsefusionsolar
influxdb_v1_passwordPassword for InfluxDBv1, only required if influx2=Falsefusionsolar
influxdb_v2_protocolProtocol for InfluxDBv2, can be https or http, only required if influx2=Truehttps
influxdb_v2_orgOrganization for InfluxDBv2, only required if influx2=Trueacme
influxdb_v2_bucketBucket for InfluxDBv2, only required if influx2=Truefusionsolar
influxdb_v2_tokenToken for InfluxDBv2, only required if influx2=TrueXXXXXXX
pvoutput_module_enabledCan be True or False, determines if PVOutput.org API is enabledFalse
pvoutput_record_urlAPI url for PVOutput.org live output postingClick url⁠
pvoutput_api_keyAPI Key for PVOutput.orgyourapikey
mqtt_module_enabledCan be True or False, determines if MQTT publishing is enabledFalse
mqtt_hostHostname of MQTT serverlocalhost
mqtt_portPort of MQTT server1883
mqtt_authCan be True or False, determines if MQTT authentication is enabledFalse
mqtt_usernameMQTT Usernamefusionsolar
mqtt_passwordMQTT Passwordfusionsolar
mqtt_root_topicMQTT Topic for publishingpyfusionsolar
mqtt_hass_discovery_enabledAutomatically publish all sensors in MQTT home assistant device discoveryTrue

⁠Changelog

VersionDescription
2.0.1Now sending MQTT device discovery message
2.0.1Bugfix in environment variable parsing for custom pydantic nested env list parser
2.0.0Introduced possibility to configure multiple input sources (kiosks, openapi meters/inverters and kenter meters)
2.0.0Implemented Huawei Northbound OpenAPI as data source for metrics
2.0.0Now supporting Kenter API v2
2.0.0Removed currentPower kiosk property (fetched from powercurve API obj) in favor of realTimePower
2.0.0Removed functionality to write utility grid consumption (non-pv) to PVOutput (InfluxDB fully supported!)
2.0.0BREAKING CHANGE: Environment variables for config changed names and structure. Please review the configuration section in README for updated variable names
2.0.0Refactored class names and .py file structure
2.0.0Implemented pydantic to replace pvconf.py, now supporting non-environment variable based settings using config.yaml
1.0.6Fixed a bug parsing the environment cron settings, which are in string format, but were interpreted as int, causing an exception
1.0.6FusionSolar API will now immediately be queried on startup if debug mode is enabled (so no waiting for cron to trigger is required for testing)
1.0.5Added InfluxDB support for an optional secondary grid telemetry EAN configuration (pvoutput output is only supported on the primary EAN)
1.0.5Bugfix for InfluxDB v1 implementation and removed auto-database creation for VictoriaMetrics compatibility
1.0.3Grid transformer usage measurement polling from Kenter's klantportaal.kenter.nu API has been implemented
1.0.3Changed docker-compose.yml template not to use host networking mode
1.0.3main.py now uses separate threads for RelayFusionSolar and RelayKenter classes
1.0.3Implemented apscheduler's cron implementation to be able to specify exact moments to fetch fusionsolar data
1.0.3Code and method name refactoring including PvConf type hints in classes where this class was injected as method parameter

Released under MIT⁠ by @JasperE84⁠.

This project has been partly developed in time donated by Contour - Sheet metal supplier⁠

Dit project is deels ontwikkeld ontwikkeld in de tijd van Contour - Plaatwerkleverancier⁠

Tag summary

Content type

Image

Digest

sha256:40c73ecf8…

Size

82 MB

Last updated

over 1 year ago

docker pull jsprnl/pyfusionsolardatarelay