Skip to content

sven/smadata2ha

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:

Parameter Short Description
--config -c Path to the configuration file (default: config.yml)
--info -i Show discovered device information and exit
--spot -s Print all available spot values from the inverter and exit
--read -r Read a specific telemetry channel by name and exit
--help -h Show 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 adapter
  baud_rate: 1200          # Usually 1200 for SMAData1

dictionary:
  path: "./dicts"          # Path to the SMANet dictionary files

mqtt:
  host: "localhost"        # MQTT Broker address
  port: 1883               # MQTT Broker port
  client_id: "smadata2ha"  # Unique client ID
  topic_prefix: "sma"      # Prefix for MQTT topics

telemetry:
  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.

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-plus
entities:
  grid:
    entity: sensor.sml_12345678901234567890_power_current_total
  solar:
    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:latest
    restart: unless-stopped
    devices:
      - "/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

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages