Page 1 of 1

plugin.py generates error while importing Domoticz module

Posted: Saturday 15 October 2022 22:17
by omeijers
Hi,
While trying to create a python plugin for a beok thermostat using broadlink, the plugin generates an error while domoticz starts up.
this is the error:

[2022-10-15 22:03:47.649 Error: Beokeroni: (Beok) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/Beok305F/:/usr/lib/python39.zip:/usr/lib/python3.9:/usr/lib/python3.9/lib-dynload:/usr/local/lib/python3.9/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.9/dist-packages'.
2022-10-15 22:03:47.649 Error: Beokeroni: Module Import failed, exception: 'ImportError'
2022-10-15 22:03:47.649 Error: Beokeroni: Module Import failed: ' Name: Domoticz'
2022-10-15 22:03:47.649 Error: Beokeroni: Error Line details not available.
2022-10-15 22:03:47.649 Error: Beokeroni: Exception traceback:
2022-10-15 22:03:47.649 Error: Beokeroni: ----> Line 18 in '/home/pi/domoticz/plugins/Beok305F/plugin.py'

The plugin is in subfolder of \domoticz\plugins\Beok305F
Question now is why it cannot import the Domoticz module . I have searched a lot on this forum and no mention of this issue. Guess my inexperience with Domoticz is cathing up with me.
the plugin also loads the broadlink module and this works fine.
in visual studio code, the Domoticz module also cannot be resolved. what am I missing?

version Domoticz: 2022.1
python version: 3.9.2

below the first part of the script:

'''
<plugin key="Beok" name="Beok Thermostat" author="Onno Meijers" version="1.0.0">
<description>
<h2>Beok Thermostat Interface</h2><br/>
</description>
<params>
<param field="Address" label="IP Address" width="200px" required="true"/>
<param field="Port" label="Port" width="30px" required="true"/>
<param field="Mode1" label="MAC Address" width="200px" required="true">
<description>e.g. XX:XX:XX:...</description>
</param>
<param field="Mode2" label="Type" width="50px" required="true"/>
</params>
</plugin>
'''
import broadlink
import Domoticz
from Domoticz import Devices, Parameters


class BasePlugin:
enabled = False
def __init__(self):
#self.var = 123
return

def onStart(self):
# thermostat ip and mac address
ip = Parameters['Address']
port = int(Parameters['Port'])
mac = ['Mode1']
type = int(Parameters['Mode2']) # Thermostat type
# Convert the mac address to bytes (from hex)
mac_bytes = bytearray.fromhex(self.host_mac.replace(':',''))
# Establish the device
self.thermostat = broadlink.hysen((ip,port), mac_bytes, type)
# Authenticate yourself
self.thermostat.auth()
#x = Domoticz.Log(self.thermostat.get_temp())
#print(x)

Re: plugin.py generates error while importing Domoticz module

Posted: Monday 17 October 2022 15:14
by waltervl
I think you have to remove the line:

Code: Select all

from Domoticz import Devices, Parameters 
as this is not needed.

Re: plugin.py generates error while importing Domoticz module

Posted: Monday 17 October 2022 18:23
by omeijers
that does the trick,
thanks