GNU Affero General Public License v3.0

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

wlcrs/huawei_solar 项目深度分析

项目背景与痛点

随着居家智能设备的普及,能源管理和监控成为了一个日益重要的领域。Huawei Solar 逆变器通过 Modbus 协议提供了丰富的数据接口,然而,要在智能家庭管理平台 Home Assistant 中集成这些逆变器的数据,却面临不少挑战。开发者在其中需要打通 Modbus 协议接口,实现数据读取,并将数据转化成 Home Assistant 能识别的格式,以便用户可以方便地查看和管理逆变器的运行状态。

核心技术揭秘

wlcrs/huawei_solar 项目巧妙地接入了 Home Assistant 的生态系统,通过 Modbus 协议实现与 Huawei Solar 逆变器的数据交互。项目的核心架构如下:

graph TD A[Home Assistant 用户界面] --> B[homeassistant_custom_component] B --> C[Sensors (Huawei Solar)] C --> D[modbus_async (Custom Component)] D --> E[Modbus TCP Adapter] E --> F[Huawei Solar Inverter]

项目通过 Home Assistant 的自定义组件(custom component)机制,创建了专门用于与 Huawei Solar 逆变器通信的传感器组件。这些传感器组件通过 modbus_async 这个自定义组件与逆变器进行数据交互。modbus_async 组件封装了整个 Modbus 通信协议栈,提供了异步通信的能力,这对于对实时性和并发性有高要求的智能家居系统来说尤为重要。

功能亮点与差异

wlcrs/huawei_solar 项目的独特之处在于它不仅仅是简单地提供了一套通信接口,而是深耕在 Modbus 协议的细节上,对数据流进行了细化处理。开发者通过对逆变器数据的解析与封装,更好地服务于 Home Assistant 生态系统的用户。

在功能方面,具备以下亮点:

  • 数据实时更新:通过异步调用机制,确保数据更新的即时性。
  • 易于集成:与 Home Assistant 完美融合,用户在任何 Home Assistant 设备上可无缝查看数据。
  • 丰富的指示信息:提供详细的逆变器运行状态报告,如功率、温度、电流等。

这使得该项目在同类竞品中脱颖而出,成为智能家居能源管理中不可或缺的一部分。

应用场景与落地建议

在生产环境中应用 wlcrs/huawei_solar 项目需要注意以下几点:

  • 网络稳定性:确保网络环境稳定,以便 Modbus 数据的可靠传输。
  • 权限管理:适当设置逆变器的访问权限,避免数据被误操作。
  • 同步机制:考虑到逆变器数据更新的频率较高,需优化同步机制,以免过于频繁的数据刷新影响系统性能。

适合的应用场景包括:

  • 智能家庭:提供全面的能源使用报告,辅助用户做出最佳决策。
  • 商业楼宇:用于建筑能源管理,降低能耗,提升建筑能效。

综合评价

wlcrs/huawei_solar 项目以 Home Assistant 为平台,通过 Modbus 协议打通 Huawei Solar 逆变器的数据接入,具备良好的实时性与双向数据交互能力。项目设计合理,集成难度适中,可以满足多种智能能源管理需求。

当然,也有改进空间:

  • 错误处理优化:加强在 Modbus 通信异常处理上的精细度,提升系统的健壮性。
  • 数据安全:数据传输过程中的加密处理仍有提升空间,以防止潜在的网络安全威胁。

整体而言,wlcrs/huawei_solar 是一款出色的智能家居能源管理工具,高度推荐给有相关需求的开发者与用户。

关于

GitHub 原始描述(英文)

Home Assistant integration for Huawei Solar inverters via Modbus

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
1257
价值分
610
活跃状态
活跃

语言占比

Python

Release

README

Huawei Solar Integration

hacs_badge GitHub release Documentation

This integration exposes the information and functions made available by Huawei Solar installations over Modbus to Home Assistant.

Table of Contents

Looking for more information? The Wiki contains in-depth documentation and support materials.

Screenshots

Inverter Battery
Inverter Sensors Battery Sensors
Inverter Configuration Battery Configuration
Inverter Diagnostics
Power Meter Optimizer
Power Meter Sensors Optimizer Sensors

HA Energy Dashboard

energy-config

Services

This integration exposes multiple services, allowing you to actively control the amount of electricity exported to the grid and forcibly charge/discharge your battery.

services

To enable these advanced features, you need to select ‘Elevate permissions’ during the setup of this integration.

Prerequisites

Connection

This integration supports two connection modes to Huawei solar devices:

  • direct serial connection to the RS485A1 and RS485B1 pins of the COM port of SUN2000 inverters
  • network connection

Detailed information can be found on the ‘Connecting to the inverter’ Wiki-page

Note 注意

Modbus devices only support one connection at a time.

Make sure that nothing else is trying to connect to your Huawei solar installation. Otherwise the connection from this integration to your installation will constantly be interrupted.

Firmware

This integration supports inverters running firmware versions released in 2023 and later. Older firmware versions don’t have support for all registers, which can result in the integration failing to work properly.

Installation

  1. Install this integration with HACS, or copy the contents of this repository into the custom_components/huawei_solar directory Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

  2. Restart HA

  3. Start the configuration flow:

    • Start Config Flow
    • Or: Go to Configuration -> Integrations and click the + Add Integration. Select Huawei Solar from the list
  4. Choose whether you want to connect via serial or network connection

