gluap / pyess

Python library for communication with LG ESS power converters
MIT License
31 stars 10 forks source link

How to connect on different subnet #19

Closed meschmesch closed 1 year ago

meschmesch commented 1 year ago

Hello, I installed pyess and I have an MQTT server running somewhere (without homeassistant, I just want to use the commandline). pyess and MQTT are running on 192.168.2.xx subnet, ESS is hooked to 192.168.176.3. How do I tell pyess to communicate with ESS on the 176.3 address?

The PW of ESS is known to me through other channels.

Thanks.

gluap commented 1 year ago

In theory this should be possible without changes.

essmqtt has a command line argument --ess_host. If you pass that with the IP address of your ESS (--ess_host=192.168.176.3, essmqtt should skip the mdns autodetection (which doesn't work across subnets, probably the problem you're facing) and directly connect to the given IP address.

A prerequisite of course is that your network is configured such that - via either a gateway or an appropriate route - the machine essmqtt runs on can connect to the 192.168.176.0 subnet.

If it doesn't work with --ess_host that's a bug - in that case please speak up.

meschmesch commented 1 year ago

ping works, access to the subnet should be possible (at least from another machine on the same network the access is working).

pi@raspberry3:~/essmqtt/bin $ ./esscli --ess_host=192.168.176.3 --action get_data --password MY_PASSWORD

Traceback (most recent call last):
  File "/home/pi/essmqtt/bin/./esscli", line 5, in <module>
    from pyess.cli import main
  File "/home/pi/essmqtt/lib/python3.9/site-packages/pyess/cli.py", line 12, in <module>
    from pyess.ess import find_all_esses, get_ess_pw, extract_name_from_zeroconf, autodetect_ess, ESS
  File "/home/pi/essmqtt/lib/python3.9/site-packages/pyess/ess.py", line 60
    ip = get_ess_ip(self.name)
TabError: inconsistent use of tabs and spaces in indentation
gluap commented 1 year ago

You seem to be trying esscli, but the option --ess_host is only available for essmqtt, do you observe the same issue with essmqtt?

As you were asking about the mqtt my guess is that essmqtt is what you need in the end anyhow.

meschmesch commented 1 year ago

pi@raspberry3:~/essmqtt/bin $ ./essmqtt --ess_host=192.168.176.3 --mqtt_server=192.168.2.115 --ess_password theesspassword

Traceback (most recent call last):
  File "/home/pi/essmqtt/bin/./essmqtt", line 5, in <module>
    from pyess.essmqtt import main
  File "/home/pi/essmqtt/lib/python3.9/site-packages/pyess/essmqtt.py", line 14, in <module>
    from pyess.ess import autodetect_ess
  File "/home/pi/essmqtt/lib/python3.9/site-packages/pyess/ess.py", line 60
    ip = get_ess_ip(self.name)
TabError: inconsistent use of tabs and spaces in indentation

The MQTT Server has no username or password requirement, it is up and running and being used by other services.

gluap commented 1 year ago

How did you download the code? did you make modifications?

Background: "Inconsistent tabs and spaces" means that the leading whitespace (which in python has syntactic meaning) is inconsistent and some whitespace is made using tabs. But in that line 60 (and in fact the whole repository as it is on github) there is not a single tab character. If you edited the file with a text editor that might have introduced tab characters (many text editors render tab as four spaces, so it is not immediately apparent when editing whether or not there are tab characters in the beginning of a line.).

If you downloaded using git you can check whether there are differences in your repository by running git status which should highlight any files different from the original version.

If you downloaded as Zip I'd suggest to re-download.

For reference this is the output of essmqtt freshly downloaded from github:

paulg@desktop:~/Workspace/pyess(master)$ venv/bin/essmqtt --ess_host=192.168.1.253 --mqtt_server=192.168.1.220 --ess_password d84fb8020100
We renamed asyncio-mqtt to aiomqtt and released a version 1.0.0 in the process. This is the last release under the asyncio-mqtt name. You can find the new repository at https://github.com/sbtinstruments/aiomqtt
INFO:pyess.aio_ess:fetching auth key
...

You could also search through the file for tab characters.

meschmesch commented 1 year ago

I got it working, thank you!! There were some weird characters in the config file. In essence by using essmqtt I am constantly receiving on the respective channels updated values of the ESS and using e.g. mosquitto_pub -t ess/control/active -m "false" I can turn off (true = on) my ESS. Perfect!!

One last question, is it also possible to turn on/off the backup functionality of the ESS using your tool?

gluap commented 1 year ago

Unfortunately I don't know about any backup functionality - My ESS is an older model and therefore can only reverse engineer the part of the api that is available with that model. (Essentially to find out how it works I used the app and sniffed network traffic after jumping through a few hoops to decrypt said network traffic). So I can only do what my ESS+App can do.

meschmesch commented 1 year ago

Got it, thanks!!