python-pylontech


Namepython-pylontech JSON
Version 0.3.3 PyPI version JSON
download
home_pagehttp://github.com/Frankkkkk/python-pylontech
SummaryInterfaces with Pylontech Batteries using RS485 protocol
upload_time2023-08-14 19:31:50
maintainer
docs_urlNone
authorFrank Villaro-Dixon
requires_python
licenseMIT
keywords pylontech pylon rs485 lithium battery us2000 us2000c us3000
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python-pylontech
Python lib to talk to pylontech lithium batteries (US2000, US3000, ...) using RS485

## What is this lib ?
This lib is meant to talk to Pylontech batteries using RS485. Sadly the protocol over RS485 is not some fancy thing like MODBUS but their own crappy protocol.

## How to use this lib ?
First of all, you need a USB to RS485 converter. They are many available online for some bucks.

Then, you simply need to import the lib and start asking values:
```python

>>> import pylontech
>>> p = pylontech.Pylontech()
>>> print(p.get_values())
Container:
    NumberOfModules = 3
    Module = ListContainer:
        Container:
            NumberOfCells = 15
            CellVoltages = ListContainer:
                3.306
                3.307
                3.305
                3.305
                3.306
                3.305
                3.304
                3.305
                3.306
                3.306
                3.307
                3.307
                3.308
                3.307
                3.306
            NumberOfTemperatures = 5
            AverageBMSTemperature = 29.81
            GroupedCellsTemperatures = ListContainer:
                29.61
                29.61
                29.61
                29.61
            Current = -3.5
            Voltage = 49.59
            Power = -173.565
            RemainingCapacity = 39.5
            TotalCapacity = 50.0
            CycleNumber = 5
    -->8-- SNIP -->8--
    TotalPower = -525.8022
    StateOfCharge = 0.79

>>> print(p.get_system_parameters())
Container: 
    CellHighVoltageLimit = 3.7
    CellLowVoltageLimit = 3.05
    CellUnderVoltageLimit = 2.9
    ChargeHighTemperatureLimit = 33.41
    ChargeLowTemperatureLimit = 26.21
    ChargeCurrentLimit = 10.2
    ModuleHighVoltageLimit = 54.0
    ModuleLowVoltageLimit = 46.0
    ModuleUnderVoltageLimit = 44.5
    DischargeHighTemperatureLimit = 33.41
    DischargeLowTemperatureLimit = 26.21
    DischargeCurrentLimit = -10.0
```

## Dependencies
`python-pylontech` needs python 3.5 or greater (but please, use at least 3.7 or more if possible to be future-proof).

This lib depends on `pyserial` and the awesome `construct` lib.

# Hardware wiring
The pylontech modules talk using the RS485 line protocol.
## Pylontech side
The first DIP switch on the pylontech indicates the line speed. It must be off (`0`, down position) so that the speed is set to 115200 Bd.

The RS485 port is exposed on the pins 7 & 8 on the RJ45 connector names `RS485`.

## Client side