Serial configuration

  1. Select the “USB to RS485 converter” that you connected to the RS485A1 and RS485B1 pins of your inverter. The Slave ID should be identical to the Com address set in the RS485_1 settings.

Network configuration

  1. Enter the IP address and port on which the Modbus-TCP interface is available. Some pointers:

    • The port is either 502 or 6607.
    • When connecting to the inverter AP the host IP is typically 192.168.200.1 and the slave id is typically 0.
    • When connecting to an SDongle, the slave id is typically 1. Make sure to give this device a fixed IP!

    Checking the Advanced: elevate permissions checkbox will:

    • give you access to optimizer data
    • enable you to dynamically change your inverter and battery settings

  1. When using the elevate permissions feature in combination with certain connection methods (most TCP-connections, not for serial connections), you will be asked to enter the credentials to the installer account in a next step. These are the credentials used to connect to the inverter in the “Device Commissioning” section of the FusionSolar App. The default password is either 00000a or 0000000a. If necessary, you can perform a password reset. This will not reset other parameters like the FusionSolar cloud connection or other changes made by the firm which did your solar installation.

Inverter polling frequency

The integration will poll the inverter for new values every 30 seconds. If you wish to receive fresh inverter data less (or more) frequently, you can disable the automatic refresh in the integration’s system options (Enable polling for updates) and create your own automations with your desired polling frequency. If your installation contains a power meter and/or battery, then you need to create a separate data polling automation for these devices. This allows for fine grained control of which entities must be updated more quickly.

- alias: "Huawei Solar inverter data polling"
  trigger:
    - platform: time_pattern
      hours: "*"
      minutes: "*"
      seconds: "/20"
  action:
    - service: homeassistant.update_entity
      target:
        entity_id: sensor.inverter_daily_yield
- alias: "Huawei Solar power meter data polling"
  trigger:
    - platform: time_pattern
      hours: "*"
      minutes: "*"
      seconds: "/5"
  action:
    - service: homeassistant.update_entity
      target:
        entity_id: sensor.power_meter_active_power
- alias: "Huawei Solar battery data polling"
  trigger:
    - platform: time_pattern
      hours: "*"
      minutes: "*"
      seconds: "/20"
  action:
    - service: homeassistant.update_entity
      target:
        entity_id: sensor.battery_state_of_capacity

Note: optimizer data is refreshed only every 5 minutes, which matches how frequently the inverter refreshes this data. Increasing the update frequency of those entities will thus not result in a higher resolution.

FAQ - Troubleshooting

Q: The Daily Yield/Total Yield is incorrect: it also goes up when the battery is discharging.

A: Huawei does not provide a Modbus register that represents the output of the inverter produced by energy coming only from the solar panels. It does provide a register that represents the input of the solar panels, but that does not take into account the conversion losses of the inverter. cfr. the Wiki page ‘Daily Solar Yield’ for some possible workarounds. cfr. #1 for more context.


Q: Why do I get the error “Connection succeeded, but failed to read from inverter.” while setting up this integration?

A: While the integration was able to setup the initial connection to the Huawei Inverter, it did not respond to any queries in time. This is either caused by using an invalid slave ID (typically 0 or 1, try both or ask your installer if unsure), or because an other device established a connection with the inverter, causing the integration to lose it’s connection


Q: Will the FusionSolar App still work when using this integration?

A: The inverter will still send it’s data to the Huawei cloud, and you will still be able to see live statistics from your installation in the FusionSolar App. However, if you are using this integration via the network, and you (or your installer) need to use the ‘Device commissioning’ feature of the app, you will need to disable this integration.


Q: I want to connect multiple systems simultaniously to the Huawei Solar inverter. For example: 2 HA installations, EVCC, … Is this possible?

A: This integration connects to the inverter over Modbus. This protocol only supports one “server” (confusingly named, but this is the party sending queries to the inverter). It is therefore not possible to connect multiple systems directly to the inverter. However, you can use a Modbus Proxy to multiplex the connection to the inverter.


Q: How do I change the connection parameters (IP, port, USB device, installer password) of this integration?

A: ‘Reconfigure’ the integration. This action is available from the dropdown menu on the integration settings page.


Q: The “Daily Yield” value reported does not match with the value from FusionSolar?

A: The “Daily Yield” reported by the inverter is the output yield of the inverter, and not the input from your solar panels. It therefore includes the yield from discharging the battery, but misses the yield used to charge the battery. FusionSolar computes the “Yield” by combining the values from “Daily Yield”, “Battery Day Charge” and “Battery Day Discharge”. More information on the Wiki …


Q: I can’t get this integration to work. What am I doing wrong?

A: First make sure that ‘Modbus TCP’ access is enabled in the settings of your inverter. Next, check if the port is correct. Some inverters use port 6607 instead of 502 (this can change for you after a firmware update!). If that doesn’t work for you, and you intend to write an issue, make sure you have the relevant logs included. For this integration, you can enable all relevant logs by including the following lines in your configuration.yaml:

logger:
  logs:
    tmodbus: debug # only include this if you're having connectivity issues
    huawei_solar: debug
    homeassistant.components.huawei_solar: debug

By providing logs directly when creating the issue, you will likely get help much faster.


Q: I didn’t check ‘Advanced: Elevate permissions’ during the initial setup of this integration and changed my mind. How do I change this?

A: ‘Reconfigure’ the integration. This action is available from the dropdown menu on the integration settings page.

Translations

Do you want to help out by translating this integration? This project uses Crowdin to make it easy to contribute translations. Use this invite link to get started.

评论

暂无评论