# pymyenergi
An async Python library for myenergi API
This is a very early release, things are changing rapidly so use at your own risk!
> [!IMPORTANT]
> This work is not officially supported by myenergi and functionality can stop working at any time without warning
## Installation
The easiest method is to install using pip (`pip`/`pip3`):
```bash
pip install pymyenergi
```
Installing within a [Python virtual environment](https://docs.python.org/3/library/venv.html) is often a good idea:
```bash
python -m venv .venv
source .venv/bin/activate
pip install pymyenergi
```
To update to the latest version:
```bash
pip install pymyenergi -U
```
Setup will add a CLI under the name `myenergicli`. See below for usage.
## CLI
A simple CLI is provided with this library.
If no `username`, `password`, `app_email` or `app_password` is supplied as input arguments, and no configuration file is found, you will be prompted for credentials.
Configuration file will be searched for in `./.myenergi.cfg` and `~/.myenergi.cfg`.
### Example configuration file
```ini
[hub]
serial=12345678
password=your-password
app_email=myemail@email.com
app_password=your-app-password
```
### CLI usage
```
usage: myenergi [-h] [-u USERNAME] [-p PASSWORD] [-e APP_EMAIL] [-a APP_PASSWORD] [-d] [-j] [--skip-oauth]
{list,overview,zappi,eddi,harvi,libbi} ...
myenergi CLI.
positional arguments:
{list,overview,zappi,eddi,harvi,libbi}
sub-command help
list list devices
overview show overview
zappi use zappi --help for available commands
eddi use eddi --help for available commands
harvi use harvi --help for available commands
libbi use libbi --help for available commands
optional arguments:
-h, --help show this help message and exit
-u USERNAME, --username USERNAME
-p PASSWORD, --password PASSWORD
-e APP_EMAIL, --app_email APP_EMAIL
-a APP_PASSWORD, --app_password APP_PASSWORD
-d, --debug
-j, --json
```
## Library usage
Install pymyenergi using pip (requires Python > 3.6)
### Example library usage
```python
import asyncio
from pymyenergi.connection import Connection
from pymyenergi.client import MyenergiClient
from sys import argv
import logging
logging.basicConfig()
logging.root.setLevel(logging.INFO)
user, password = argv
async def zappis() -> None:
conn = Connection(user, password)
client = MyenergiClient(conn)
zappis = await client.getDevices('zappi')
for zappi in zappis:
print(f"Zappi {zappi.serial_number} charge mode {zappi.charge_mode}")
loop = asyncio.get_event_loop()
loop.run_until_complete(zappis())
```
### Example library usage - Zappi
```python
import asyncio
from pymyenergi.connection import Connection
from pymyenergi.zappi import Zappi
from sys import argv
import logging
logging.basicConfig()
logging.root.setLevel(logging.INFO)
user, password, zappi_serial = argv
async def get_data() -> None:
conn = Connection(user, password)
zappi = Zappi(conn, zappi_serial)
await zappi.refresh()
print(f"Zappi S/N {zappi.serial_number} version {zappi.firmware_version}")
print(f"Status: {zappi.status} Plug status: {zappi.plug_status} Locked: {zappi.locked}")
print(f"Priority: {zappi.priority}")
print(f"Charge mode: {zappi.charge_mode} {zappi.num_phases} phase")
print()
print(f"Lock when plugged in : {zappi.lock_when_pluggedin}")
print(f"Lock when unplugged : {zappi.lock_when_unplugged}")
print(f"Charge when locked : {zappi.charge_when_locked}")
print(f"Charge session allowed : {zappi.charge_session_allowed}")
print(f"Charge added: {zappi.charge_added}")
print()
print(f"CT 1 {zappi.ct1.name} {zappi.ct1.power}W")
print(f"CT 2 {zappi.ct2.name} {zappi.ct2.power}W")
print(f"CT 3 {zappi.ct3.name} {zappi.ct3.power}W")
print(f"CT 4 {zappi.ct4.name} {zappi.ct4.power}W")
print(f"CT 5 {zappi.ct5.name} {zappi.ct5.power}W")
print(f"CT 6 {zappi.ct6.name} {zappi.ct6.power}W")
print()
print(f"Supply voltage: {zappi.supply_voltage}V frequency: {zappi.supply_frequency}Hz")
print("Power:")
print(f" Grid : {zappi.power_grid}W")
print(f" Generated : {zappi.power_generated}W")
print()
# print(f" Boost start at {zappi.boost_start_hour}:{zappi.boost_start_minute} add {zappi.boost_amount}kWh")
print(f"Smart Boost start at {zappi.smart_boost_start_hour}:{zappi.smart_boost_start_minute} add {zappi.smart_boost_amount}kWh")
loop = asyncio.get_event_loop()
loop.run_until_complete(get_data())
```
## Libbi support
Currently supported features:
- Reads a few values such as State of Charge, DCPV CT
- Battery in and out energy
- Gets and sets the current operating mode (normal/stopped/export)
- Change priority of Libbi
- Enable/Disable charging from the grid
- Set charge target (in Wh)
## CLI examples:
```bash
myenergi libbi show
myenergi libbi mode normal
myenergi libbi priority 1
myenergi libbi energy
myenergi libbi chargefromgrid false
myenergi libbi chargetarget 10200
```
## Credits
[twonk](https://github.com/twonk/MyEnergi-App-Api) for documenting the unofficial API
Raw data
{
"_id": null,
"home_page": "https://github.com/cjne/pymyenergi",
"name": "pymyenergi",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Johan Isaksson",
"author_email": "johan@generatorhallen.se",
"download_url": "https://files.pythonhosted.org/packages/00/ef/b6e8b2b8b7afd2502656926f783102ac5b86699eaa52afde11f737c328f2/pymyenergi-0.2.2.tar.gz",
"platform": null,
"description": "# pymyenergi\n\nAn async Python library for myenergi API\n\nThis is a very early release, things are changing rapidly so use at your own risk!\n\n> [!IMPORTANT]\n> This work is not officially supported by myenergi and functionality can stop working at any time without warning\n\n## Installation\n\nThe easiest method is to install using pip (`pip`/`pip3`):\n\n```bash\npip install pymyenergi\n```\n\nInstalling within a [Python virtual environment](https://docs.python.org/3/library/venv.html) is often a good idea:\n\n```bash\npython -m venv .venv\nsource .venv/bin/activate\npip install pymyenergi\n```\n\nTo update to the latest version:\n\n```bash\npip install pymyenergi -U\n```\n\nSetup will add a CLI under the name `myenergicli`. See below for usage.\n\n## CLI\n\nA simple CLI is provided with this library.\n\nIf no `username`, `password`, `app_email` or `app_password` is supplied as input arguments, and no configuration file is found, you will be prompted for credentials.\n\nConfiguration file will be searched for in `./.myenergi.cfg` and `~/.myenergi.cfg`.\n\n### Example configuration file\n\n```ini\n[hub]\nserial=12345678\npassword=your-password\napp_email=myemail@email.com\napp_password=your-app-password\n```\n\n### CLI usage\n\n```\nusage: myenergi [-h] [-u USERNAME] [-p PASSWORD] [-e APP_EMAIL] [-a APP_PASSWORD] [-d] [-j] [--skip-oauth]\n {list,overview,zappi,eddi,harvi,libbi} ...\n\nmyenergi CLI.\n\npositional arguments:\n {list,overview,zappi,eddi,harvi,libbi}\n sub-command help\n list list devices\n overview show overview\n zappi use zappi --help for available commands\n eddi use eddi --help for available commands\n harvi use harvi --help for available commands\n libbi use libbi --help for available commands\n\noptional arguments:\n -h, --help show this help message and exit\n -u USERNAME, --username USERNAME\n -p PASSWORD, --password PASSWORD\n -e APP_EMAIL, --app_email APP_EMAIL\n -a APP_PASSWORD, --app_password APP_PASSWORD\n -d, --debug\n -j, --json\n```\n\n## Library usage\n\nInstall pymyenergi using pip (requires Python > 3.6)\n\n### Example library usage\n\n```python\nimport asyncio\nfrom pymyenergi.connection import Connection\nfrom pymyenergi.client import MyenergiClient\nfrom sys import argv\nimport logging\n\nlogging.basicConfig()\nlogging.root.setLevel(logging.INFO)\n\nuser, password = argv\n\nasync def zappis() -> None:\n conn = Connection(user, password)\n client = MyenergiClient(conn)\n\n zappis = await client.getDevices('zappi')\n for zappi in zappis:\n print(f\"Zappi {zappi.serial_number} charge mode {zappi.charge_mode}\")\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(zappis())\n```\n\n### Example library usage - Zappi\n\n```python\nimport asyncio\nfrom pymyenergi.connection import Connection\nfrom pymyenergi.zappi import Zappi\nfrom sys import argv\nimport logging\n\nlogging.basicConfig()\nlogging.root.setLevel(logging.INFO)\n\nuser, password, zappi_serial = argv\n\n\nasync def get_data() -> None:\n conn = Connection(user, password)\n zappi = Zappi(conn, zappi_serial)\n await zappi.refresh()\n print(f\"Zappi S/N {zappi.serial_number} version {zappi.firmware_version}\")\n print(f\"Status: {zappi.status} Plug status: {zappi.plug_status} Locked: {zappi.locked}\")\n print(f\"Priority: {zappi.priority}\")\n print(f\"Charge mode: {zappi.charge_mode} {zappi.num_phases} phase\")\n print()\n print(f\"Lock when plugged in : {zappi.lock_when_pluggedin}\")\n print(f\"Lock when unplugged : {zappi.lock_when_unplugged}\")\n print(f\"Charge when locked : {zappi.charge_when_locked}\")\n print(f\"Charge session allowed : {zappi.charge_session_allowed}\")\n print(f\"Charge added: {zappi.charge_added}\")\n print()\n print(f\"CT 1 {zappi.ct1.name} {zappi.ct1.power}W\")\n print(f\"CT 2 {zappi.ct2.name} {zappi.ct2.power}W\")\n print(f\"CT 3 {zappi.ct3.name} {zappi.ct3.power}W\")\n print(f\"CT 4 {zappi.ct4.name} {zappi.ct4.power}W\")\n print(f\"CT 5 {zappi.ct5.name} {zappi.ct5.power}W\")\n print(f\"CT 6 {zappi.ct6.name} {zappi.ct6.power}W\")\n print()\n print(f\"Supply voltage: {zappi.supply_voltage}V frequency: {zappi.supply_frequency}Hz\")\n print(\"Power:\")\n print(f\" Grid : {zappi.power_grid}W\")\n print(f\" Generated : {zappi.power_generated}W\")\n print()\n # print(f\" Boost start at {zappi.boost_start_hour}:{zappi.boost_start_minute} add {zappi.boost_amount}kWh\")\n print(f\"Smart Boost start at {zappi.smart_boost_start_hour}:{zappi.smart_boost_start_minute} add {zappi.smart_boost_amount}kWh\")\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(get_data())\n```\n\n## Libbi support\n\nCurrently supported features:\n\n- Reads a few values such as State of Charge, DCPV CT\n- Battery in and out energy\n- Gets and sets the current operating mode (normal/stopped/export)\n- Change priority of Libbi\n- Enable/Disable charging from the grid\n- Set charge target (in Wh)\n\n## CLI examples:\n\n```bash\nmyenergi libbi show\nmyenergi libbi mode normal\nmyenergi libbi priority 1\nmyenergi libbi energy\nmyenergi libbi chargefromgrid false\nmyenergi libbi chargetarget 10200\n```\n\n## Credits\n\n[twonk](https://github.com/twonk/MyEnergi-App-Api) for documenting the unofficial API\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python library and CLI for communicating with myenergi API.",
"version": "0.2.2",
"project_urls": {
"Homepage": "https://github.com/cjne/pymyenergi"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "09461cbcaf48220bccd60924e9fc7f57671dd8ba89ebd208286446a6eb0a4206",
"md5": "5dcbe9f7e2d9141d234146f8a3107227",
"sha256": "17374fa38181593eb46277839191e74c48a4bc115ed282e5373c92ee40e2310d"
},
"downloads": -1,
"filename": "pymyenergi-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5dcbe9f7e2d9141d234146f8a3107227",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 23511,
"upload_time": "2024-10-16T20:23:45",
"upload_time_iso_8601": "2024-10-16T20:23:45.867105Z",
"url": "https://files.pythonhosted.org/packages/09/46/1cbcaf48220bccd60924e9fc7f57671dd8ba89ebd208286446a6eb0a4206/pymyenergi-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "00efb6e8b2b8b7afd2502656926f783102ac5b86699eaa52afde11f737c328f2",
"md5": "8647630441d9ffbc99a3d5bb8e782112",
"sha256": "b90a9b7b1d8ff02c7308517e508ebb3d8fe35c85428feaaa2dae21126306ff92"
},
"downloads": -1,
"filename": "pymyenergi-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "8647630441d9ffbc99a3d5bb8e782112",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 21083,
"upload_time": "2024-10-16T20:23:47",
"upload_time_iso_8601": "2024-10-16T20:23:47.121211Z",
"url": "https://files.pythonhosted.org/packages/00/ef/b6e8b2b8b7afd2502656926f783102ac5b86699eaa52afde11f737c328f2/pymyenergi-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-16 20:23:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cjne",
"github_project": "pymyenergi",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pymyenergi"
}