Skip to content

About

Collects data from Modbus devices like SolarEdge inverters and exports it as JSON, XML or to Prometheus/InfluxDB.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

EnergyExporter (previously SolarEdgeExporter)

This project was renamed and refactored to be usable for other devices than just SolarEdge.

Collects data from Modbus devices like inverters, batteries or energy meters and exports it as JSON, XML or to Prometheus/InfluxDB and Mqtt.

The data is queried over Modbus TCP. For now, the following devices are supported:

  • SolarEdge (over SunSpec)
    • Inverters
    • Energy meters
    • Batteries (StorEdge, BYD, ...)
  • Janitza
    • Energy Meters
      • UMG 96-PA with UMG 96-PA-RCM-EL Ethernet module

Other device models that use similar Modbus registers may also work.

It's possible to query any number of devices at the same time.

Usage

Configuration

This exporter can be configured through commandline arguments, environment variables (details) or via a appsettings.json file. The last option is probably the easiest.

You can find an example for such a configuration file at src/EnergyExporter/appsettings.sample.json. This shows all available configuration options. Just create your own appsettings.json based on that sample.

The Devices section is the main part and configures all the devices that should be queried via Modbus TCP, grouped by vendor. When multiple configured devices use the same Modbus TCP server, the TCP connection is shared between them, as many devices (e.g. SolarEdge) don't allow multiple clients to connect to Modbus TCP at the same time.

When the Modbus devices are in a master-slave configuration, the Unit number should be counted up for every slave. If you don't know the correct order, you can just try different options. If the exporter hangs on start, the Unit number is probably wrong and it doesn't receive any response from the device.

The InfluxDB section in the export configuration is fully optional and can be configured to push all queried metrics directly to an InfluxDB instance. If you don't need that, just remove that section.

Likewise, the Mqtt section in the export configuration is optional and can be configured to publish all queried metrics directly to an MQTT broker. If you don't need it, just remove that section, too.

If needed, you can enable extended logging by setting the default log level in appsettings.json to Debug.

Run the exporter

Using Docker

This repository provides Docker images using the GitHub Container Registry to get things running easily: Images

Sample docker-compose.yml:

energy-exporter:
    image: ghcr.io/jamesvarty/energy-exporter:master
    container_name: energy-exporter
    ports:
        - "14552:14552"
    volumes:
        - /path/to/appsettings.json:/app/appsettings.json
    restart: always

Using .NET

You can also install the .NET SDK on your system and run the exporter this way:

  • Pull this repository and navigate into src/EnergyExporter
  • Create an appsettings.json (see appsettings.sample.json) with your configuration options
  • Execute dotnet run -c Release

Access metrics

While the exporter is running and has access to the Modbus TCP interface, it will query all data for the available devices in a regular interval (IntervalSeconds).

Now visit the IP address and port (14552 by default) of the running exporter to open the management UI.

The available URLs are:

  • /: Management UI showing whether each device is online, its live values, the last error, the state of the InfluxDB/MQTT exporters and recent events. It also has buttons to poll immediately or force a reconnect.
  • /api/status: The data behind the management UI as JSON (POST /api/poll, POST /api/reconnect and POST /api/devices/{id}/reconnect trigger the actions)
  • /metrics: Prometheus metrics
  • /devices: REST API (see Swagger documentation)
  • /swagger: Interactive API documentation

Besides the device values, /metrics contains energy_exporter_device_up, energy_exporter_device_polls_total, energy_exporter_device_poll_failures_total and energy_exporter_device_poll_duration_seconds for every configured device, so you can alert on a device that stopped responding.

Registers that a SunSpec device reports as "not implemented" (e.g. phase 2 and 3 values on a single-phase inverter) are left out of the metrics, InfluxDB and MQTT, and show up as null in the REST API.

Connection handling

All settings in the Polling section are optional:

Setting Default Description
IntervalSeconds 5 Time between polls. A poll never overlaps with the previous one.
ConnectTimeoutSeconds 5 How long to wait for the TCP connection to a device.
ReadTimeoutSeconds 5 How long to wait for a single Modbus response.
Retries 1 How often a read on an existing connection is retried with a fresh connection, e.g. after the inverter dropped it.

When a device stops responding (for example a SolarEdge inverter at night), a single warning is logged and the device is marked offline in the UI. Further failures are only logged at Debug level until the device comes back.

The REST API will export the data in a readable JSON format. If you prefer XML, just set the HTTP Accept header to application/xml and you will get the response as XML.

Vendors

SolarEdge

Enable Modbus TCP

To enable the Modbus TCP interface on your SolarEdge inverter, enable its configuration Wifi (turn the switch on the inverter to P) and connect to it using the QR code on its side. You don't have to use the SolarEdge app, just connect using your phone's WiFi settings. After that you can visit the IP address (the WiFi gateway IP) of the inverter and enable Modbus TCP in the configuration interface.

You can also use the SolarEdge SetApp to enable Modbus TCP, but that will require you to be a verified installer and grant you only read-only access otherwise.

Janitza

This exporter was tested with the UMG 96-PA power analyzer with the UMG 96-PA-RCM-EL Ethernet module. It should also be possible to use an external Modbus gateway instead of the UMG 96-PA-RCM-EL.

About

Collects data from Modbus devices like SolarEdge inverters and exports it as JSON, XML or to Prometheus/InfluxDB.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages