跳转到主要内容

从Deye微型逆变器获取信息

项目描述

逆变器

tests codecov inverter-connect @ PyPi Python Versions License GPL-3.0-or-later

从Deye微型逆变器获取信息

目前这只是一个学习练习。我们将拭目以待。

快速入门

概述

  • 克隆源代码
  • 通过调用 ./cli.py edit-settings 来初始化和创建默认用户设置
  • 根据您的需求更改设置
  • ...使用命令... ;)
  • 设置systemd服务以通过MQTT将逆变器值发布到Home Assistant实例

目前仅克隆项目并启动cli(这将创建虚拟环境并安装所有依赖项)

注意:如果您在Raspberry Pi上,请启用https://www.piwheels.org/

例如:

~$ git clone https://github.com/jedie/inverter-connect.git
~$ cd inverter-connect
~/inverter-connect$ ./cli.py --help

./cli.py --help 的输出看起来像

Usage: ./cli.py [OPTIONS] COMMAND [ARGS]...

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help      Show this message and exit.                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ debug-settings        Display (anonymized) MQTT server username and password                     │
│ edit-settings         Edit the settings file. On first call: Create the default one.             │
│ inverter-version      Print all version information of the inverter                              │
│ print-at-commands     Print one or more AT command values from Inverter.                         │
│ print-values          Print all known register values from Inverter, e.g.:                       │
│ publish-loop          Publish current data via MQTT for Home Assistant (endless loop)            │
│ read-register         Read register(s) from the inverter                                         │
│ set-time              Set current date time in the inverter device.                              │
│ systemd-debug         Print Systemd service template + context + rendered file content.          │
│ systemd-remove        Write Systemd service file, enable it and (re-)start the service. (May     │
│                       need sudo)                                                                 │
│ systemd-setup         Write Systemd service file, enable it and (re-)start the service. (May     │
│                       need sudo)                                                                 │
│ systemd-status        Display status of systemd service. (May need sudo)                         │
│ systemd-stop          Stops the systemd service. (May need sudo)                                 │
│ test-mqtt-connection  Test connection to MQTT Server                                             │
│ version               Print version and exit                                                     │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

为Home Assistant设置systemd服务

通过 ./cli.py edit-settings 更新您的设置,并在 [mqtt] 部分插入MQTT凭证

检查配置部分 [systemd][systemd.template_context],但通常它们不需要更改;)

要验证您的设置,请调用: ./cli.py debug-settings

要查看systemd服务文件内容,请调用: ./cli.py systemd-debug

注意:一些systemd命令需要sudo,因为普通用户无法更改systemd服务!您将看到权限错误,并提示使用sudo调用cli;)

如果一切正常,请使用 sudo ./cli.py systemd-setup 设置并启动systemd服务

使用 sudo ./cli.py systemd-status 检查服务

最重要的命令

publish-loop

./cli.py print-values --help 获取的帮助看起来像

Usage: ./cli.py publish-loop [OPTIONS]

 Publish current data via MQTT for Home Assistant (endless loop)
 The "Daily Production" count will be cleared in the night, by set the current date time via
 AT-command.

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ *  --ip             TEXT                                  IP address of your inverter [required] │
│ *  --port           INTEGER                               Port of inverter services              │
│                                                           [default: 48899]                       │
│                                                           [required]                             │
│ *  --inverter       [deye_2mppt|deye_4mppt|deye_sg04lp3]  Prefix of yaml config files in         │
│                                                           inverter/definitions/                  │
│                                                           [default: deye_2mppt]                  │
│                                                           [required]                             │
│    --verbosity  -v  INTEGER RANGE [0<=x<=3]               Verbosity level; Accepts integer value │
│                                                           e.g.: "--verbose 2" or can be count    │
│                                                           e.g.: "-vv"                            │
│                                                           [default: 0; 0<=x<=3]                  │
│    --help                                                 Show this message and exit.            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

print-values

./cli.py print-values --help 获取的帮助看起来像

Usage: ./cli.py print-values [OPTIONS]

 Print all known register values from Inverter, e.g.:
 .../inverter-connect$ ./cli.py print-values

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ *  --ip             TEXT                                  IP address of your inverter [required] │
│ *  --port           INTEGER                               Port of inverter services              │
│                                                           [default: 48899]                       │
│                                                           [required]                             │
│ *  --inverter       [deye_2mppt|deye_4mppt|deye_sg04lp3]  Prefix of yaml config files in         │
│                                                           inverter/definitions/                  │
│                                                           [default: deye_2mppt]                  │
│                                                           [required]                             │
│    --verbosity  -v  INTEGER RANGE [0<=x<=3]               Verbosity level; Accepts integer value │
│                                                           e.g.: "--verbose 2" or can be count    │
│                                                           e.g.: "-vv"                            │
│                                                           [default: 0; 0<=x<=3]                  │
│    --compact    -c                                        Only show the values concerning power  │
│                                                           generation                             │
│    --help                                                 Show this message and exit.            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