### USB to RS485
Any RS485 to USB converter should would. You just have to wire the two pins above to the `A` and `B` ports (swap them around if it doesn't work). of your converter.

I personally use cheap chinese "RS485 to USB" converters worth a couple of bucks each.

### TCP/IP
If you are using a Ethernet to RS485 bridge, connect as for USB and run the following command (Linux only) for creating a virtual serial port. Then run the python script with adapted serial parameter in the constructor.

`socat pty,link=$HOME/bat2,waitslave tcp:<IP_ADDRESS>:<PORT>`

This is tested with an USR-N540

# Known bugs
## Mixing between US2000 and US3000
If you are using US2000 and US3000 batteries, then the main battery must be a US2000. Please see bug https://github.com/Frankkkkk/python-pylontech/issues/2#issuecomment-915966564 for more information


# FAQ

## Using Pylontech LV Hub with multible battery banks

If the LV hub is used the address of the RS485 devices is depending on the battery bank. To read values the specific device address is needed. To scan for devices on a bank you can use the `scan_for_batteries` function. The max range is 0 to 255.

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/Frankkkkk/python-pylontech",
    "name": "python-pylontech",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pylontech pylon rs485 lithium battery US2000 US2000C US3000",
    "author": "Frank Villaro-Dixon",
    "author_email": "frank@villaro-dixon.eu",
    "download_url": "https://files.pythonhosted.org/packages/0c/97/43ddf2ee7bc128fb5ccece7b437dae1d7551685fe1ef202d69d5a4296434/python-pylontech-0.3.3.tar.gz",
    "platform": null,
    "description": "# python-pylontech\nPython lib to talk to pylontech lithium batteries (US2000, US3000, ...) using RS485\n\n## What is this lib ?\nThis lib is meant to talk to Pylontech batteries using RS485. Sadly the protocol over RS485 is not some fancy thing like MODBUS but their own crappy protocol.\n\n## How to use this lib ?\nFirst of all, you need a USB to RS485 converter. They are many available online for some bucks.\n\nThen, you simply need to import the lib and start asking values:\n```python\n\n>>> import pylontech\n>>> p = pylontech.Pylontech()\n>>> print(p.get_values())\nContainer:\n    NumberOfModules = 3\n    Module = ListContainer:\n        Container:\n            NumberOfCells = 15\n            CellVoltages = ListContainer:\n                3.306\n                3.307\n                3.305\n                3.305\n                3.306\n                3.305\n                3.304\n                3.305\n                3.306\n                3.306\n                3.307\n                3.307\n                3.308\n                3.307\n                3.306\n            NumberOfTemperatures = 5\n            AverageBMSTemperature = 29.81\n            GroupedCellsTemperatures = ListContainer:\n                29.61\n                29.61\n                29.61\n                29.61\n            Current = -3.5\n            Voltage = 49.59\n            Power = -173.565\n            RemainingCapacity = 39.5\n            TotalCapacity = 50.0\n            CycleNumber = 5\n    -->8-- SNIP -->8--\n    TotalPower = -525.8022\n    StateOfCharge = 0.79\n\n>>> print(p.get_system_parameters())\nContainer: \n    CellHighVoltageLimit = 3.7\n    CellLowVoltageLimit = 3.05\n    CellUnderVoltageLimit = 2.9\n    ChargeHighTemperatureLimit = 33.41\n    ChargeLowTemperatureLimit = 26.21\n    ChargeCurrentLimit = 10.2\n    ModuleHighVoltageLimit = 54.0\n    ModuleLowVoltageLimit = 46.0\n    ModuleUnderVoltageLimit = 44.5\n    DischargeHighTemperatureLimit = 33.41\n    DischargeLowTemperatureLimit = 26.21\n    DischargeCurrentLimit = -10.0\n```\n\n## Dependencies\n`python-pylontech` needs python 3.5 or greater (but please, use at least 3.7 or more if possible to be future-proof).\n\nThis lib depends on `pyserial` and the awesome `construct` lib.\n\n# Hardware wiring\nThe pylontech modules talk using the RS485 line protocol.\n## Pylontech side\nThe first DIP switch on the pylontech indicates the line speed. It must be off (`0`, down position) so that the speed is set to 115200 Bd.\n\nThe RS485 port is exposed on the pins 7 & 8 on the RJ45 connector names `RS485`.\n\n## Client side\n\n### USB to RS485\nAny RS485 to USB converter should would. You just have to wire the two pins above to the `A` and `B` ports (swap them around if it doesn't work). of your converter.\n\nI personally use cheap chinese \"RS485 to USB\" converters worth a couple of bucks each.\n\n### TCP/IP\nIf you are using a Ethernet to RS485 bridge, connect as for USB and run the following command (Linux only) for creating a virtual serial port. Then run the python script with adapted serial parameter in the constructor.\n\n`socat pty,link=$HOME/bat2,waitslave tcp:<IP_ADDRESS>:<PORT>`\n\nThis is tested with an USR-N540\n\n# Known bugs\n## Mixing between US2000 and US3000\nIf you are using US2000 and US3000 batteries, then the main battery must be a US2000. Please see bug https://github.com/Frankkkkk/python-pylontech/issues/2#issuecomment-915966564 for more information\n\n\n# FAQ\n\n## Using Pylontech LV Hub with multible battery banks\n\nIf the LV hub is used the address of the RS485 devices is depending on the battery bank. To read values the specific device address is needed. To scan for devices on a bank you can use the `scan_for_batteries` function. The max range is 0 to 255.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Interfaces with Pylontech Batteries using RS485 protocol",
    "version": "0.3.3",
    "project_urls": {
        "Homepage": "http://github.com/Frankkkkk/python-pylontech"
    },
    "split_keywords": [
        "pylontech",
        "pylon",
        "rs485",
        "lithium",
        "battery",
        "us2000",
        "us2000c",
        "us3000"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8aed85505fb3f8325f3759d2366cd2a146ccbe5a4852955cb822ddd3641d3ec",
                "md5": "7e3593b140c18ccaf2f6347794a905ab",
                "sha256": "f2d2f905f76c053592340ba0457b71dd8f769a62923cbebc6dda7d35fdf010a8"
            },
            "downloads": -1,
            "filename": "python_pylontech-0.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7e3593b140c18ccaf2f6347794a905ab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6482,
            "upload_time": "2023-08-14T19:31:49",
            "upload_time_iso_8601": "2023-08-14T19:31:49.770033Z",
            "url": "https://files.pythonhosted.org/packages/c8/ae/d85505fb3f8325f3759d2366cd2a146ccbe5a4852955cb822ddd3641d3ec/python_pylontech-0.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c9743ddf2ee7bc128fb5ccece7b437dae1d7551685fe1ef202d69d5a4296434",
                "md5": "ba0ba01664dab6f2ad8ee5d83aa6ae50",
                "sha256": "b851778ddfb64e20cdfaded1a60a16ce6152030d7ef28abaae6534715410867f"
            },
            "downloads": -1,
            "filename": "python-pylontech-0.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "ba0ba01664dab6f2ad8ee5d83aa6ae50",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7477,
            "upload_time": "2023-08-14T19:31:50",
            "upload_time_iso_8601": "2023-08-14T19:31:50.711868Z",
            "url": "https://files.pythonhosted.org/packages/0c/97/43ddf2ee7bc128fb5ccece7b437dae1d7551685fe1ef202d69d5a4296434/python-pylontech-0.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-14 19:31:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Frankkkkk",
    "github_project": "python-pylontech",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-pylontech"
}
        
Elapsed time: 0.20008s