derenback / Domoticz-SMA-Inverter

A Domoticz plugin for SMA solar inverters
GNU General Public License v3.0
2 stars 1 forks source link

"NameError: name 'client' is not defined" when running from docker on Synology #9

Closed jjvdkraats closed 2 years ago

jjvdkraats commented 2 years ago

Hi David, When running the script in a docker Domoticz environment on Synology, after adding the hardware, the script adds all devices with a zero value but creates errors in the log: _2022-06-24 10:34:31.296 Error: SMA: Call to function 'onStart' failed, exception details: 2022-06-24 10:34:31.298 Error: SMA: Traceback (most recent call last): 2022-06-24 10:34:31.299 Error: SMA: File "/opt/domoticz/userdata/plugins/Domoticz-SMA-Inverter/plugin.py", line 127, in onStart 2022-06-24 10:34:31.299 Error: SMA: Domoticz.Log("SMA Inverter serial number: " + str(get_modbus_value(SERIAL_NUMBER_ADDRESS))) 2022-06-24 10:34:31.299 Error: SMA: File "/opt/domoticz/userdata/plugins/Domoticz-SMA-Inverter/plugin.py", line 59, in get_modbus_value 2022-06-24 10:34:31.299 Error: SMA: valueread = client.read_holding_registers(modbus_address, data_len) 2022-06-24 10:34:31.299 Error: SMA: NameError: name 'client' is not defined 2022-06-24 10:34:40.067 Error: SMA: Call to function 'onHeartbeat' failed, exception details: 2022-06-24 10:34:40.067 Error: SMA: Traceback (most recent call last): 2022-06-24 10:34:40.067 Error: SMA: File "/opt/domoticz/userdata/plugins/Domoticz-SMA-Inverter/plugin.py", line 162, in onHeartbeat 2022-06-24 10:34:40.067 Error: SMA: if not client.isopen(): 2022-06-24 10:34:40.067 Error: SMA: NameError: name 'client' is not defined

The errors get repeated every 10 seconds, values are not updated. Pymodbus and pymodbustcp are installed and the SMA inverter (STP5.0-3AV-40) is Modbus enabled. Is there a way to get more logging to figure out where the error originates from?

Kind regards, Jasper

derenback commented 2 years ago

Hello, not sure how to get more debug information from a scrip running on Domoticz. I have added my test docker files and a test-script in this feature branch. https://github.com/derenback/Domoticz-SMA-Inverter/tree/feature/add-docker-files I have tested the plugin with these docker / docker compose files on a Ubuntu machine and it works just fine.

jjvdkraats commented 2 years ago

Hi David,

sma_test.py worked like a charm. It took a while to fix your script. I got it working after changing

    client = ModbusClient(host=Parameters["Address"], port = Parameters["Port"], unit_id=Parameters["Mode1"])

to client = ModbusClient(host=Parameters["Address"], port = int(Parameters["Port"]), unit_id=int(Parameters["Mode1"]))

and

if not client.is_open():

to if not client.is_open:

I could create a pull request, but maybe you would like to test it yourself?

Kind regards, Jasper

derenback commented 2 years ago

I added your suggested changes after I had tested... Thanks!