Skip to main content

Samil Power 逆变器工具

项目描述

Samil Power 逆变器工具

派皮

通过网络从 Samil Power 逆变器获取模型和状态数据。

如果你只需要 PVOutput.org 上传,你也可以试试 旧版本

支持的逆变器系列

  • 太阳河 TL
  • 太阳河 TL-D
  • SolarLake TL

逆变器需配网线并接入同一个网络,不支持串口。

如果您有 SolarLake TL-PM 系列逆变器,请查看此前叉!-> semonet/太阳能

特征

  • 查看逆变器数据
  • 上传到 PVOutput.org
  • 发布到 MQTT 代理

以下功能未实现,但可根据要求轻松实现:

  • 根据IP或序列号过滤逆变器
  • 支持多个 PVOutput.org 系统

入门

码头工人

您可以使用 Docker 运行任何可用的命令。确保使用主机网络,因为该应用程序依赖于 UDP 广播。该映像目前不是为 ARM 平台(如 Raspberry Pi)构建的,因此对于这些平台,您需要自己构建或通过 pip 安装。

docker run --network host mhvis/samil monitor

这是一个示例compose.yaml

name: "samil"

services:
  samil:
    image: mhvis/samil
    command: monitor  # Adapt as desired
    network_mode: host
    restart: unless-stopped

Ubuntu/Debian/树莓派

$ sudo apt install python3-pip
$ pip3 install --user samil

安装后,调用samil --help使用信息。如果samil找不到该命令,请先尝试重新登录。如果这没有帮助,您需要PATH使用以下命令更改变量并重新登录以应用更改。

$ echo 'PATH="$HOME/.local/bin:$PATH"' >> ~/.profile

其他

$ pip install samil

用法

监视器

该命令samil monitor将在网络中搜索逆变器并打印型号和状态信息。它将连接到它找到的第一个逆变器并每 5 秒打印一次状态数据。有关samil monitor --help其他选项,请参阅。

MQTT

该命令samil mqtt连接到一个或多个逆变器并将状态消息连续发送到 MQTT 代理。这些消息包括逆变器数据,如输入功率、输出功率、能量和温度。

示例:samil mqtt -h 192.168.1.2 -p 1883 --username user --password pw --inverters 2 --interval 10。此命令连接到 address 处的 MQTT 代理192.168.1.2,并使用给定的用户名user和密码进行身份验证pw。它将连接到网络中的 2 个逆变器,并每 10 秒连续发送一条 MQTT 消息。

有关完整的使用信息,请运行samil mqtt --help.

要在启动时运行此命令,请参见下文

PVOutput.org 上传

该命令samil pvoutput从 1 个或多个逆变器收集状态数据并将其上传到您的 PVOutput.org 系统。如果您有多台逆变器,上传前会汇总每台逆变器的数据。

有关完整的使用信息,请运行samil pvoutput --help.

默认情况下,脚本上传一次然后停止。您可以使用 cron 每 5 分钟执行一次脚本。

获取历史数据

去做

在启动时运行命令

按照此处的说明在启动时自动运行 MQTT 或 PVOutput 命令。如果您使用 cron 运行 PVOutput,则不需要这个!

这些说明基于这篇文章 ,并在 2020 年 5 月的 Raspberry Pi OS Lite 版本上进行了测试。

创建一个新服务:

$ sudo systemctl edit --force --full samil.service

在打开的空文件中,插入以下语句,根据需要进行调整,保存并关闭。

[Unit]
Description=Samil
After=multi-user.target

[Service]
# Adjust the command to your needs! Keep the path as is unless you installed to somewhere else.
ExecStart=/home/pi/.local/bin/samil mqtt --host 192.168.1.2

# Adjust if you have a different user account
User=pi
Group=pi

# Automatically restart on crashes after 30 seconds
Restart=on-failure
RestartSec=30

Environment="PYTHONUNBUFFERED=1"  # Leave as is

[Install]
WantedBy=multi-user.target

启用并启动服务:

$ sudo systemctl enable --now samil.service

检查服务是否启动成功:

$ sudo systemctl status samil.service

禁用

如果要停止脚本,请运行:

$ sudo systemctl stop samil.service

