Skip to content

Repository files navigation

smadata2ha - SMAData1 to Home Assistant via MQTT

A native Rust implementation of the SMANet (SMAData1) protocol is provided to integrate legacy SMA inverters (like the Sunny Boy 2500) into Home Assistant via MQTT Discovery.

A lightweight alternative to the YASDI library is provided by this project, which is specifically tailored for integration with Home Assistant.

Project Description

The gap between old SMA RS485 communication and modern home automation is bridged by this project. A more mature alternative that uses yasdi is yasdi2mqtt.

This hobby project was created primarily for the integration of an old Sunny Boy 2500 in pure Rust. The need to use FFI for integrating yasdi is eliminated.

This project, including this README, was completely written with AI assistance (Gemini Flash/Pro). No manual code review has been performed. The status is marked as WorksForMe 😀

Disclaimer

Warning

This project was written completely with AI. No responsibility is taken for any damages or issues caused by the use of this software. DAMAGE TO YOUR INVERTER CAN BE CAUSED BY THIS SOFTWARE! IT SHOULD BE USED ONLY FOR EDUCATIONAL PURPOSES! A WARNING HAS BEEN ISSUED!

This project is not affiliated with SMA Solar Technology AG or Home Assistant.

Command Line Parameters

Several command-line flags for configuration and debugging are supported by the application:

ParameterShortDescription
--config-cPath to the configuration file (default: config.yml)
--info-iShow discovered device information and exit
--spot-sPrint all available spot values from the inverter and exit
--read-rRead a specific telemetry channel by name and exit
--help-hShow help information

Configuration Values

A YAML configuration file (config.yml) is used by the application. An example with available options is provided below:

serial:
port: "/dev/ttyUSB_sma"# Path to your RS485 adapterbaud_rate: 1200# Usually 1200 for SMAData1dictionary:
path: "./dicts"# Path to the SMANet dictionary filesmqtt:
host: "localhost"# MQTT Broker addressport: 1883# MQTT Broker portclient_id: "smadata2ha"# Unique client IDtopic_prefix: "sma"# Prefix for MQTT topicstelemetry:
channels: # List of channels to monitor and send to HA
- "E-Total"
- "Pac"
- "Inv.TmpVal"

Home Assistant Integration

MQTT Discovery is leveraged by this application, meaning the inverter will be automatically detected by Home Assistant as a new device with all configured sensors once the application is running and connected to the broker.

Appropriate Home Assistant device_class and state_class attributes (such as energy and total_increasing for E-Total, power and measurement for Pac, and temperature and measurement for Inv.TmpVal) are automatically detected and configured. This ensures full integration with Home Assistant features, including the Energy dashboard.

A clean device page is created in Home Assistant by the integration, where all configured telemetry data such as current power (Pac), total energy (E-Total), and inverter temperature are shown.

Home Assistant Device View

Visualization

For a great overview of the energy flow, the use of the Power Flow Card Plus is recommended.

Power Flow Card Plus

Example Dashboard Configuration

The following configuration can be used to integrate the Power Flow Card Plus with the SMA inverter (the serial number 1234567890 should be replaced with the actual inverter's serial number):

type: custom:power-flow-card-plusentities:
grid:
entity: sensor.sml_12345678901234567890_power_current_totalsolar:
entity: sensor.sma_1234567890_pac

Docker

smadata2ha can be run as a Docker container.

Build the Image

docker build -t smadata2ha .

Docker Compose Example

The serial device must be mapped into the container.

services:
smadata2ha:
image: smadata2ha:latestrestart: unless-stoppeddevices:
- "/dev/ttyUSB_sma:/dev/ttyUSB_sma"volumes:
- "./config.yml:/app/config.yml:ro"
- "./dicts:/app/dicts"

Pull Requests are Welcomed

Issues can be opened or pull requests can be submitted. If time allows, they will be reviewed.

Credits

Thanks to everybody who contributed to a part that is used by this project or was used to develop it.

License

This project is licensed under the MIT License.

About

SMAData1 to Home Assistant via MQTT

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages