I try to do my baby steps first plugin following the wiki help page.
But there is no plugins directory into my domoticz (/etc/domoticz) !
is that normal?
ok, i've created the folder, gived access to pi user and made my first plugin /etc/domoticz/plugins/myplugin.py
but even after reboot it is not displayed in settings->material
I'm little bit lost so. Here my code , any help would be really appreciated !
Code: Select all
#
# Windows Screen Remote
#
# Author: Giova, 2017
#
# let Domoticz remotely control your Windows PC Screen (turn On/Off)
#
"""
<plugin key="WinScreenRemote" version="1.0.0" name="Windows Screen Remote" author="Giova" >
<params>
<param field="Address" label="IP Address" width="200px" required="true" default="192.168.0.1"/>
<param field="Port" label="Port" width="30px" required="true" default="5553"/>
<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
isConnected = False
isStarting = False
nextConnect = 3
oustandingPings = 0
# Device Status - When off set device values to negative
powerOn = False
def onStart():
if Parameters["Mode6"] == "Debug":
Domoticz.Debugging(1)
if (len(Devices) == 0):
Domoticz.Device(Name="Screen Power", Unit=1, TypeName="Switch").Create()
Domoticz.Log("Devices created.")
DumpConfigToLog()
Domoticz.Transport("TCP/IP", Parameters["Address"], Parameters["Port"])
Domoticz.Protocol("Line")
Domoticz.Connect()
return
def onConnect(Status, Description):
global isConnected
if (Status == 0):
isConnected = True
Domoticz.Log("Connected successfully to: "+Parameters["Address"]+":"+Parameters["Port"])
Domoticz.Send('PW?\r')
else:
isConnected = False
Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Port"])
Domoticz.Debug("Failed to connect ("+str(Status)+") to: "+Parameters["Address"]+":"+Parameters["Port"]+" with error: "+Description)
# Turn devices off in Domoticz
for Key in Devices:
UpdateDevice(Key, 0, Devices[Key].sValue)
return True
def onMessage(Data, Status, Extra):
global oustandingPings, isStarting
global powerOn
oustandingPings = oustandingPings - 1
Domoticz.Debug("onMessage ("+str(isStarting)+") called with Data: '"+str(Data)+"'")
Data = Data.strip()
action = Data[0:2]
detail = Data[2:]
if (action == "PW"): # Power Status
if (detail == "Off"):
powerOn = False
elif (detail == "On"):
powerOn = True
else: Domoticz.Debug("Unknown: Action "+action+", Detail '"+detail+"' ignored.")
else:
Domoticz.Error("Unknown message '"+action+"' ignored.")
SyncDevices()
return
def onCommand(Unit, Command, Level, Hue):
global powerOn
Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
Command = Command.strip()
action, sep, params = Command.partition(' ')
if (powerOn == False):
Domoticz.Send('PWON\r') # Any commands sent within 4 seconds of this will potentially be ignored
else:
if (action == "On"):
if (Unit == 1): Domoticz.Send('PWON\r')
else: Domoticz.Error( "Unknown Unit number in command "+str(Unit)+".")
elif (action == "Off"):
if (Unit == 1): Domoticz.Send('PWOFF\r')
else: Domoticz.Error( "Unknown Unit number in command "+str(Unit)+".")
else:
Domoticz.Error("Unhandled action '"+action+"' ignored, options are On/Set/Off")
return
def onDisconnect():
global isConnected, powerOn
isConnected = False
powerOn = False
Domoticz.Log("Device has disconnected.")
SyncDevices()
return
def onStop():
Domoticz.Log("onStop called")
return 8
def onHeartbeat():
global isConnected, nextConnect, oustandingPings
if (isConnected == True):
if (oustandingPings > 5):
Domoticz.Disconnect()
nextConnect = 0
else:
Domoticz.Send('PW?\r')
oustandingPings = oustandingPings + 1
else:
# if not connected try and reconnected every 3 heartbeats
oustandingPings = 0
nextConnect = nextConnect - 1
if (nextConnect <= 0):
nextConnect = 3
Domoticz.Connect()
return
def SyncDevices():
global powerOn
if (powerOn == False):
UpdateDevice(1, 0, "Off")
else:
UpdateDevice(1, 1, "On")
return
def UpdateDevice(Unit, nValue, sValue):
# Make sure that the Domoticz device still exists (they can be deleted) before updating it
if (Unit in Devices):
if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue):
Devices[Unit].Update(nValue, str(sValue))
Domoticz.Log("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[Unit].Name+")")
return
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