Package: pyess
Python library for communication with LG ESS power converter / energy storage devices for photovoltaic solar generatorsThis library isnot endorsed by the manufacturer. It was written for lack of an official API. It should allow to
design home automation around the current state of a solar energy system - e.g. turn appliances on when there is surplus
solar power. LG only offers access via a badly scriptable web page or alternatively via a proprietary app that - at least
on my phone - crashes at least twice for every successful startup.Disclaimer:For this python module I reverse-engineered the communication between theLG EnerVu Plus 1.2.3Android
App and the Energy Storage / Inverter device, so there is some likelihood that it will work for devices that
can be accessed via that app. Nevertheless it looks like some of the interface is delivered by the ESS as html via the
network. Therefore it may be that not all commands work against all boxes. I only have customer-level access to my own
box, so this module only offers those parts of the API that are accessible to me as a customer. As far as I can tell
the installer has higher privileges and can fiddle with internal parameters of the system from what I saw him do when he
installed the system.UsageCommand LineFetch the device passwordFind the esses on your networkFetch the state from ess as jsonGraphite wrapperMQTT Wrapperessmqtt as systemd serviceessmqtt config fileMQTT discovery for homeassistantCommand LineThis module comes with a rudimentary command line interface that allows for the following actions.Fetch the device passwordCaveat:To fetch the device password you need to be connected to the devices wifi.Once you are on the wifi you can
run the following to get the password. Write it down, it seems it is a static password per device:esscli --action get_passwordThe command assumes that the ess device is listening on192.168.23.1on its own wifi, in my setup it reproducibly
chooses that IP.Find the esses on your networkGet a list of ESS devices on the local network (your home wifi, not the one of ess):esscli --action list_essFetch the state from ess as jsonfetch a bunch of json states as json and display the result on the command line:esscli --action get_data --password <your ess_password>Examples for the data available:
- current power from and to the grid and the battery
- current voltage and power from both strings of the photovoltaic system independently
- current ip address
- details on grid power, battery state, daily and monthly statisticsGraphite wrapperThelog_against_graphitecommand will fetch thehomeandcommoninfo from ess every 10 seconds and log them against a graphite
server (assuming standard port and udp as protocol). Running this command requires the ess password to be passed on
the command line:esscli --action log_against_graphite --password <your_ess_password> --graphite <ip_of_graphite_server>MQTT wrapperSync ess state with an mqtt server (also accepts commands)To connect your ESS with an mqtt server run the following in your venv:essmqtt --mqtt_server=<your_mqtt_server> --mqtt_user <your_mqtt_username> --mqtt_password <your_mqtt_password> --ess_password <your_ess_password>Your ESS will show up iness/#on mqtt.Available values to control the ess (write true/false)Remember that this is an MIT-Licensed software and I take no responsibility for the usage of this library. That being said I send the same commands the app would send to trigger these actions to my best knowledge.:ess/control/winter_mode
ess/control/fastcharge
ess/control/activeAvailable paths with metrics to read from:ess/home/statistics/pcs_pv_total_power 0
ess/home/statistics/batconv_power 190
ess/home/statistics/bat_use 1
ess/home/statistics/bat_status 2
ess/home/statistics/bat_user_soc 81.25
ess/home/statistics/load_power 191
ess/home/statistics/load_today 0.0
ess/home/statistics/grid_power 1
ess/home/statistics/current_day_self_consumption 0.0
ess/home/statistics/current_pv_generation_sum 0
ess/home/statistics/current_grid_feed_in_energy 0
ess/home/direction/is_direct_consuming_ 0
ess/home/direction/is_battery_charging_ 0
ess/home/direction/is_battery_discharging_ 1
ess/home/direction/is_grid_selling_ 0
ess/home/direction/is_grid_buying_ 1
ess/home/direction/is_charging_from_grid_ 0
ess/home/operation/status start
ess/home/operation/mode 1
ess/home/wintermode/winter_status on
ess/home/pcs_fault/pcs_status pcs_ok
ess/common/PV/brand LGE-SOLAR
ess/common/PV/capacity 5850
ess/common/PV/pv1_voltage 26.500000
ess/common/PV/pv2_voltage 26.700001
ess/common/PV/pv1_power 0
ess/common/PV/pv2_power 0
ess/common/PV/pv1_current 0.110000
ess/common/PV/pv2_current 0.000000
ess/common/PV/today_pv_generation_sum 0
ess/common/PV/today_month_pv_generation_sum 438389
ess/common/BATT/status 2
ess/common/BATT/soc 81.2
ess/common/BATT/dc_power 190
ess/common/BATT/winter_setting on
ess/common/BATT/winter_status on
ess/common/BATT/safty_soc 20
ess/common/BATT/today_batt_discharge_enery 135
ess/common/BATT/today_batt_charge_energy 0
ess/common/BATT/month_batt_charge_energy 72692
ess/common/BATT/month_batt_discharge_energy 51250
ess/common/GRID/active_power 2.790000
ess/common/GRID/a_phase 230.899994
ess/common/GRID/freq 49.959999
ess/common/GRID/today_grid_feed_in_energy 0
ess/common/GRID/today_grid_power_purchase_energy 0
ess/common/GRID/month_grid_feed_in_energy 266094
ess/common/GRID/month_grid_power_purchase_energy 7037
ess/common/LOAD/load_power 191
ess/common/LOAD/today_load_consumption_sum 135
ess/common/LOAD/today_pv_direct_consumption_enegy 0
ess/common/LOAD/today_batt_discharge_enery 135
ess/common/LOAD/today_grid_power_purchase_energy 0
ess/common/LOAD/month_load_consumption_sum 157890
ess/common/LOAD/month_pv_direct_consumption_energy 99603
ess/common/LOAD/month_batt_discharge_energy 51250
ess/common/LOAD/month_grid_power_purchase_energy 7037
ess/common/PCS/today_self_consumption 0.0
ess/common/PCS/month_co2_reduction_accum 311256
ess/common/PCS/today_pv_generation_sum 0
ess/common/PCS/month_pv_generation_sum 438389
ess/common/PCS/today_grid_feed_in_energy 0
ess/common/PCS/month_grid_feed_in_energy 266094
ess/common/PCS/pcs_stauts 3
ess/common/PCS/feed_in_limitation 70
ess/common/PCS/operation_mode 0I usemosquitto_subto find the values I’m interested in while debugging like so:mosquitto_sub -v -h <your_mqtt_server> -p 1883 -u <your_mqtt_user> -P <your_mqtt_password> -t "#"essmqtt as systemd serviceTo set upessmqttas a daemon (systemd service) it is recommended to install it in a venv first:python3.7 -m venv <path_to_venv>
<path_to_venv>/bin/pip install pyessset up youressmqtt config filefrom then onessmqttcan be called via<path_to_venv>/bin/essmqtt.A systemd service file/etc/systemd/system/essmqtt.servicecould look like so:[Unit]
Description=ESS MQTT wrapper