print-values 调用的示例输出

print-values


print-at-commands

./cli.py print-at-commands --help 获取的帮助看起来像

Usage: ./cli.py print-at-commands [OPTIONS] [COMMANDS]...

 Print one or more AT command values from Inverter.
 Use all known AT commands, if no one is given, e.g.:
 .../inverter-connect$ ./cli.py print-at-commands
 Or specify one or more AT-commands, e.g.:
 .../inverter-connect$ ./cli.py print-at-commands WEBVER .../inverter-connect$ ./cli.py
 print-at-commands WEBVER WEBU
 e.g.: Set NTP server, enable NTP and check the values:
 .../inverter-connect$ ./cli.py print-at-commands NTPSER=192.168.1.1 NTPEN=on NTPSER NTPEN
 wait a while and request the current date time:
 .../inverter-connect$ ./cli.py print-at-commands NTPTM
 (Note: The prefix "AT+" will be added to every command)

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ *  --ip             TEXT                     IP address of your inverter [required]              │
│ *  --port           INTEGER                  Port of inverter services [default: 48899]          │
│                                              [required]                                          │
│    --verbosity  -v  INTEGER RANGE [0<=x<=3]  Verbosity level; Accepts integer value e.g.:        │
│                                              "--verbose 2" or can be count e.g.: "-vv"           │
│                                              [default: 0; 0<=x<=3]                               │
│    --help                                    Show this message and exit.                         │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

print-at-commands 调用的示例输出

print-at-commands


read-register

./cli.py read-register --help 获取的帮助看起来像

Usage: ./cli.py read-register [OPTIONS] REGISTER LENGTH

 Read register(s) from the inverter
 e.g.: read 3 registers starting from 0x16:
 .../inverter-connect$ ./cli.py read-register 0x16 3
 e.g.: read the first 32 registers:
 .../inverter-connect$ ./cli.py read-register 0 32
 The start address can be pass as decimal number or as hex string, e.g.: 0x123

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ *  --ip             TEXT                     IP address of your inverter [required]              │
│ *  --port           INTEGER                  Port of inverter services [default: 48899]          │
│                                              [required]                                          │
│    --verbosity  -v  INTEGER RANGE [0<=x<=3]  Verbosity level; Accepts integer value e.g.:        │
│                                              "--verbose 2" or can be count e.g.: "-vv"           │
│                                              [default: 0; 0<=x<=3]                               │
│    --help                                    Show this message and exit.                         │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

示例输出为 read-register 调用

read-register


开始开发

为了开发,我们有一个单独的 CLI,只需调用它

~/inverter-connect$ ./dev-cli.py --help

./dev-cli.py --help 的输出如下

Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help      Show this message and exit.                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ check-code-style            Check code style by calling darker + flake8                          │
│ coverage                    Run and show coverage.                                               │
│ create-default-settings     Create a default user settings file. (Used by CI pipeline ;)         │
│ fix-code-style              Fix code style of all inverter source code files via darker          │
│ install                     Run pip-sync and install 'inverter' via pip as editable.             │
│ mypy                        Run Mypy (configured in pyproject.toml)                              │
│ publish                     Build and upload this project to PyPi                                │
│ safety                      Run safety check against current requirements files                  │
│ test                        Run unittests                                                        │
│ tox                         Run tox                                                              │
│ update                      Update "requirements*.txt" dependencies files                        │
│ update-test-snapshot-files  Update all test snapshot files (by remove and recreate all snapshot  │
│                             files)                                                               │
│ version                     Print version and exit                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

致谢

在我之前,其他人已经做了很好的工作。特别是,我从以下项目中学到了很多

包含的定义 yaml 文件来自

https://github.com/StephanJoubert/home_assistant_solarman/tree/main/custom_components/solarman/inverter_definitions

各种链接

项目详情


下载文件

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

源分发

inverter-connect-0.13.0.tar.gz (69.5 kB 查看散列)

上传时间:

构建分发

inverter_connect-0.13.0-py3-none-any.whl (48.2 kB 查看散列)

上传时间: Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面