如果要禁用脚本在启动时启动:

$ sudo systemctl disable samil.service

背景资料

此处描述了这些逆变器使用的协议 。

以下单位用于状态值:

  • 电压(伏特)
  • 电流安培
  • 以千瓦时为单位的能量
  • 功率(瓦)
  • 以摄氏度为单位的温度
  • 运行时间(小时)

这个项目最初是zombiekipling/solriv的一个分支, 但现在完全重写以实现新的需求。

作为图书馆

您可以将此项目用作库。对于文档,您需要通读源代码。要开始使用,我建议阅读monitor.samil.cli

CLI 参考

以下命令和选项可用:

$ samil monitor --help
Usage: samil monitor [OPTIONS]

  Print model and status info for an inverter.

  When you have multiple inverters, run this command multiple times to
  connect to all inverters.

Options:
  --interval FLOAT  Status interval.  [default: 5.0]
  --interface TEXT  IP address of local network interface to bind to.
  --help            Show this message and exit.
$ samil mqtt --help
Usage: samil mqtt [OPTIONS]

  Publish inverter data to an MQTT broker.

  The default topic format is inverter/<serial number>/status, e.g.
  inverter/DW413B8080/status. The message value is a JSON object with all
  status data from the inverter. Example message value:

      {"operation_mode":"Normal","total_operation_time":45,
      "pv1_input_power":2822.0,"pv2_input_power":0.0,"pv1_voltage":586.5,
      "pv2_voltage":6.7,"pv1_current":4.8,"pv2_current":0.1,
      "output_power":2589.0,"energy_today":21.2,"energy_total":77.0,
      "grid_voltage":242.6,"grid_current":3.6,"grid_frequency":50.01,
      "internal_temperature":35.0}

Options:
  -n, --inverters INTEGER  Number of inverters.  [default: 1]
  -i, --interval FLOAT     Interval between status messages in seconds.
                           [default: 10.0]

  -h, --host TEXT          MQTT broker hostname or IP.  [default: localhost]
  -p, --port INTEGER       MQTT broker port.  [default: 1883]
  --client-id TEXT         MQTT client ID. If not provided, one will be
                           randomly generated.

  --tls                    Enable MQTT SSL/TLS support.
  --username TEXT          MQTT username.
  --password TEXT          MQTT password.
  --topic-prefix TEXT      MQTT topic prefix.  [default: inverter]
  --interface TEXT         IP address of local network interface to bind to.
  --help                   Show this message and exit.
$ samil pvoutput --help
Usage: samil pvoutput [OPTIONS] SYSTEM_ID API_KEY

  Upload inverter status to a PVOutput.org system.

  Specify the PVOutput system using the SYSTEM_ID and API_KEY arguments. The
  command will connect to the inverter, upload the current status data and
  exit. Use something like cron to upload status data every 5 minutes.

  If you have multiple inverters, specify -n with the number of inverters.
  Data of all inverters will be aggregated before uploading to PVOutput,
  energy is summed, voltage and temperature are averaged. For temperature,
  the internal temperature is used, not the heatsink temperature. If the
  inverter uses three phases, the voltage of each phase is averaged.

  If you don't want to use cron, specify the --interval option to make the
  application upload status data on the specified interval. With this mode
  the application will stay connected to the inverters in between uploads,
  this is less recommended.

Options:
  -n INTEGER              Connect to n inverters.  [default: 1]
  --dc-voltage            By default, AC voltage is uploaded, specify this if
                          you want to upload DC (panel) voltage instead.

  -i, --interval INTEGER  Interval between status uploads in minutes, should
                          be 5, 10 or 15. If not specified, only does a single
                          upload.

  --dry-run               Do not upload data to PVOutput.org.
  --interface TEXT        IP address of local network interface to bind to.
  --help                  Show this message and exit.

开发信息

开发安装(通常在虚拟环境中):

pip install -e .
pip install -r dev-requirements.txt

皮棉代码:flake8

运行测试用例:python -m unittest

执照

麻省理工学院

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

samil-2.2.1.tar.gz (21.0 kB 查看哈希)

已上传 source

内置分布

samil-2.2.1-py3-none-any.whl (20.4 kB 查看哈希

已上传 py3