Hi,
I want to create a new plugin who use
bluepy to check and control Awox Smartplug
I already write a
python script for domoticz who read status from the plug and send data to domoticz.
My domoticz system is a rpi3 with raspbian jessie lite and I compile domoticz from source (Version: 3.6389), PluginSystem work very well (I tried with Kody plugins, all work fine)
But with my new plugin, when i ask to import bluepy it's fail with this error :
Code: Select all
2017-01-19 23:59:03.109 Error: (smp) Module Import failed, exception: 'ImportError'
2017-01-19 23:59:03.109 Error: (smp) Module Import failed: ' Name: bluepy'
My code work for configuration in Hardware menu and create news devices, but don't load bluepy module
here the beginning of my plugin :
- Spoiler: show
Code: Select all
# Awox SmartPlug Plugin
#
# Author: zaraki673, 2017
#
"""
<plugin key="AwoxSMP" name="Awox SmartPlug" author="zaraki673" version="1.0.0">
<params>
<param field="Mode1" label="MAC Address" width="150px" required="true"/>
<param field="Mode6" label="Debug" width="75px">
<options>
<option label="True" value="Debug"/>
<option label="False" value="Normal" default="true" />
</options>
</param>
</params>
</plugin>
"""
import Domoticz
import binascii
import struct
from bluepy import btle
START_OF_MESSAGE = b'\x0f'
END_OF_MESSAGE = b'\xff\xff'
SMPstate = 0
SMPconso = 0
# Domoticz call back functions
def onStart():
global SMPstate, SMPconso
if Parameters["Mode6"] == "Debug":
Domoticz.Debugging(1)
if (len(Devices) == 0):
Domoticz.Device(Name="Status", Unit=1, TypeName="Switch").Create()
Domoticz.Device(Name="Conso", Unit=2, TypeName="Usage").Create()
Domoticz.Log("Devices created.")
else:
if (1 in Devices): SMPstate = Devices[1].nValue
if (2 in Devices): SMPconso = Devices[2].nValue
DumpConfigToLog()
Domoticz.Heartbeat(5)
return True
def onConnect(Status, Description):
return True
def onMessage(Data, Status, Extra):
return True
def onCommand(Unit, Command, Level, Hue):
return True
def onNotification(Data):
Domoticz.Log("Notification: " + str(Data))
return
def onHeartbeat():
global SMPstate, SMPconso
try:
(state, power) = plug.status_request()
except btle.BTLEException as err:
Domoticz.Log('error when requesting stat to plug %s (code %d)' % (args.ble_addr, err.code))
# print result
status = 'on' if state else 'off'
Domoticz.Log('plug state = %s' % status)
SMPstate = status
Domoticz.Log('plug power = %d W' % power)
SMPconso = power
return True
def onDisconnect():
return True
def onStop():
return True
# Generic helper functions
def DumpConfigToLog():
for x in Parameters:
if Parameters[x] != "":
Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
Domoticz.Debug("Device count: " + str(len(Devices)))
for x in Devices:
Domoticz.Debug("Device: " + str(x) + " - " + str(Devices[x]))
Domoticz.Debug("Device ID: '" + str(Devices[x].ID) + "'")
Domoticz.Debug("Device Name: '" + Devices[x].Name + "'")
Domoticz.Debug("Device nValue: " + str(Devices[x].nValue))
Domoticz.Debug("Device sValue: '" + Devices[x].sValue + "'")
Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
return
How does Python Framework work in Domoticz ?
I try in command line to import the module, it's work ...
thank's for your help