[Service]
# all essmqtt command line arguments can be used here. it is recommended to configure essmqtt in a config file
# for this use case
ExecStart=<path_to_venv>/bin/essmqtt
# Restart will keep the service alive for instance in case the mqtt server goes down or isn't up yet
# when esmqqt starts
Restart=on-failure
# a sensible restart delay prevents fast restart loops potentially denial-of-servicing the ess.
RestartSec=10

[Install]
# we'd like to start, but only after network is up
WantedBy=default.target
Wants=network-online.targetIt can be started like any regular service viasystemctl start essmqttor enabled for boot up starts viasystemctl enable essmqtt. Logs can be displayed using systemctl as well viasystemctl status essmqttor for
more linessystemctl status-n100 essmqttessmqtt config fileTo permanently configure essmqtt you can create a config file in either/etc/essmqtt.confor~/essmqtt.confof the user runningessmqttor you can specify which config file to load by using the argument--config_file.
The config file can contain any of the command line arguments. Example:ess_password = <your_ess_password>
mqtt_server = <your_mqtt_server>
mqtt_user = <your_mqtt_username>
mqtt_password = <your_mqtt_password>
# optional settings
## sensors for homeassistant MQTT discovery (default is not set -> homeassistant autoconfig disabled)
# hass_autoconfig_sensors = ess/common/BATT/soc,ess/home/statistics/pcs_pv_total_power,ess/common/GRID/active_power,ess/common/LOAD/load_power
## update interval for MQTT values in seconds (default is 10 seconds)
# interval_seconds = 10
## only send the values below common every n'th update of those for home
## this is a debugging option that shouldn't be required, (default is 1)
# common_divisor = 1MQTT discovery for homeassistantBelow you find the manual setup process. If you use homeassistant operating system or one of the other installation methods that offers add-ons you can find a homeassistant add-on repo with an addon for pyesshere.essmqttcan provide autoconfiguration forhomeassistant.prerequisites:mqtt must be set up withmqtt discoveryin homeassistantTo select the sensors that should be autodiscovered by homeassistant, provide the--hass_autoconfig_sensorsargument with a comma separated list of all mqtt pathes you want to see as sensors in homeassistant. Some autodetection
of the value type is done so for instance if an mqtt path containspowerit is assumed to be a power
value in watts. Of course this can also be configured in a config file.Example config file:ess_password = <your_ess_password>
mqtt_server = <your_mqtt_server>
mqtt_user = <your_mqtt_username>
mqtt_password = <your_mqtt_password>
hass_autoconfig_sensors = ess/common/BATT/soc,ess/home/statistics/pcs_pv_total_power,ess/common/GRID/active_power,ess/common/LOAD/load_powerAPIFor the time being please use the docstrings in the code onhttps://github.com/gluap/pyessas documentation for the
API. A good place to start is pyess/cli.py where you can find the implementation of the CLI. One thing available
via the API but not yet via the CLI is the data for the daily / weekly / monthly / yearly statistics graphs that can
be accessed via the EnerVu App.Changelog2024-02-14 0.1.21nail aiomqtt to a lower version due to incompatible changes.2023-07-01 0.1.20homeassistant: some more imporvements to energy sensing, add switch capability2023-06-29 0.1.18homeassistant: stuff with _sum is also an “increasing” thing.2023-06-29 0.1.17homeassistant: add state_class and measurement units consistently2023-06-29 0.1.16homeassistant: add state_class for homeassistant integration2023-06-29 0.1.15compatibility changes for python3.112022-03-15 0.1.14fix typo in mqtt autoconfig2020-06-12 0.1.12Only publish homeassistant autoconfig information once2020-06-01 0.1.11for cleaner restarts pass exceptions out and set up the full communication freshly when MQTT or ess crashes2020-06-01 0.1.10add another possible fix for #7 after logging showed that an MQTT error might be the cause.2020-06-01 0.1.9add homeassistant auto config2020-05-30 0.1.8refactor uploading to MQTT to avoid accidentally trying to access a string by key (should fix #8)2020-05-30 0.1.7add config file to allow storing settings for essmqtt2020-05-30 0.1.6repair crash introduced with 0.1.52020-05-30 0.1.5some extra logging, timeouts and exception handling. Might fix #72020-05-13 0.1.3add argument to increase polling time for “common” by a factor.2020-05-05 0.1.3add argument to set ess hostname explicitly (avoiding mdns timeouts if necessary)2020-04-29 0.1.2fix issue where esscli and essmqtt were incompatible with the app and confusing the web interface2020-04-26 0.1.1fix issue where commands via mqtt were not workingadd--interval_secondsparameter for mqtt client to allow experimenting with poll timeouts on user sidefix logout handling on aiohttp2020-04-15 0.1.0fix issue with fetch_password using wrong IPfix documentationadd new mqtt synchronization service script2019-11-03 0.0.3add aiohttp-based backend for use with asyncio2019-10-12 0.0.2some minor fixes2019-10-09 0.0.1More documentationInitial commit for pypi relaseLicense:Copyright (c) 2019-2020 Paul Görgen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.