GithubHelp home page GithubHelp logo

ccorderor / huawei-sun2000-modbus-mqtt Goto Github PK

View Code? Open in Web Editor NEW
36.0 36.0 19.0 402 KB

Monitoring the Huawei SUN2000L KTL L1 inverter via Modbus TCP and publishing the values to MQTT

Dockerfile 2.81% Python 97.19%

huawei-sun2000-modbus-mqtt's People

Contributors

albin-sunnanbo-sveasolar avatar carlioth avatar ccorderor avatar hydra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

huawei-sun2000-modbus-mqtt's Issues

Huawei Sun2000 - Using NodeRed and ModBus to generate the MQTT messages instead of python code

Hi everyone,

I was using this library for a while, it served me well, but I recently decided that I wanted more data from my inverter inside node-red and to log it to an influx db, and this python script didn't expose what I wanted so I took the plunge and created a nodered flow that uses ModBus directly, no additional docker image or python script to maintain separately.

here's the nodered flow code:

huawei-solar-modbus.json

here's a screenshot:

image

  • you can use this as an interim solution if you want to transition your existing setups that use the emon/* topics.
  • the script only posts to MQTT topics the same data that I was previously using from this script, you might want additional data, but see the script for examples on how to do it.
  • you can use this script as a starting point to extract information from the inverter into your nodered flows without using mqtt at all, e.g. by linking your existing mqtt inputs directly to the outputs of the 'change' nodes that extract the information from the modbus messages.
  • I've not fully polished this flow, there may be typos, errors etc, but if you're interested you'll probably find it useful as-is.

an example 'process device status' output message payload looks like this:

{"state_1":[{"bits":[0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0],"bit0":0,"bit1":1,"bit2":1,"bit3":0,"bit4":0,"bit5":0,"bit6":0,"bit7":0,"bit8":0,"bit9":0,"bit10":0,"bit11":0,"bit12":0,"bit13":0,"bit14":0,"bit15":0}],"state_2":[{"bits":[1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0],"bit0":1,"bit1":0,"bit2":1,"bit3":0,"bit4":0,"bit5":0,"bit6":0,"bit7":0,"bit8":0,"bit9":0,"bit10":0,"bit11":0,"bit12":0,"bit13":0,"bit14":0,"bit15":0}],"state_3":0,"alarm_1":[{"bits":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"bit0":0,"bit1":0,"bit2":0,"bit3":0,"bit4":0,"bit5":0,"bit6":0,"bit7":0,"bit8":0,"bit9":0,"bit10":0,"bit11":0,"bit12":0,"bit13":0,"bit14":0,"bit15":0}],"alarm_2":[{"bits":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"bit0":0,"bit1":0,"bit2":0,"bit3":0,"bit4":0,"bit5":0,"bit6":0,"bit7":0,"bit8":0,"bit9":0,"bit10":0,"bit11":0,"bit12":0,"bit13":0,"bit14":0,"bit15":0}],"alarm_3":[{"bits":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"bit0":0,"bit1":0,"bit2":0,"bit3":0,"bit4":0,"bit5":0,"bit6":0,"bit7":0,"bit8":0,"bit9":0,"bit10":0,"bit11":0,"bit12":0,"bit13":0,"bit14":0,"bit15":0}],"pv1_voltage_v":0,"pv1_current_a":0,"pv2_voltage_v":0,"pv2_current_a":0,"input_power_kw":0,"power_grid_voltage_c":234.5,"power_grid_curent_a":0,"peak_active_power_today_kw":5.22,"active_power_kw":0.679,"reactive_power_kw":0,"power_factor_kvar":1,"grid_hz":49.92,"efficiency_percent":100,"internal_temperature_c":29.400000000000002,"insulation_resistance_mohms":3,"device_status":512,"fault_code":0,"startup_time_s":1710921425,"shutdown_time_s":4294967295,"accumulated_energy_yield_kwh":1979.654,"daily_energy_yield_kwh":1.605,"running_status":2,"charge_discharge_w":-731,"bus_voltage_v":438.70000000000005,"battery_soc_percent":92,"working_mode":0.4,"rated_charge_power_w":500,"rated_discharge_power_w":500,"fault_id":0,"current_day_charge_capacity_kwh":8.97,"current_day_discharge_capacity_kwh":6.99,"bus_current":-1.7000000000000002,"battery_temperature_c":36.7,"remaining_time_m":0,"dcdc_version":"","bms_version":"","maximum_charge_power_w":5000,"maximum_discharge_power_w":500,"serial_number":"BT21804169","total_charge_kwh":5583.35,"total_discharge_kwh":5447.14,"device_status_message":"On-Grid"}

Here's what a simple graph in InfuxDB looks like using the above:

Screenshot 2024-03-20 202046

Note that on my inverter's dongle firmware it's not possible to have 2 programs connected to the modbus on tcp port 502. i.e. both the python script from this project running at the same time as the NodeRed modbus 'server' instance, thus you can only use either this projects python code, or this nodered flow.

Hope this is useful to someone.

Unable to get this working

Hi there,

Trying to get this working. I also have a SUN2000-5KTL-L1. I have a vanilla RPI4 with Rabian OS Lite. I've installed your docker image and changed the config as my Sun2000 IP is 192.168.200.1:6607 (port 502 isn't used in the latest firmware).

When I try run the app I get the following error:
sudo docker run huawei-solar Traceback (most recent call last): File "huaweisolar.py", line 2, in <module> from huawei_solar import HuaweiSolar File "/usr/local/lib/python3.8/site-packages/huawei_solar/__init__.py", line 6, in <module> from .bridge import HuaweiSolarBridge # noqa File "/usr/local/lib/python3.8/site-packages/huawei_solar/bridge.py", line 15, in <module> from huawei_solar.huawei_solar import AsyncHuaweiSolar, Result File "/usr/local/lib/python3.8/site-packages/huawei_solar/huawei_solar.py", line 35, in <module> from .registers import REGISTERS, RegisterDefinition File "/usr/local/lib/python3.8/site-packages/huawei_solar/registers.py", line 216, in <module> class TimeOfUseRegisters(RegisterDefinition): File "/usr/local/lib/python3.8/site-packages/huawei_solar/registers.py", line 228, in TimeOfUseRegisters ) -> list[LG_RESU_TimeOfUsePeriod]: TypeError: 'type' object is not subscriptable

Any ideas or things I could troubleshoot?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.