def onStart(self): # setup the appropriate logging level try: debuglevel = int(Parameters["Mode6"]) except ValueError: debuglevel = 0 self.loglevel = Parameters["Mode6"] if debuglevel != 0: self.debug = True Domoticz.Debugging(debuglevel) DumpConfigToLog() self.loglevel = "Verbose" else: self.debug = False Domoticz.Debugging(0) # create the child devices if these do not exist yet devicecreated = [] if 1 not in Devices: Options = { "LevelActions": "||", "LevelNames": "Off|Auto|Forced", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Thermostat Control", Unit=1, TypeName="Selector Switch", Switchtype=18, Image=15, Options=Options, Used=1).Create() devicecreated.append(deviceparam(1, 0, "0")) # default is Off state if 2 not in Devices: Options = { "LevelActions": "||", "LevelNames": "Off|Normal|Economy", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Thermostat Mode", Unit=2, TypeName="Selector Switch", Switchtype=18, Image=15, Options=Options, Used=1).Create() devicecreated.append(deviceparam(2, 0, "10")) # default is normal mode if 3 not in Devices: Domoticz.Device(Name="Pause", Unit=3, TypeName="Switch", Image=9, Used=1).Create() devicecreated.append(deviceparam(3, 0, "")) # default is Off if 4 not in Devices: Domoticz.Device(Name="Setpoint Normal", Unit=4, Type=242, Subtype=1, Used=1).Create() devicecreated.append(deviceparam(4, 0, "20")) # default is 20 degrees if 5 not in Devices: Domoticz.Device(Name="Setpoint Economy", Unit=5, Type=242, Subtype=1, Used=1).Create() devicecreated.append(deviceparam(5, 0, "20")) # default is 20 degrees if 6 not in Devices: Domoticz.Device(Name="AVG Temperature", Unit=6, TypeName="Temperature").Create() devicecreated.append(deviceparam(6, 0, "20")) # default is 20 degrees if 7 not in Devices: Domoticz.Device(Name="Heating", Unit=7, TypeName="Switch", Image=15, Used=1).Create() devicecreated.append(deviceparam(7, 0, "")) # default is Off if 8 not in Devices: Domoticz.Device(Name="Wall Sensor", Unit=8, TypeName="Temp+Hum+Baro", Used=1).Create() devicecreated.append(deviceparam(8, 0, "20")) # default is 20 degrees # if any device has been created in onStart(), now is time to update its defaults for device in devicecreated: Devices[device.unit].Update(nValue=device.nvalue, sValue=device.svalue) # build lists of sensors and switches self.InTempSensors = parseCSV(Parameters["Mode1"]) Domoticz.Debug("Inside Temperature sensors = {}".format( self.InTempSensors)) self.OutTempSensors = parseCSV(Parameters["Mode2"]) Domoticz.Debug("Outside Temperature sensors = {}".format( self.OutTempSensors)) self.Heaters = parseCSV(Parameters["Mode3"]) Domoticz.Debug("Heaters = {}".format(self.Heaters)) # build dict of status of all temp sensors to be used when handling timeouts for sensor in itertools.chain(self.InTempSensors, self.OutTempSensors): self.ActiveSensors[sensor] = True # splits additional parameters params = parseCSV(Parameters["Mode5"]) if len(params) == 5: self.calculate_period = CheckParam("Calculation Period", params[0], 30) if self.calculate_period < 5: Domoticz.Error( "Invalid calculation period parameter. Using minimum of 5 minutes !" ) self.calculate_period = 5 self.minheatpower = CheckParam("Minimum Heating (%)", params[1], 0) if self.minheatpower > 100: Domoticz.Error( "Invalid minimum heating parameter. Using maximum of 100% !" ) self.minheatpower = 100 self.pauseondelay = CheckParam("Pause On Delay", params[2], 2) self.pauseoffdelay = CheckParam("Pause Off Delay", params[3], 0) self.forcedduration = CheckParam("Forced Mode Duration", params[4], 60) if self.forcedduration < 30: Domoticz.Error( "Invalid forced mode duration parameter. Using minimum of 30 minutes !" ) self.calculate_period = 30 else: Domoticz.Error("Error reading Mode5 parameters") # loads persistent variables from dedicated user variable # note: to reset the thermostat to default values (i.e. ignore all past learning), # just delete the relevant "<plugin name>-InternalVariables" user variable Domoticz GUI and restart plugin self.getUserVar() # if mode = off then make sure actual heating is off just in case if was manually set to on if Devices[1].sValue == "0": self.switchHeat(False)
def onStart(self): try: self.logLevel = int(Parameters["Mode6"]) except: self.Log( "Debuglevel '" + Parameters["Mode6"] + "' is not an integer", 1, 3) if self.logLevel == 10: Domoticz.Debugging(1) self.Log( "onStart called, heartbeat interval " + str(Parameters["Mode1"]) + " seconds", 4, 1) Domoticz.Heartbeat(int(Parameters["Mode1"])) try: self.maxOutstandingMessages = int(Parameters["Mode5"]) except: self.Log( "max open messages '" + Parameters["Mode5"] + "' is not an integer", 1, 3) dictValue = 0 for item in Parameters["Mode3"].split('|'): self.selectorMap[dictValue] = item dictValue = dictValue + 10 if (Parameters["Mode3"].count('|') != Parameters["Mode4"].count('|')): self.Log( "Sources (" + Parameters["Mode3"] + ") and names (" + Parameters["Mode4"] + ") do not match! Using only sources", 1, 3) sourceOptions = { 'LevelActions': '|' * Parameters["Mode3"].count('|'), 'LevelNames': Parameters["Mode3"], 'LevelOffHidden': 'false', 'SelectorStyle': '0' } # 1 = combobox, 0 = buttons else: sourceOptions = { 'LevelActions': '|' * Parameters["Mode4"].count('|'), 'LevelNames': Parameters["Mode4"], 'LevelOffHidden': 'false', 'SelectorStyle': '0' } #ICONS if ("DenonMarantzIncrease" not in Images): Domoticz.Image('DenonMarantzIncrease.zip').Create() if ("DenonMarantzDecrease" not in Images): Domoticz.Image('DenonMarantzDecrease.zip').Create() if ("DenonMarantzboombox" not in Images): Domoticz.Image('DenonMarantzboombox.zip').Create() if (2 not in Devices): Domoticz.Device(Name="Source", Unit=2, TypeName="Selector Switch", Switchtype=18, Image=5, Options=sourceOptions).Create() if (len(Devices[2].sValue) > 0): self.mainSource = int(Devices[2].sValue) self.mainOn = (Devices[2].nValue != 0) elif (Devices[2].Options != sourceOptions): self.Log("Sources or names have changed.", Level=2, Type=1) # update does not work, so delte it and readd it. Devices[2].Delete() Domoticz.Device(Name="Source", Unit=2, TypeName="Selector Switch", Switchtype=18, Image=5, Used=1, Options=sourceOptions).Create() if (3 not in Devices): Domoticz.Device(Name="Volume", Unit=3, Type=244, Subtype=73, Switchtype=7, Image=8).Create() if (len(Devices[3].sValue) > 0): self.mainVolume1 = int(Devices[3].sValue) if ( Devices[3].nValue != 0) else int(Devices[3].sValue) * -1 if (4 not in Devices): Domoticz.Device(Name="Tuner up", Unit=4, TypeName="Switch", Image=Images["DenonMarantzIncrease"].ID).Create() if (5 not in Devices): Domoticz.Device(Name="Tuner down", Unit=5, TypeName="Switch", Image=Images["DenonMarantzDecrease"].ID).Create() if (6 not in Devices): Domoticz.Device(Name="Station", Unit=6, Type=243, Subtype=19, Switchtype=0, Image=Images["DenonMarantzboombox"].ID).Create() self.DumpConfigToLog() return
def onStart(self): if Parameters["Mode6"] != "Normal": Domoticz.Debugging(1) DumpConfigToLog() self.callbackPort = Parameters["Port"] self.bridgeIP = Parameters["Mode1"] self.bridgeToken = Parameters["Mode2"] self.pollInterval = int(Parameters["Mode3"]) self.bridgePort = Parameters["Mode4"] s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) self.myIP = s.getsockname()[0] s.close() Domoticz.Debug("My IP is " + self.myIP) Domoticz.Log("Nuki plugin started on IP " + self.myIP + " and port " + str(self.callbackPort)) req = 'http://' + self.bridgeIP + ':' + self.bridgePort + '/list?token=' + self.bridgeToken Domoticz.Debug('REQUESTING ' + req) # resp = urllib.request.urlopen(req).read() try: resp = urllib.request.urlopen(req).read() except HTTPError as e: Domoticz.Error('NUKI HTTPError code: ' + str(e.code)) except URLError as e: Domoticz.Error('NUKI URLError Reason: ' + str(e.reason)) else: strData = resp.decode("utf-8", "ignore") Domoticz.Debug("Lock list received " + strData) resp = json.loads(strData) num = len(resp) Domoticz.Debug("I count " + str(num) + " locks") self.numLocks = num # create a lock device for every listed lock # and update the lock state and battery immediately as listed in the response for i in range(num): if (i + 1 not in Devices): Domoticz.Device(Name=resp[i]["name"], Unit=i + 1, TypeName="Switch", Switchtype=19, Used=1).Create() Domoticz.Log("Lock " + resp[i]["name"] + " created.") else: Domoticz.Debug("Lock " + resp[i]["name"] + " already exists.") self.lockNames.append(resp[i]["name"]) self.lockIds.append(resp[i]["nukiId"]) Domoticz.Debug( "Lock batt " + str(resp[i]["lastKnownState"]["batteryCritical"])) Domoticz.Debug("Lock stateName " + resp[i]["lastKnownState"]["stateName"]) Domoticz.Debug("Lock state " + str(resp[i]["lastKnownState"]["state"])) if (resp[i]["lastKnownState"]["batteryCritical"]): batt = 0 else: batt = 255 nval = -1 sval = "Unknown" if (resp[i]["lastKnownState"]["state"] == 1): sval = 'Locked' nval = 1 elif (resp[i]["lastKnownState"]["state"] == 3): sval = 'Unlocked' nval = 0 Devices[i + 1].Update(nValue=nval, sValue=str(sval), Description=str(resp[i]["nukiId"]), BatteryLevel=batt) # create unlatch device for every listed lock for i in range(num): if ((2 * (i + 1)) not in Devices): Domoticz.Device(Name=resp[i]["name"] + "Unlatch", Unit=2 * (i + 1), TypeName="Switch", Switchtype=9, Used=1).Create() Domoticz.Log("Unlatch for Lock " + resp[i]["name"] + " created.") else: Domoticz.Debug("Unlatch for Lock " + resp[i]["name"] + " already exists.") Domoticz.Debug("Lock(s) created") DumpConfigToLog() # check if callback exists and, if not, create req = 'http://' + self.bridgeIP + ':' + self.bridgePort + '/callback/list?token=' + self.bridgeToken Domoticz.Debug('checking callback ' + req) found = False try: resp = urllib.request.urlopen(req).read() except HTTPError as e: Domoticz.Error('NUKI HTTPError code: ' + str(e.code)) except URLError as e: Domoticz.Error('NUKI URLError Reason: ' + str(e.reason)) except HTTPException as e: Domoticz.Error('NUKI URLError Reason: ' + str(e.reason)) else: strData = resp.decode("utf-8", "ignore") Domoticz.Debug("Callback list received " + strData) resp = json.loads(strData) urlNeeded = 'http://' + self.myIP + ':' + self.callbackPort num = len(resp["callbacks"]) Domoticz.Debug("Found callbacks: " + str(num)) if num > 0: for i in range(num): if resp["callbacks"][i]["url"] == urlNeeded: Domoticz.Debug("Callback already installed") found = True if not found: # create callback for the bridge (all lock changes reported on this callback) callback = 'http://' + self.bridgeIP + ':' + self.bridgePort + '/callback/add?url=http%3A%2F%2F' + self.myIP + '%3A' + self.callbackPort + '&token=' + self.bridgeToken Domoticz.Log('Installing callback ' + callback) try: resp = urllib.request.urlopen(callback).read() except HTTPError as e: Domoticz.Error('NUKI HTTPError code: ' + str(e.code)) except URLError as e: Domoticz.Error('NUKI URLError Reason: ' + str(e.reason)) else: strData = resp.decode("utf-8", "ignore") Domoticz.Debug("Callback response received " + strData) resp = json.loads(strData) if resp["success"]: Domoticz.Log("Nuki Callback install succeeded") else: Domoticz.Error("Unable to register NUKI callback") # now listen on the port for any state changes else: self.httpServerConn = Domoticz.Connection( Name="Server Connection", Transport="TCP/IP", Protocol="HTML", Port=Parameters["Port"]) self.httpServerConn.Listen() Domoticz.Debug("Leaving on start")
def onStart(self): Domoticz.Log("onStart called") # setup the appropriate logging level try: debuglevel = int(Parameters["Mode6"]) except ValueError: debuglevel = 0 self.loglevel = Parameters["Mode6"] if debuglevel != 0: self.debug = True Domoticz.Debugging(debuglevel) DumpConfigToLog() self.loglevel = "Verbose" else: self.debug = False Domoticz.Debugging(0) # create the child devices if these do not exist yet devicecreated = [] if 1 not in Devices: Domoticz.Device(Name="Connexion", Unit=1, TypeName="Selector Switch", Switchtype=2, Used=1).Create() devicecreated.append(deviceparam(1, 1, "100")) # default is connected if 2 not in Devices: Domoticz.Device( Name="ASR Index", Unit=2, Type=243, Subtype=6, ).Create() devicecreated.append(deviceparam(2, 1, "1")) # default is Index 1 if 3 not in Devices: Domoticz.Device(Name="AC On/Off", Unit=3, TypeName="Switch", Image=9).Create() devicecreated.append(deviceparam(3, 1, "100")) # default is On if 4 not in Devices: Options = { "LevelActions": "||", "LevelNames": "Off|Auto|Cool|Heat|Dry|Fan", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="AC Manual Mode", Unit=4, TypeName="Selector Switch", Switchtype=18, Image=15, Options=Options, Used=1).Create() devicecreated.append(deviceparam(4, 0, "30")) # default is Heating mode if 5 not in Devices: Options = { "LevelActions": "||", "LevelNames": "Off|Auto|Low|Mid|High", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="AC Manual Fan Speed", Unit=5, TypeName="Selector Switch", Switchtype=18, Image=15, Options=Options, Used=1).Create() devicecreated.append(deviceparam(5, 0, "10")) # default is Auto mode if 6 not in Devices: Domoticz.Device(Name="AC Setpoint", Unit=6, Type=242, Subtype=1).Create() devicecreated.append(deviceparam(6, 0, "20")) # default is 20 degrees if 7 not in Devices: Options = { "LevelActions": "||", "LevelNames": "Off|Manual|Auto", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Wind direction (swing)", Unit=7, TypeName="Selector Switch", Switchtype=18, Image=15, Options=Options, Used=1).Create() devicecreated.append(deviceparam(7, 0, "10")) # default is Manual if 8 not in Devices: Domoticz.Device(Name="Presence sensor", Unit=8, TypeName="Switch", Image=9).Create() devicecreated.append(deviceparam(8, 0, "")) # default is Off if 9 not in Devices: Options = { "LevelActions": "||", "LevelNames": "Disconnected|Off|Auto|Manual", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Control", Unit=9, TypeName="Selector Switch", Switchtype=18, Image=9, Options=Options, Used=1).Create() devicecreated.append(deviceparam(9, 0, "10")) # default is Off if 10 not in Devices: Domoticz.Device(Name="Thermostat Setpoint", Unit=10, Type=242, Subtype=1, Used=1).Create() devicecreated.append(deviceparam(10, 0, "21")) # default is 21 degrees if 11 not in Devices: Domoticz.Device(Name="Presence Active", Unit=11, TypeName="Switch", Image=9, Used=1).Create() devicecreated.append(deviceparam(11, 0, "")) # default is Off if 12 not in Devices: Domoticz.Device(Name="Room temp", Unit=12, TypeName="Temperature", Used=1).Create() devicecreated.append(deviceparam(12, 0, "30")) # default is 30 degrees if 13 not in Devices: Domoticz.Device(Name="Pause requested", Unit=13, TypeName="Switch", Image=9, Used=1).Create() devicecreated.append(deviceparam(13, 0, "")) # default is Off # if any device has been created in onStart(), now is time to update its defaults for device in devicecreated: Devices[device.unit].Update(nValue=device.nvalue, sValue=device.svalue) # build lists of sensors and switches self.DTpresence = parseCSV(Parameters["Mode3"]) Domoticz.Debug("DTpresence = {}".format(self.DTpresence)) self.InTempSensors = parseCSV(Parameters["Mode4"]) Domoticz.Debug("Inside Temperature sensors = {}".format( self.InTempSensors)) # splits additional parameters params = parseCSV(Parameters["Mode5"]) if len(params) == 7: self.DTDayNight = CheckParam("Day/Night Activator", params[0], 0) self.pauseondelay = CheckParam("Pause On Delay", params[1], 1) self.pauseoffdelay = CheckParam("Pause Off Delay", params[2], 1) self.presenceondelay = CheckParam("Presence On Delay", params[3], 2) self.presenceoffdelay = CheckParam("Presence Off Delay", params[4], 45) self.reductedsp = CheckParam("Reduction temp", params[5], 3) self.deltamax = CheckParam("delta max fan", params[6], 10) else: Domoticz.Error("Error reading Mode5 parameters") # Check if the used control mode is ok if (Devices[9].sValue == "20"): self.ModeAuto = True self.ModeManual = False self.powerOn = 1 elif (Devices[9].sValue == "30"): self.ModeAuto = False self.ModeManual = True self.powerOn = 1 elif (Devices[9].sValue == "10"): self.ModeAuto = True self.ModeManual = False self.powerOn = 0 # reset presence detection when starting the plugin. Devices[8].Update(nValue=0, sValue=Devices[8].sValue) self.Presencemode = False self.Presence = False self.PresenceTH = False self.presencechangedtime = datetime.now() self.PresenceDetected = False # reset time info when starting the plugin. self.controlinfotime = datetime.now() self.PLUGINstarteddtime = datetime.now() self.readTemps()
def onStart(self): self.myDebug("onStart called") Domoticz.Log( "Ce plugin est compatible avec Domoticz version 3.9517 et plus récent, mais la vue par heure peut ne pas fonctionner avec la version 4.9700" ) self.sUser = Parameters["Username"] self.sPassword = Parameters["Password"] self.iHistoryDaysForHoursView = Parameters["Mode1"] self.iHistoryDaysForDaysView = Parameters["Mode2"] self.bAutoAcceptTerms = Parameters["Mode4"] == "True" self.sConsumptionType = Parameters["Mode5"] try: self.iDebugLevel = int(Parameters["Mode3"]) except ValueError: self.iDebugLevel = 0 if self.iDebugLevel > 1: Domoticz.Debugging(1) # History for short log is 7 days max (default to 7) try: self.iHistoryDaysForHoursView = int(self.iHistoryDaysForHoursView) except: self.iHistoryDaysForHoursView = 7 if self.iHistoryDaysForHoursView < 0: self.iHistoryDaysForHoursView = 0 elif self.iHistoryDaysForHoursView > 7: self.iHistoryDaysForHoursView = 7 # History for short log is 7 days max (default to 366) try: self.iHistoryDaysForDaysView = int(self.iHistoryDaysForDaysView) except: self.iHistoryDaysForDaysView = 366 if self.iHistoryDaysForDaysView < 28: self.iHistoryDaysForDaysView = 28 elif self.iHistoryDaysForDaysView > 100000: self.iHistoryDaysForDaysView = 100000 if (self.sConsumptionType == "month") and (self.iHistoryDaysForDaysView < 32): self.iHistoryDaysForDaysView = 32 if (self.sConsumptionType == "lmonth") and (self.iHistoryDaysForDaysView < 63): self.iHistoryDaysForDaysView = 63 if (self.sConsumptionType == "year") and (self.iHistoryDaysForDaysView < 366): self.iHistoryDaysForDaysView = 366 Domoticz.Log("Adresse e-mail mise à " + self.sUser) if self.sPassword: Domoticz.Log("Mot de passe entré") else: Domoticz.Log("Mot de passe laissé vide") Domoticz.Log("Consommation à montrer sur le tableau de bord mis à " + self.sConsumptionType) Domoticz.Log( "Accepter automatiquement les conditions d'utilisation mis à " + str(self.bAutoAcceptTerms)) Domoticz.Log( "Nombre de jours à récupérer pour la vue par heures mis à " + str(self.iHistoryDaysForHoursView)) Domoticz.Log( "Nombre de jours à récupérer pour les autres vues mis à " + str(self.iHistoryDaysForDaysView)) Domoticz.Log("Debug mis à " + str(self.iDebugLevel)) # most init self.__init__() Domoticz.Log( "Si vous ne voyez pas assez de données dans la vue par heures, augmentez le paramètre Log des capteurs qui se trouve dans Réglages / Paramètres / Historique des logs" ) if self.createDevice(): self.nextConnection = datetime.now() else: self.setNextConnection(False) # Now we can enabling the plugin self.isStarted = True
def onStop(self): Domoticz.Debugging(0)
def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == 'Debug': self.debug = True Domoticz.Debugging(1) DumpConfigToLog() else: Domoticz.Debugging(0) Domoticz.Heartbeat(20) self.pollinterval = int(Parameters["Mode3"]) * 60 self.variables = { self.UNIT_AIR_QUALITY_INDEX: { "Name": _("Air Quality Index"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "AQI" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AVARAGE_AQI: { "Name": _("Avarage Air Quality Index"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "AQI" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AIR_POLLUTION_LEVEL: { "Name": _("Air pollution Level"), "TypeName": "Alert", "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_TEMPERATURE: { "Name": _("Temperature"), "TypeName": "Temperature", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_HUMIDITY: { "Name": _("Humidity"), "TypeName": "Humidity", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_MOTOR_SPEED: { "Name": _("Fan Speed"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "RPM" }, "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, } #create switches if (len(Devices) == 0): Domoticz.Device(Name="Power", Unit=self.UNIT_POWER_CONTROL, TypeName="Switch", Image=7).Create() Options = { "LevelActions": "||||", "LevelNames": "Auto|Silent|Favorite|Idle", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Source", Unit=self.UNIT_MODE_CONTROL, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() Domoticz.Log("Devices created.") Domoticz.Device(Name="Fan Favorite level", Unit=self.UNIT_MOTOR_SPEED_FAVORITE, Type=244, Subtype=73, Switchtype=7, Image=7).Create() else: if (self.UNIT_POWER_CONTROL in Devices): Domoticz.Log("Device UNIT_MODE_CONTROL with id " + str(self.UNIT_POWER_CONTROL) + " exist") else: Domoticz.Device(Name="Power", Unit=self.UNIT_POWER_CONTROL, TypeName="Switch", Image=7).Create() if (self.UNIT_MODE_CONTROL in Devices): Domoticz.Log("Device UNIT_MODE_CONTROL with id " + str(self.UNIT_MODE_CONTROL) + " exist") else: Options = { "LevelActions": "||||", "LevelNames": "Idle|Silent|Favorite|Auto", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Mode", Unit=self.UNIT_MODE_CONTROL, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() if (self.UNIT_MOTOR_SPEED_FAVORITE in Devices): Domoticz.Log("Device UNIT_MOTOR_SPEED_FAVORITE with id " + str(self.UNIT_MOTOR_SPEED_FAVORITE) + " exist") else: Domoticz.Device(Name="Fan Favorite level", Unit=self.UNIT_MOTOR_SPEED_FAVORITE, Type=244, Subtype=73, Switchtype=7, Image=7).Create() self.onHeartbeat(fetch=False)
def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == 'Debug': self.debug = True Domoticz.Debugging(1) DumpConfigToLog() else: Domoticz.Debugging(0) self.myAir = miio.airpurifier.AirPurifier(Parameters["Address"], Parameters["Mode1"]) self.myAir._timeout = 1 self.messageThread.start() Domoticz.Heartbeat(20) self.pollinterval = int(Parameters["Mode3"]) * 60 self.variables = { self.UNIT_ILLUMINANCE_SENSOR: { "Name": _("Illuminance sensor"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "lux" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.FILTER_LIFE_REMAINING: { "Name": _("Filter life remaining"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "%" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.FILTER_WORK_HOURS: { "Name": _("Filter work hours"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "h" }, "Image": 7, "Used": 0, "nValue": 0, "sValue": 0, }, self.UNIT_AIR_QUALITY_INDEX: { "Name": _("Air Quality Index"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "AQI" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AVARAGE_AQI: { "Name": _("Avarage Air Quality Index"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "AQI" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AIR_POLLUTION_LEVEL: { "Name": _("Air pollution Level"), "TypeName": "Alert", "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_TEMPERATURE: { "Name": _("Temperature"), "TypeName": "Temperature", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_HUMIDITY: { "Name": _("Humidity"), "TypeName": "Humidity", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_MOTOR_SPEED: { "Name": _("Fan Speed"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "RPM" }, "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, } #create switches if (len(Devices) == 0): Domoticz.Device(Name="Power", Unit=self.UNIT_POWER_CONTROL, TypeName="Switch", Image=7).Create() Options = { "LevelActions": "||||", "LevelNames": "Auto|Silent|Favorite|Idle", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Source", Unit=self.UNIT_MODE_CONTROL, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() Domoticz.Log("Devices created.") Domoticz.Device(Name="Fan Favorite level", Unit=self.UNIT_MOTOR_SPEED_FAVORITE, Type=244, Subtype=73, Switchtype=7, Image=7).Create() else: if (self.UNIT_POWER_CONTROL in Devices): Domoticz.Log("Device UNIT_MODE_CONTROL with id " + str(self.UNIT_POWER_CONTROL) + " exist") else: Domoticz.Device(Name="Power", Unit=self.UNIT_POWER_CONTROL, TypeName="Switch", Image=7).Create() if (self.UNIT_MODE_CONTROL in Devices): Domoticz.Log("Device UNIT_MODE_CONTROL with id " + str(self.UNIT_MODE_CONTROL) + " exist") else: Options = { "LevelActions": "||||", "LevelNames": "Idle|Silent|Favorite|Auto", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Mode", Unit=self.UNIT_MODE_CONTROL, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() if (self.UNIT_MOTOR_SPEED_FAVORITE in Devices): Domoticz.Log("Device UNIT_MOTOR_SPEED_FAVORITE with id " + str(self.UNIT_MOTOR_SPEED_FAVORITE) + " exist") else: Domoticz.Device(Name="Fan Favorite level", Unit=self.UNIT_MOTOR_SPEED_FAVORITE, Type=244, Subtype=73, Switchtype=7, Image=7).Create() if (self.UNIT_LED in Devices): Domoticz.Log("Device UNIT_LED with id " + str(self.UNIT_LED) + " exist") else: Domoticz.Device(Name="Fan LED", Unit=self.UNIT_LED, TypeName="Switch", Image=7).Create() self.onHeartbeat(fetch=False)
def onStart(self): Domoticz.Log("onStart called") try: Domoticz.Log( "Modbus RTU/ASCII/TCP - Universal READ loaded!, using python v" + sys.version[:6] + " and pymodbus v" + pymodbus.__version__) except: Domoticz.Log("Modbus RTU/ASCII/TCP - Universal READ loaded!") # Dependancies notification try: if (float(Parameters["DomoticzVersion"][:6]) < float("2020.2")): Domoticz.Error( "WARNING: Domoticz version is outdated/not supported, please update!" ) if (float(sys.version[:1]) < 3): Domoticz.Error("WARNING: Python3 should be used!") if (float(pymodbus.__version__[:3]) < float("2.3")): Domoticz.Error( "WARNING: Pymodbus version is outdated, please update!") except: Domoticz.Error("WARNING: Dependancies could not be checked!") ######################################## # READ-IN OPTIONS AND SETTINGS ######################################## # Convert "option names" to variables for easy reading and debugging. # Note: Parameters["Port"] cannot accept other value then int! (e.g. 192.168.0.0 will result in 192) Domoticz_Setting_Communication_MODDEB = Parameters["Mode1"].split( ":") # Split MODE and DEBUG setting MODE:DEBUG self.Domoticz_Setting_Communication_Mode = Domoticz_Setting_Communication_MODDEB[ 0] self.Domoticz_Setting_Serial_Port = Parameters["SerialPort"] self.Domoticz_Setting_Baudrate = Parameters["Mode2"] self.Domoticz_Setting_Port_Mode = Parameters["Mode3"] self.Domoticz_Setting_Modbus_Function = Parameters["Username"] self.Domoticz_Setting_Register_Number = Parameters["Port"] self.Domoticz_Setting_Data_Type = Parameters["Mode6"] self.Domoticz_Setting_Scale_Factor = Parameters["Mode5"] self.Domoticz_Setting_Sensor_Type = Parameters["Mode4"] self.Domoticz_Setting_Device_IDPOL = Parameters["Password"].split( ":") # Split ID and pollrate setting ID:POLL (heartbeat) self.Domoticz_Setting_Device_ID = 1 # Default if len(self.Domoticz_Setting_Device_IDPOL) > 0: self.Domoticz_Setting_Device_ID = self.Domoticz_Setting_Device_IDPOL[ 0] self.Domoticz_Setting_Device_Pollrate = 10 # Default if len(self.Domoticz_Setting_Device_IDPOL) > 1: self.Domoticz_Setting_Device_Pollrate = self.Domoticz_Setting_Device_IDPOL[ 1] self.Domoticz_Setting_TCP_IPPORT = Parameters["Address"].split( ":") # Split address and port setting TCP:IP self.Domoticz_Setting_TCP_IP = 0 # Default if len(self.Domoticz_Setting_TCP_IPPORT) > 0: self.Domoticz_Setting_TCP_IP = self.Domoticz_Setting_TCP_IPPORT[0] self.Domoticz_Setting_TCP_PORT = 0 # Default if len(self.Domoticz_Setting_TCP_IPPORT) > 1: self.Domoticz_Setting_TCP_PORT = self.Domoticz_Setting_TCP_IPPORT[ 1] # Set debug yes/no if (Domoticz_Setting_Communication_MODDEB[1] == "debug"): Domoticz.Debugging(1) # Enable debugging DumpConfigToLog() Domoticz.Debug("***** NOTIFICATION: Debug enabled!") else: Domoticz.Debugging(0) # Disable debugging # Set device pollrate (heartbeat) Domoticz.Heartbeat(int(self.Domoticz_Setting_Device_Pollrate)) Domoticz.Debug("***** NOTIFICATION: Pollrate (heartbeat): " + self.Domoticz_Setting_Device_Pollrate + " seconds.") # RTU - Serial port settings if (self.Domoticz_Setting_Port_Mode == "S1B7PN"): self.StopBits, self.ByteSize, self.Parity = 1, 7, "N" if (self.Domoticz_Setting_Port_Mode == "S1B7PE"): self.StopBits, self.ByteSize, self.Parity = 1, 7, "E" if (self.Domoticz_Setting_Port_Mode == "S1B7PO"): self.StopBits, self.ByteSize, self.Parity = 1, 7, "O" if (self.Domoticz_Setting_Port_Mode == "S1B8PN"): self.StopBits, self.ByteSize, self.Parity = 1, 8, "N" if (self.Domoticz_Setting_Port_Mode == "S1B8PE"): self.StopBits, self.ByteSize, self.Parity = 1, 8, "E" if (self.Domoticz_Setting_Port_Mode == "S1B8PO"): self.StopBits, self.ByteSize, self.Parity = 1, 8, "O" if (self.Domoticz_Setting_Port_Mode == "S2B7PN"): self.StopBits, self.ByteSize, self.Parity = 2, 7, "N" if (self.Domoticz_Setting_Port_Mode == "S2B7PE"): self.StopBits, self.ByteSize, self.Parity = 2, 7, "E" if (self.Domoticz_Setting_Port_Mode == "S2B7PO"): self.StopBits, self.ByteSize, self.Parity = 2, 7, "O" if (self.Domoticz_Setting_Port_Mode == "S2B8PN"): self.StopBits, self.ByteSize, self.Parity = 2, 8, "N" if (self.Domoticz_Setting_Port_Mode == "S2B8PE"): self.StopBits, self.ByteSize, self.Parity = 2, 8, "E" if (self.Domoticz_Setting_Port_Mode == "S2B8PO"): self.StopBits, self.ByteSize, self.Parity = 2, 8, "O" # Read n registers depending on data type # Added additional options for byte/word swapping self.Register_Count = 1 # Default if (self.Domoticz_Setting_Data_Type == "noco"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "bool"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "int8LSB"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "int8MSB"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "int16"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "int16s"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "int32"): self.Register_Count = 2 if (self.Domoticz_Setting_Data_Type == "int32s"): self.Register_Count = 2 if (self.Domoticz_Setting_Data_Type == "int64"): self.Register_Count = 4 if (self.Domoticz_Setting_Data_Type == "int64s"): self.Register_Count = 4 if (self.Domoticz_Setting_Data_Type == "uint8LSB"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "uint8MSB"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "uint16"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "uint16s"): self.Register_Count = 1 if (self.Domoticz_Setting_Data_Type == "uint32"): self.Register_Count = 2 if (self.Domoticz_Setting_Data_Type == "uint32s"): self.Register_Count = 2 if (self.Domoticz_Setting_Data_Type == "uint64"): self.Register_Count = 4 if (self.Domoticz_Setting_Data_Type == "uint64s"): self.Register_Count = 4 if (self.Domoticz_Setting_Data_Type == "float32"): self.Register_Count = 2 if (self.Domoticz_Setting_Data_Type == "float32s"): self.Register_Count = 2 if (self.Domoticz_Setting_Data_Type == "float64"): self.Register_Count = 4 if (self.Domoticz_Setting_Data_Type == "float64s"): self.Register_Count = 4 if (self.Domoticz_Setting_Data_Type == "string2"): self.Register_Count = 2 if (self.Domoticz_Setting_Data_Type == "string4"): self.Register_Count = 4 if (self.Domoticz_Setting_Data_Type == "string6"): self.Register_Count = 6 if (self.Domoticz_Setting_Data_Type == "string8"): self.Register_Count = 8 self.Read_Scale_Factor = 0 if (self.Domoticz_Setting_Scale_Factor == "sfnextreg"): self.Read_Scale_Factor = 1 self.Register_Count = self.Register_Count + 1 # Due to the lack of more parameter posibility, the name will be the hardware name self.Domoticz_Setting_Sensor_Type = Parameters["Mode4"] if (len(Devices) == 0): Domoticz.Device(Name="Modbus-READ", Unit=1, TypeName=self.Domoticz_Setting_Sensor_Type, Image=0, Used=1).Create() #Added sensor type return
def onStart(self): Domoticz.Debug("onStart called") Domoticz.Debug("Debug Mode:" + Parameters["Mode6"]) if Parameters["Mode6"] == "Debug": self.debug = True Domoticz.Debugging(1) write_config_to_log() if (len(Devices) == 0): # Create new devices for the Hardware Domoticz.Debug("Creating devices") # General;Text Domoticz.Device(Name="JSON", Unit=UNITJSON, TypeName="Text", Used=1).Create() Domoticz.Debug("Device created: " + Devices[UNITJSON].Name) # Switches for the configuration Domoticz.Device(Name="Backlight", Unit=UNITBACKLIGHT, TypeName="Switch", Used=1).Create() Devices[UNITBACKLIGHT].Update(nValue=1, sValue="") Domoticz.Debug("Device created: " + Devices[UNITBACKLIGHT].Name) Domoticz.Device(Name="Cursor", Unit=UNITCURSOR, TypeName="Switch", Used=1).Create() Domoticz.Debug("Device created: " + Devices[UNITCURSOR].Name) Domoticz.Device(Name="Blinking", Unit=UNITBLINKING, TypeName="Switch", Used=1).Create() Domoticz.Debug("Device created: " + Devices[UNITBLINKING].Name) # Swiches for the push-buttons Domoticz.Device(Name="Button 0", Unit=UNITBUTTON0, TypeName="Switch", Used=1).Create() Domoticz.Debug("Device created: " + Devices[UNITBUTTON0].Name) Domoticz.Device(Name="Button 1", Unit=UNITBUTTON1, TypeName="Switch", Used=1).Create() Domoticz.Debug("Device created: " + Devices[UNITBUTTON1].Name) Domoticz.Device(Name="Button 2", Unit=UNITBUTTON2, TypeName="Switch", Used=1).Create() Domoticz.Debug("Device created: " + Devices[UNITBUTTON2].Name) Domoticz.Device(Name="Button 3", Unit=UNITBUTTON3, TypeName="Switch", Used=1).Create() Domoticz.Debug("Device created: " + Devices[UNITBUTTON3].Name) Domoticz.Debug("Creating device: OK") # Get the UID of the bricklet self.lcdUID = Parameters["Mode1"] if len(self.lcdUID) == 0: write_to_log(STATUSLEVELERROR, MSGERRNOUID) return # Flag to check if connected to the master brick self.ipConnected = 0 # Create IP connection self.ipConn = IPConnection() # Create device object self.lcdDev = BrickletLCD20x4(self.lcdUID, self.ipConn) # Connect to brickd using Host and Port try: self.ipConn.connect(Parameters["Address"], int(Parameters["Port"])) self.ipConnected = 1 Domoticz.Debug("IP Connection - OK") except: write_to_log(STATUSLEVELERROR, MSGERRNOIPCONN) return # Set the bricklet configuration: backlight, cursor, blink are set according their switch device state set_configuration(self) # Register button pressed callback to function cb_button_pressed self.lcdDev.register_callback(self.lcdDev.CALLBACK_BUTTON_PRESSED, onButtonPressedCallback) # Register button released callback to function cb_button_released self.lcdDev.register_callback(self.lcdDev.CALLBACK_BUTTON_RELEASED, onButtonReleasedCallback)
def onStart(self): Domoticz.Log("onStart called") #if Parameters["Mode4"] == "debug": Domoticz.Debugging(1) #Domoticz.Debugging(0) #Enable debugging by default, mode 4 is used for sensor mode #Removed the full name parameter Device = Parameters["Mode4"] Domoticz.Log("Device: " + Device) Domoticz.Log("Parameters[Address] " + Parameters["Address"]) # Split address to support TCP/IP device ID AddressData = Parameters["Address"].split("/") # Split on "/" UnitAddress = AddressData[0] Domoticz.Log("UnitAddress: " + str(UnitAddress)) # Is there a unit ID given after the IP? (e.g. 192.168.2.100/56) self.UnitIdForIp = 1 # Default if len(AddressData) > 1: self.UnitIdForIp = AddressData[1] Domoticz.Log("UnitIdForIp: " + self.UnitIdForIp) try: filename = Parameters["HomeFolder"] + 'modbusdevices.ini' config = configparser.ConfigParser() config.read_file(open(filename)) numberofregisters = config[Device]['numberofregisters'] Domoticz.Log("number of registers:" + numberofregisters) #if (len(Devices) <> numberofregisters): # try: # Devices[10].Delete() # Devices[9].Delete() # Devices[8].Delete() # Devices[7].Delete() # Devices[6].Delete() # Devices[5].Delete() # Devices[4].Delete() # Devices[3].Delete() # Devices[2].Delete() # Devices[1].Delete() # except Exception as e: # Domoticz.Log("Error deleting device "+repr(e)) for x in range(1, int(numberofregisters) + 1): tag = Device + '_reg_' Domoticz.Log("reg:" + str(x)) function = config[Device + '_reg_' + str(x)]['function'] reg_name = config[Device + '_reg_' + str(x)]['name'] address = config[Device + '_reg_' + str(x)]['address'] Sensortype = config[Device + '_reg_' + str(x)]['Sensortype'] datatype = config[Device + '_reg_' + str(x)]['datatype'] unitfallback = config['DEFAULT'][Sensortype] unit2 = config.get(Device + '_reg_' + str(x), 'unit', fallback=unitfallback) digits = config[Device + '_reg_' + str(x)]['digits'] devide = config[Device + '_reg_' + str(x)]['devide'] used = config[Device + '_reg_' + str(x)]['used'] multiplydevice = config[Device + '_reg_' + str(x)]['multiply'] Domoticz.Log("func:" + function + " name:" + reg_name + " adr:" + address + " sensortype:" + Sensortype + " datatype:" + datatype + " unit:" + unit2 + " devide:" + devide + " digits:" + digits + " used=" + used) if (unit2): Domoticz.Log("unit true:" + unit2) else: Domoticz.Log("unit false:" + unit2) Domoticz.Log("TypeName:" + Sensortype) #if Devices[x].TypeName<>Sensortype or (Sensortype=="kWh" and Devices[x].TypeName<>"Custom"): # Devices[x].Delete() # Domoticz.Log("Device Changed. TypeName:"+Sensortype) if (x not in Devices): if ((Sensortype == "Custom") and unit2): Options = {"Custom": "1;" + unit2} Domoticz.Log("Custom with options:" + str(Options) + " unit:" + str(x)) Domoticz.Device(Name=reg_name, Unit=x, TypeName=Sensortype, Used=0, Options=Options).Create() elif (Sensortype == "kWh"): Domoticz.Log("kwh:" + " unit:" + str(x)) Domoticz.Device(Name=reg_name, Unit=x, TypeName="Custom", Subtype=sTypeKwh, Used=0).Create() else: Domoticz.Log("without options:" + " unit:" + str(x)) Domoticz.Device(Name=reg_name, Unit=x, TypeName=Sensortype, Used=0).Create() try: Domoticz.Log("step 1:" + str(x) + "Devices:" + str(len(Devices))) Domoticz.Log("UnitAddress: " + str(UnitAddress) + " device:" + Devices[x].sValue) Domoticz.Log("step 2") #reg.append(ModbusRegister(function,address,datatype, devide,Sensortype,"",UnitAddress,Parameters["Mode1"],Devices[x],multiplydevice,digits)) reg.append( ModbusRegister(function, address, datatype, devide, Sensortype, "", self.UnitIdForIp, Parameters["Mode1"], Devices[x], multiplydevice, digits)) Domoticz.Log("step 3") Domoticz.Log("reg: created:" + str(x)) except Exception as e: Domoticz.Log("Error creating class " + repr(e)) except Exception as e: Domoticz.Log("Error opening config " + repr(e) + ":" + filename) #Due to the lack of more parameter posibility, the name will be the hardware name #if (len(Devices) == 0): # Domoticz.Device(Name=" ", Unit=1, TypeName=Parameters["Mode4"], Image=0, Used=1).Create() #Added sensor type #if (len(Devices) == 1): # Domoticz.Device(Name=" ", Unit=2, TypeName=Parameters["Mode4"], Image=0, Used=1).Create() #Added sensor type #if 3 not in Devices: # Domoticz.Device(Name="Average Line To Neutral Volts", Unit=3,TypeName="Voltage",Used=0).Create() #try: # reg.append(ModbusRegister(Parameters["Username"],int(Parameters["Password"]),Parameters["Mode6"], Parameters["Mode5"],Parameters["Mode4"],"",self.UnitIdForIp,Parameters["Mode1"],Devices[1])) # reg.append( ModbusRegister(Parameters["Username"],31,Parameters["Mode6"], Parameters["Mode5"],Parameters["Mode4"],"",self.UnitIdForIp,Parameters["Mode1"],Devices[2])) # Domoticz.Log("reg: created") #except Exception as e: # Domoticz.Log("Error creating class "+repr(e)) #Domoticz.Log("AFTER reg") #DumpConfigToLog() Domoticz.Log("Modbus RTU/ASCII/TCP - Universal READ loaded.") return
def onStart(self): #Get the variables self.debugging = Parameters["Mode6"].strip() self.dt = str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S")) self.baudrate = Parameters["Mode1"].strip() self.pin = Parameters["Mode2"].strip() self.apn = Parameters["Mode3"].strip() self.auth_phones = Parameters["Address"].strip() self.port = Parameters["SerialPort"].strip() self.passkey = unidecode(Parameters["Mode4"].strip().replace( " ", "").lower()) self.name_idx = unidecode( str(Parameters["Mode5"]).strip().replace(" ", "").lower()) #HARDCODED if self.debugging == "true": Domoticz.Debugging(2) DumpConfigToLog() #Debug data values #HEartbeat Domoticz.Heartbeat(20) Domoticz.Notifier("OnBoard_GSM") #ReConfigure the config.json success = self.reWriteConfigFile() if not success: Domoticz.Log("Reconfigure config.json --> Failed") return 0 #Create Variables and Devices if len(Devices) == 0: #SMS LOG Variable Domoticz.Device(Name="GSM Info", TypeName="Text", Unit=uid_GSMinfo, DeviceID="gsm_info").Create() Domoticz.Device(Name="Received SMS", TypeName="Text", Unit=uid_SMS, DeviceID="gsm_receivedsms").Create() Domoticz.Device(Name="GSM Network Status", TypeName="Text", Unit=uid_netstat, DeviceID="gsm_attached").Create() Domoticz.Device(Name="GSM Jamming", TypeName="Alert", Unit=uid_jamming, DeviceID="gsm_jamming").Create() #PinCode if set if self.pin != "": pin_status = os.popen( '/usr/bin/gammu --config /home/pi/.gammurc entersecuritycode PIN ' + self.pin).read() if "Nothing to enter." in pin_status: Domoticz.Log("No Pin Code required !") elif "Security error": Domoticz.Log( "Error PIN Code ! Please check in a phone (locked after 3 attempts" ) return time.sleep(0.5) # global SerialConn global ser ser = serial.Serial(port=self.port, baudrate=int(self.baudrate.split('at')[1]), timeout=1) # ser = serial.Serial(port = '/dev/ttyUSB_ttyS1',baudrate=19200,timeout=1) try: ser.open() # SerialConn = Domoticz.Connection(Name="tty_GSM", Transport="Serial", Protocol="None", Address=self.port, Baud=int(self.baudrate)) # SerialConn.Connect() # SerialConn.Send(b'AT+SJDR=1,0,255\r') except Exception as e: Domoticz.Debug("error open serial port: " + str(e)) #Set the jamming detection option ser.write(b'AT+SJDR=1,0,255\r') ser.close() #Check that everything is running fine network_info = os.popen( '/usr/bin/gammu --config /home/pi/.gammurc networkinfo').read() if "Warning" in network_info or "Error" in network_info: success = 0 if success == 1: #remove the backup file os.system("sudo rm " + self.backupfile) else: Domoticz.Log("Trying to revert the config file...") copy2(self.backupfile, self.path + "/config.json") success = self.startProcess() #Update the ID if success: #update the network info Devices[uid_GSMinfo].Update(sValue=str(network_info), nValue=0)
def onStart(self): self.lastHeartbeatTime = 0 self.runCounter = 6 if Parameters["SerialPort"] == "1": Domoticz.Debugging(2 + 4 + 8 + 16 + 32) Domoticz.Log('Debug mode') logging.basicConfig( format= '%(asctime)s - %(levelname)-8s - %(filename)-18s - %(message)s', filename='bluvo.log', level=logging.DEBUG) DumpConfigToLog() else: Domoticz.Debugging(0) if Parameters["SerialPort"] == "2": logging.basicConfig( format= '%(asctime)s - %(levelname)-8s - %(filename)-18s - %(message)s', filename='bluvo.log', level=logging.INFO) elif Parameters["SerialPort"] == "3": logging.basicConfig( format= '%(asctime)s - %(levelname)-8s - %(filename)-18s - %(message)s', filename='bluvo.log', level=logging.WARNING) else: logging.basicConfig( format= '%(asctime)s - %(levelname)-8s - %(filename)-18s - %(message)s', filename='bluvo.log', level=logging.ERROR) logging.info('started plugin with Domoticz.Heartbeat = {0}'.format( Domoticz.Heartbeat())) ''' # add custom images CLOSED_ICON = "Closed" CHARGING_ICON = "Charging" AFSTAND_ICON = "Distance" # Dry Logo if self.CLOSED_ICON in Images: Domoticz.Debug("ID: " + str(Images[self.CLOSED_ICON].ID)) else: Domoticz.Image(CLOSED_ICON+".zip").Create() if self.CHARGING_ICON in Images:Domoticz.Debug("ID: " + str(Images[self.CHARGING_ICON].ID)) else: Domoticz.Image(CHARGING_ICON+".zip").Create() if self.AFSTAND_ICON in Images: Domoticz.Debug("ID: " + str(Images[self.AFSTAND_ICON].ID)) else: Domoticz.Image(AFSTAND_ICON+".zip").Create() ''' if "Maps icon" not in Images: Domoticz.Image("Maps icon.zip").Create() if (1 not in Devices): Domoticz.Device(Unit=1, Type=113, Subtype=0, Switchtype=3, Name="odometer").Create() if (2 not in Devices): Domoticz.Device(Unit=2, Type=243, Subtype=31, Switchtype=0, Name="range").Create() if (3 not in Devices): Domoticz.Device(Unit=3, Type=244, Subtype=73, Switchtype=0, Name="charging").Create() if (4 not in Devices): Domoticz.Device(Unit=4, TypeName="Percentage", Name="Battery percentage").Create() if (5 not in Devices): Domoticz.Device(Unit=5, TypeName="Percentage", Name="Battery 12v").Create() if (6 not in Devices): Domoticz.Device(Unit=6, Type=243, Subtype=31, Switchtype=0, Name="status 12v").Create() if (7 not in Devices): Domoticz.Device(Unit=7, Type=244, Subtype=73, Switchtype=11, Name="tailgate").Create() if (8 not in Devices): Domoticz.Device(Unit=8, Type=243, Subtype=19, Image=Images["Maps icon"].ID, Name="distance from home: 0").Create() Devices[8].Update(nValue=0, sValue="Location update needed") if (9 not in Devices): Domoticz.Device(Unit=9, Type=244, Subtype=73, Switchtype=0, Name="force status update").Create() if (10 not in Devices): Domoticz.Device(Unit=10, Type=244, Subtype=73, Switchtype=19, Name="doors").Create() if (11 not in Devices): Domoticz.Device(Unit=11, Type=242, Subtype=1, Name="airco: off").Create() if (12 not in Devices): Domoticz.Device(Unit=12, Type=244, Subtype=73, Switchtype=11, Name="hood").Create() if (13 not in Devices): Domoticz.Device(Unit=13, Type=243, Subtype=31, Name="current speed").Create() if (14 not in Devices): Domoticz.Device(Unit=14, Type=243, Subtype=31, Name="Remaining charge time", Options={ 'Custom': '1;hrs' }).Create() Domoticz.Log("Devices created.") p_email = Parameters["Username"] p_password = Parameters["Password"] p_pin = Parameters["Port"] pin = ('0000' + (str(p_pin) if isinstance(p_pin, int) else p_pin))[-4:] p_vin = Parameters["Mode6"] p_abrp_token = Parameters["Mode1"] p_abrp_carmodel = Parameters["Mode2"] # TODO see what weather API is running and get the data .. p_WeatherApiKey = Parameters["Mode4"] p_WeatherProvider = Parameters["Mode5"] p_homelocation = Settings["Location"] if p_homelocation is None: Domoticz.Log("Unable to parse coordinates") p_homelocation = "52.0930241;4.3423724,17" return False intervals = Parameters["Mode3"] for delim in ',;:': intervals = intervals.replace(delim, ' ') intervals = intervals.split(" ") self.p_forcepollinterval = float(intervals[0]) self.p_charginginterval = float(intervals[1]) self.heartbeatinterval = float(intervals[2]) if self.heartbeatinterval == "": self.heartbeatinterval = float(120) else: self.heartbeatinterval = float(self.heartbeatinterval) * 60 self.bluelink = BlueLink(p_email, p_password, p_pin, p_vin, p_abrp_carmodel, p_abrp_token, p_WeatherApiKey, p_WeatherProvider, p_homelocation) self.bluelink.initialise(self.p_forcepollinterval, self.p_charginginterval) if self.bluelink.initSuccess: Domoticz.Heartbeat(15) else: Domoticz.Log("Initialisation failed") return False return True
def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == 'Debug': self.debug = True Domoticz.Debugging(1) DumpConfigToLog() else: Domoticz.Debugging(0) Domoticz.Heartbeat(20) self.pollinterval = int(Parameters["Mode3"]) * 60 if self.iconName not in Images: Domoticz.Image('icons.zip').Create() iconID = Images[self.iconName].ID self.variables = { self.UNIT_AIR_QUALITY_INDEX: { "Name": _("Air Quality Index"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "CAQI" }, "Image": iconID, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_PM1: { "Name": _("PM1"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "µg/m³" }, "Image": iconID, "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_PM25: { "Name": _("PM2,5"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "µg/m³" }, "Image": iconID, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_PM10: { "Name": _("PM10"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "µg/m³" }, "Image": iconID, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_NO2: { "Name": _("NO₂"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "µg/m³" }, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_O3: { "Name": _("O₃"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "µg/m³" }, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_SO2: { "Name": _("SO₂"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "µg/m³" }, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_CO: { "Name": _("CO"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "µg/m³" }, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AIR_POLLUTION_LEVEL: { "Name": _("Air pollution Level"), "TypeName": "Alert", "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AIR_POLLUTION_ADVICE: { "Name": _("Advice"), "TypeName": "Alert", "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_TEMPERATURE: { "Name": _("Temperature"), "TypeName": "Temperature", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_BAROMETER: { "Name": _("Air pressure"), "TypeName": "Barometer", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_HUMIDITY: { "Name": _("Humidity"), "TypeName": "Humidity", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_STATION_LOCATION: { "Name": _("Sensor information"), "TypeName": "Text", "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_PM25_PERCENTAGE: { "Name": _("PM2,5 Norm"), "TypeName": "Percentage", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_PM10_PERCENTAGE: { "Name": _("PM10 Norm"), "TypeName": "Percentage", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_NO2_PERCENTAGE: { "Name": _("NO₂ Norm"), "TypeName": "Percentage", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_O3_PERCENTAGE: { "Name": _("O₃ Norm"), "TypeName": "Percentage", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_SO2_PERCENTAGE: { "Name": _("SO₂ Norm"), "TypeName": "Percentage", "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_CO_PERCENTAGE: { "Name": _("CO Norm"), "TypeName": "Percentage", "Used": 1, "nValue": 0, "sValue": None, }, } self.onHeartbeat(fetch=True)
def onStart(self): if Parameters['Mode4'] == 'Debug': Domoticz.Debugging(1) DumpConfigToLog() self.heartBeatCnt = 0 self.subHost, self.subPort = Parameters['Mode6'].split(':') self.tcpConn = Domoticz.Connection(Name='MIIOServer', Transport='TCP/IP', Protocol='None', Address=self.subHost, Port=self.subPort) if self.iconName not in Images: Domoticz.Image('icons.zip').Create() iconID = Images[self.iconName].ID if self.statusUnit not in Devices: Domoticz.Device(Name='Status', Unit=self.statusUnit, Type=17, Switchtype=17, Image=iconID).Create() if self.controlUnit not in Devices: Domoticz.Device(Name='Control', Unit=self.controlUnit, TypeName='Selector Switch', Image=iconID, Options=self.controlOptions).Create() if self.fanDimmerUnit not in Devices and Parameters[ 'Mode5'] == 'dimmer': Domoticz.Device(Name='Fan Level', Unit=self.fanDimmerUnit, Type=244, Subtype=73, Switchtype=7, Image=iconID).Create() elif self.fanSelectorUnit not in Devices and Parameters[ 'Mode5'] == 'selector': Domoticz.Device(Name='Fan Level', Unit=self.fanSelectorUnit, TypeName='Selector Switch', Image=iconID, Options=self.fanOptions).Create() if self.batteryUnit not in Devices: Domoticz.Device(Name='Battery', Unit=self.batteryUnit, TypeName='Custom', Image=iconID, Options=self.customSensorOptions).Create() if self.cMainBrushUnit not in Devices: Domoticz.Device(Name='Care Main Brush', Unit=self.cMainBrushUnit, TypeName='Custom', Image=iconID, Options=self.customSensorOptions).Create() if self.cSideBrushUnit not in Devices: Domoticz.Device(Name='Care Side Brush', Unit=self.cSideBrushUnit, TypeName='Custom', Image=iconID, Options=self.customSensorOptions).Create() if self.cSensorsUnit not in Devices: Domoticz.Device(Name='Care Sensors ', Unit=self.cSensorsUnit, TypeName='Custom', Image=iconID, Options=self.customSensorOptions).Create() if self.cFilterUnit not in Devices: Domoticz.Device(Name='Care Filter', Unit=self.cFilterUnit, TypeName='Custom', Image=iconID, Options=self.customSensorOptions).Create() if self.cResetControlUnit not in Devices: Domoticz.Device(Name='Care Reset Control', Unit=self.cResetControlUnit, TypeName='Selector Switch', Image=iconID, Options=self.careOptions).Create() Domoticz.Heartbeat(int(Parameters['Mode2']))
def onStart(): global numberDev, nbUpdate if Parameters["Mode6"] == "Debug": Domoticz.Debugging(1) if (len(Devices) == 0): if Parameters["Address"] == '127.0.0.1' and Parameters[ "Mode1"] == '000000000000': Domoticz.Device(Name="Discover", Unit=1, Type=17, Image=2, Switchtype=17, Used=1).Create() if (1 not in Devices): Options = { "LevelActions": "||||", "LevelNames": "Off|Learn|Test|Save|Reset", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Command", Unit=1, TypeName="Selector Switch", Switchtype=18, Image=12, Options=Options, Used=1).Create() if (2 not in Devices and Parameters["Mode3"] == 'yes'): Domoticz.Device(Name="Temp", Unit=2, TypeName="Temperature", Used=1).Create() if (254 not in Devices): Domoticz.Device(Name="Remote", Unit=254, Type=17, Image=2, Switchtype=17, Used=1).Create() if (255 not in Devices and Parameters["Mode4"] == 'yes'): Options = { "LevelActions": "||||", "LevelNames": "Off|WebStart|Generate|Import|Clear", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Import", Unit=255, TypeName="Selector Switch", Switchtype=18, Image=12, Options=Options, Used=1).Create() DumpConfigToLog() Domoticz.Heartbeat(30) numberDev = len(Devices) - 1 if (255 in Devices): UpdateDevice(255, 0, 'Off') numberDev = numberDev - 1 Domoticz.Log("Connecting to: " + Parameters["Address"] + ":" + Parameters["Mode1"]) broadlinkConnect() UpdateDevice(1, 0, 'Off') if not os.path.exists(Parameters["Mode2"] + "/import"): os.makedirs(Parameters["Mode2"] + "/import") if not os.path.exists(Parameters["Mode2"] + "/remote"): os.makedirs(Parameters["Mode2"] + "/remote") Domoticz.Log("Device Number begin to : " + str(numberDev)) genRemote() return True
def onStart(self): device_ip = Parameters["Address"] device_id = Parameters["Mode3"] device_port = Parameters["Mode4"] client = midea_device(device_ip, int(device_id), int(device_port)) device = client.setup() # get AC info device.refresh() if Parameters["Mode2"] == "Debug": Domoticz.Debugging(1) DumpConfigToLog() if len(Devices) == 0: Domoticz.Device(Name="Power", Unit=1, Image=9, TypeName="Switch", Used=1).Create() Domoticz.Device(Name="Temp Inside", Unit=2, TypeName="Temperature", Used=1).Create() Domoticz.Device(Name="Temp Outside", Unit=3, TypeName="Temperature", Used=1).Create() Domoticz.Device(Name="Setpoint", Unit=4, Type=242, Subtype=1, Image=16, Used=1).Create() Options = { "LevelActions": "||||||", "LevelNames": "|Auto|Heat|Cool|Dry|Fan", "LevelOffHidden": "true", "SelectorStyle": "1" } Domoticz.Device(Name="Mode", Unit=5, TypeName="Selector Switch", Image=16, Options=Options, Used=1).Create() Options = { "LevelActions": "|||||", "LevelNames": "|High|Medium|Low|Auto", "LevelOffHidden": "true", "SelectorStyle": "1" } Domoticz.Device(Name="Fan Rate", Unit=6, TypeName="Selector Switch", Image=7, Options=Options, Used=1).Create() Options = { "LevelActions": "|||", "LevelNames": "Off|Vertical|Horizontal|Both", "LevelOffHidden": "false", "SelectorStyle": "1" } Domoticz.Device(Name="Swing", Unit=7, TypeName="Selector Switch", Image=7, Options=Options, Used=1).Create() Domoticz.Device(Name="Turbo", Unit=8, Image=9, TypeName="Switch", Used=1).Create() Domoticz.Device(Name="Eco", Unit=9, Image=9, TypeName="Switch", Used=1).Create() Domoticz.Debug("Qlima Wifi Airco device created.") DumpConfigToLog() Domoticz.Heartbeat(10) self.DataUpdate()
def onStart(self): Domoticz.Status("onStart called - Zigate plugin V 3.0.4") if Parameters["Mode6"] != "0": Domoticz.Debugging(int(Parameters["Mode6"])) DumpConfigToLog() if Parameters["Mode1"] == "USB": z_var.transport = "USB" z_var.ZigateConn = Domoticz.Connection( Name="ZiGate", Transport="Serial", Protocol="None", Address=Parameters["SerialPort"], Baud=115200) z_var.ZigateConn.Connect() if Parameters["Mode1"] == "Wifi": z_var.transport = "Wifi" z_var.ZigateConn = Domoticz.Connection( Name="Zigate", Transport="TCP/IP", Protocol="None ", Address=Parameters["Address"], Port=Parameters["Port"]) z_var.ZigateConn.Connect() # CLD CLD # Import PluginConf.txt tmpPluginConf = "" with open(Parameters["HomeFolder"] + "PluginConf.txt", 'r') as myPluginConfFile: tmpPluginConf += myPluginConfFile.read().replace('\n', '') myPluginConfFile.close() Domoticz.Debug("PluginConf.txt = " + str(tmpPluginConf)) self.PluginConf = eval(tmpPluginConf) z_var.CrcCheck = 1 if self.PluginConf['CrcCheck'] == "False" or self.PluginConf[ 'CrcCheck'] == "Off": z_var.CrcCheck = 0 z_var.ReqRcv = bytearray() for x in Devices: # initialise listeofdevices avec les devices en bases domoticz ID = Devices[x].DeviceID self.ListOfDevices[ID] = {} try: self.ListOfDevices[ID] = eval(Devices[x].Options['Zigate']) except: Domoticz.Error("Error loading Device " + str(Devices[x]) + " not loaded int Zigate Plugin!") else: Domoticz.Log("Device : [" + str(x) + "] ID = " + ID + " Options['Zigate'] = " + Devices[x].Options['Zigate'] + " loaded into self.ListOfDevices") #Import DeviceConf.txt tmpread = "" with open(Parameters["HomeFolder"] + "DeviceConf.txt", 'r') as myfile: tmpread += myfile.read().replace('\n', '') myfile.close() Domoticz.Debug("DeviceConf.txt = " + str(tmpread)) self.DeviceConf = eval(tmpread) #Import DeviceList.txt with open(Parameters["HomeFolder"] + "DeviceList.txt", 'r') as myfile2: Domoticz.Debug("DeviceList.txt open ") for line in myfile2: (key, val) = line.split(":", 1) key = key.replace(" ", "") key = key.replace("'", "") z_tools.CheckDeviceList(self, key, val) return
def onStart(self): # setup the appropriate logging level try: debuglevel = int(Parameters["Mode6"]) except ValueError: debuglevel = 0 self.loglevel = Parameters["Mode6"] if debuglevel != 0: self.debug = True Domoticz.Debugging(debuglevel) DumpConfigToLog() self.loglevel = "Verbose" else: self.debug = False Domoticz.Debugging(0) # create the child devices if these do not exist yet devicecreated = [] if 1 not in Devices: Options = { "LevelActions": "||", "LevelNames": "Off|Auto", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Control", Unit=1, TypeName="Selector Switch", Switchtype=18, Image=15, Options=Options, Used=1).Create() devicecreated.append(deviceparam(1, 0, "0")) # default is Off state if 2 not in Devices: Domoticz.Device(Name="General heating request", Unit=2, TypeName="Switch", Image=9, Used=1).Create() devicecreated.append(deviceparam(2, 0, "")) # default is Off # if any device has been created in onStart(), now is time to update its defaults for device in devicecreated: Devices[device.unit].Update(nValue=device.nvalue, sValue=device.svalue) # build lists of sensors and switches self.Heatingrequester = parseCSV(Parameters["Mode1"]) Domoticz.Debug("Heating requester = {}".format(self.Heatingrequester)) self.Heaters = parseCSV(Parameters["Mode2"]) Domoticz.Debug("Heaters = {}".format(self.Heaters)) # splits additional parameters params = parseCSV(Parameters["Mode5"]) if len(params) == 2: self.ondelay = CheckParam("On Delay", params[0], 10) if self.ondelay < 5: Domoticz.Error( "Invalid on delay parameter. Using minimum of 5 minutes !") self.ondelay = 5 self.orderconfirm = CheckParam("order confirmation Delay", params[1], 60) if self.orderconfirm < 15: Domoticz.Error( "Invalid forced order confirmation parameter. Using minimum of 15 minutes !" ) self.orderconfirm = 15 else: Domoticz.Error("Error reading Mode5 parameters") # if mode = off then make sure actual heating is off just in case if was manually set to on if Devices[1].sValue == "0": self.SwitchHeat(False)
def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == 'Debug': self.debug = True Domoticz.Debugging(1) DumpConfigToLog() else: Domoticz.Debugging(0) Domoticz.Log("Domoticz Node Name is:" + platform.node()) Domoticz.Log("Domoticz Platform System is:" + platform.system()) Domoticz.Debug("Domoticz Platform Release is:" + platform.release()) Domoticz.Debug("Domoticz Platform Version is:" + platform.version()) Domoticz.Log("Default Python Version is:" + str(sys.version_info[0]) + "." + str(sys.version_info[1]) + "." + str(sys.version_info[2]) + ".") if platform.system() == "Windows": Domoticz.Error("Windows Platform NOT YET SUPPORTED!!") return pluginText = "" pluginAuthor = "" pluginRepository = "" pluginKey = "" pluginKey = Parameters["Mode2"] pluginAuthor = self.plugindata[pluginKey][0] pluginRepository = self.plugindata[pluginKey][1] pluginText = self.plugindata[pluginKey][2] pluginBranch = self.plugindata[pluginKey][3] # GitHub branch to clone if (Parameters["Mode5"] == 'True'): Domoticz.Log("Plugin Security Scan is enabled") # Reading secpoluserFile and populating array of values secpoluserFile = str( os.getcwd()) + "/plugins/PP-MANAGER/secpoluser.txt" Domoticz.Debug("Checking for SecPolUser file on:" + secpoluserFile) if (os.path.isfile(secpoluserFile) == True): Domoticz.Log("secpoluser file found. Processing!!!") # Open the file secpoluserFileHandle = open(secpoluserFile) # use readline() to read the first line line = secpoluserFileHandle.readline() while line: if mid(line, 0, 4) == "--->": secpoluserSection = mid(line, 4, len(line)) Domoticz.Log("secpoluser settings found for plugin:" + secpoluserSection) if ((mid(line, 0, 4) != "--->") and (line.strip() != "") and (line.strip() != " ")): Domoticz.Debug("SecPolUserList exception (" + secpoluserSection.strip() + "):'" + line.strip() + "'") #SecPolUserList.append(line.strip()) #SecPolUserList[secpoluserSection].append(line.strip()) if secpoluserSection.strip( ) not in self.SecPolUserList: self.SecPolUserList[secpoluserSection.strip()] = [] self.SecPolUserList[secpoluserSection.strip()].append( line.strip()) # use realine() to read next line line = secpoluserFileHandle.readline() secpoluserFileHandle.close() Domoticz.Log("SecPolUserList exception:" + str(self.SecPolUserList)) else: self.SecPolUserList = {"Global": []} i = 0 path = str(os.getcwd()) + "/plugins/" for (path, dirs, files) in os.walk(path): for dir in dirs: if str(dir) != "": #self.UpdatePythonPlugin(pluginAuthor, pluginRepository, str(dir)) #parseFileForSecurityIssues(str(os.getcwd()) + "/plugins/PP-MANAGER/plugin.py") if (os.path.isfile( str(os.getcwd()) + "/plugins/" + str(dir) + "/plugin.py") == True): self.parseFileForSecurityIssues( str(os.getcwd()) + "/plugins/" + str(dir) + "/plugin.py", str(dir)) i += 1 if i >= 1: break # Reading exception file and populating array of values exceptionFile = str(os.getcwd()) + "/plugins/PP-MANAGER/exceptions.txt" Domoticz.Debug("Checking for Exception file on:" + exceptionFile) if (os.path.isfile(exceptionFile) == True): Domoticz.Log("Exception file found. Processing!!!") # Open the file f = open(exceptionFile) # use readline() to read the first line line = f.readline() while line: if ((line[:1].strip() != "#") and (line[:1].strip() != " ") and (line[:1].strip() != "")): Domoticz.Log("File ReadLine result:'" + line.strip() + "'") self.ExceptionList.append(line.strip()) # use realine() to read next line line = f.readline() f.close() Domoticz.Debug("self.ExceptionList:" + str(self.ExceptionList)) if Parameters["Mode4"] == 'All': Domoticz.Log("Updating All Plugins!!!") i = 0 path = str(os.getcwd()) + "/plugins/" for (path, dirs, files) in os.walk(path): for dir in dirs: if str(dir) != "": if str(dir) in self.plugindata: self.UpdatePythonPlugin(pluginAuthor, pluginRepository, str(dir)) elif str(dir) == "PP-MANAGER": Domoticz.Debug( "PP-Manager Folder found. Skipping!!") else: Domoticz.Log( "Plugin:" + str(dir) + " cannot be managed with PP-Manager!!.") i += 1 if i >= 1: break if Parameters["Mode4"] == 'AllNotify': Domoticz.Log("Collecting Updates for All Plugins!!!") i = 0 path = str(os.getcwd()) + "/plugins/" for (path, dirs, files) in os.walk(path): for dir in dirs: if str(dir) != "": if str(dir) in self.plugindata: self.CheckForUpdatePythonPlugin( pluginAuthor, pluginRepository, str(dir)) elif str(dir) == "PP-MANAGER": Domoticz.Debug( "PP-Manager Folder found. Skipping!!") else: Domoticz.Log( "Plugin:" + str(dir) + " cannot be managed with PP-Manager!!.") i += 1 if i >= 1: break if (Parameters["Mode4"] == 'SelectedNotify'): Domoticz.Log("Collecting Updates for Plugin:" + pluginKey) self.CheckForUpdatePythonPlugin(pluginAuthor, pluginRepository, pluginKey) if pluginKey == "Idle": Domoticz.Log("Plugin Idle") Domoticz.Heartbeat(60) else: Domoticz.Debug("Checking for dir:" + str(os.getcwd()) + "/plugins/" + pluginKey) #If plugin Directory exists if (os.path.isdir(str(os.getcwd()) + "/plugins/" + pluginKey)) == True: Domoticz.Debug("Folder for Plugin:" + pluginKey + " already exists!!!") #Domoticz.Debug("Set 'Python Plugin Manager'/ 'Domoticz plugin' attribute to 'idle' in order t.") if Parameters["Mode4"] == 'Selected': Domoticz.Debug("Updating Enabled for Plugin:" + pluginText + ".Checking For Update!!!") self.UpdatePythonPlugin(pluginAuthor, pluginRepository, pluginKey) Domoticz.Heartbeat(60) else: Domoticz.Log("Installation requested for Plugin:" + pluginText) Domoticz.Debug("Installation URL is:" + "https://github.com/" + pluginAuthor + "/" + pluginRepository) Domoticz.Debug("Current Working dir is:" + str(os.getcwd())) if pluginKey in self.plugindata: Domoticz.Log("Plugin Display Name:" + pluginText) Domoticz.Log("Plugin Author:" + pluginAuthor) Domoticz.Log("Plugin Repository:" + pluginRepository) Domoticz.Log("Plugin Key:" + pluginKey) Domoticz.Log("Plugin Branch:" + pluginBranch) self.InstallPythonPlugin(pluginAuthor, pluginRepository, pluginKey, pluginBranch) Domoticz.Heartbeat(60)
def onStart(self): # Debug mode Domoticz.Debugging(int(Parameters["Mode6"])) Domoticz.Debug("onStart called") #get parameters self.__address = Parameters["Address"] self.__devID = Parameters["Mode1"] self.__localKey = Parameters["Mode2"] self.__ampere, self.__watt, self.__voltage = Parameters["Mode5"].split(";") #set the next heartbeat self.__runAgain = self.__HB_BASE_FREQ #build internal maps (__unit2dps_id_list and __plugs) self.__unit2dps_id_list = {} self.__plugs = {} max_unit = 0 max_dps = 0 for val in sorted(Parameters["Mode3"].split(";")): self.__unit2dps_id_list[int(val)]=[int(val),] self.__plugs[int(val)]=Plug(int(val)) if(int(val)>max_unit): max_unit=int(val) max_dps = max_unit #groups management: #syntax: 1;2 : 3;4 # +5 instead of +1 to have spare room for the extra devices for Amp, W, kWh max_unit = max_unit + 5 if(Parameters["Mode4"]!="None"): groups = Parameters["Mode4"].split(":") for group in groups: self.__unit2dps_id_list[max_unit]=[] for val in sorted(group.split(";")): self.__unit2dps_id_list[max_unit].append(int(val)) max_unit = max_unit + 1 #create domoticz devices if(len(Devices) == 0): for val in self.__unit2dps_id_list: if(val <= max_dps): #single socket dps Domoticz.Device(Name="Tuya SmartPlug (Switch)", Unit=val, TypeName="Switch").Create() Domoticz.Log("Tuya SmartPlug Device (Switch) #" + str(val) +" created.") ## After the last DPS add the global devices if(val == max_dps): Domoticz.Device(Name="Tuya SmartPlug (A)" , Unit=val+1, TypeName="Current (Single)").Create() Domoticz.Log("Tuya SmartPlug Device (A) #" + str(val+1) +" created.") Domoticz.Device(Name="Tuya SmartPlug (kWh)", Unit=val+2, TypeName="kWh").Create() Domoticz.Log("Tuya SmartPlug Device kWh #" + str(val+2) +" created.") Domoticz.Device(Name="Tuya SmartPlug (V)", Unit=val+3, TypeName="Voltage").Create() Domoticz.Log("Tuya SmartPlug Device (V) #" + str(val+3) +" created.") Domoticz.Device(Name="Tuya SmartPlug (W)", Unit=val+4, TypeName="Usage").Create() Domoticz.Log("Tuya SmartPlug Device (W) #" + str(val+4) +" created.") else: #group: selector switch Options = {"LevelActions": "|", "LevelNames": "Off|On", "LevelOffHidden": "false", "SelectorStyle": "0"} Domoticz.Device(Name="Tuya SmartPlug #" + str(val), Unit=val, TypeName="Selector Switch", Options=Options).Create() Domoticz.Log("Tuya SmartPlug Device #" + str(val) +" created.") #manage always on #if(Parameters["Mode5"]!="None"): # for val in sorted(Parameters["Mode5"].split(";")): # self.__plugs[int(val)].set_alwaysON() #create the pytuya object self.__device = pytuya.OutletDevice(self.__devID, self.__address, self.__localKey) #state machine self.__state_machine = 0 #start the connection self.__connection = Domoticz.Connection(Name="Tuya", Transport="TCP/IP", Address=self.__address, Port="6668") self.__connection.Connect()
def onStop(self): Domoticz.Debug("onStop called") Domoticz.Log("Plugin is stopping.") self.UpdatePythonPlugin("ycahome", "pp-manager", "PP-MANAGER") Domoticz.Debugging(0)
def onStart(self): self.counter = 0 self.Color = {} self.Level = 100 global ipaddress global updateInterval if Parameters["Mode6"] != "0": Domoticz.Debugging(int(Parameters["Mode6"])) DumpConfigToLog() ipaddress = Parameters["Address"].strip() updateInterval = int(Parameters["Mode1"].strip()) self.UDPConn = Domoticz.Connection(Name="UDPConn", Transport="UDP/IP", Address=ipaddress, Port=str(Parameters["Port"])) self.UDPConn.Listen() if (len(Devices) == 0): Domoticz.Log("creating devices") Options = { "LevelActions": "", "LevelNames": "Loading...", "LevelOffHidden": "true", "SelectorStyle": "1" } Domoticz.Device(Name="Palettes", Unit=1, TypeName="Selector Switch", Options=Options, Image=0).Create() Domoticz.Device(Name="Effects", Unit=2, TypeName="Selector Switch", Options=Options).Create() Domoticz.Device(Name="Color & Brightness", Unit=3, Type=241, Subtype=2, Switchtype=7, Options=Options).Create() Domoticz.Device(Name="Presets", Unit=4, TypeName="Selector Switch", Options=Options).Create() Domoticz.Device(Name="FX Speed", Unit=5, Type=244, Subtype=62, Switchtype=7, Options=Options).Create() Domoticz.Device(Name="FX Intensity", Unit=6, Type=244, Subtype=62, Switchtype=7, Options=Options).Create() else: Domoticz.Log("devices existed already") UpdatePresetsInDomoticz() getWLEDJSON(self.JSONConn)
def onStart(self): try: self.logLevel = int(Parameters["Mode6"]) except: self.Log("Debuglevel '"+Parameters["Mode6"]+"' is not an integer", 1, 3) if self.logLevel == 10: Domoticz.Debugging(1) self.Log("onStart called", 9, 1) if (self.regexIp.match(Parameters["Address"] )): self.ip = Parameters["Address"] else: self.Log("'"+Parameters["Address"]+"' is not a valid IP address.", 1, 3 ) try: self.port = int(Parameters["Port"]) except Exception as e: self.Log("Port is not a number: "+ Parameters["Port"], 1, 3) try: self.maxQueued = int(Parameters["Mode3"]) except Exception as e: self.Log("'"+Parameters["Mode3"]+"' is not a number.", 1, 3 ) try: Domoticz.Heartbeat(int(Parameters["Mode2"])) except: pass self.key = Parameters["Mode4"] dictValue = 0 sourceOptions = {} for item in Parameters["Mode1"].split('|'): # parse into type, since we cannot read all specific types... if item == "off": self.srcOff = dictValue self.selectorMap[dictValue] = "power_off" elif item == "tv": self.srcTv = dictValue self.selectorMap[dictValue] = "tv_radio" elif item == "radio": self.srcRadio = dictValue self.selectorMap[dictValue] = "tv_radio" elif item == "hdmi1" or item == "hdmi2" or item == "hdmi3" or item == "hdmi4": self.srcHdmi.append(dictValue) self.selectorMap[dictValue] = item elif item == "av1" or item == "av2" or item == "av3" or item == "usb" or item == "usb": self.srcAv.append(dictValue) self.selectorMap[dictValue] = item else: self.Log("Unknown source type '"+str(item)+"' with value "+str(dictValue), Level = 2, Type = 3) self.selectorMap[dictValue] = item dictValue = dictValue + 10 srcLastLive = self.srcTv if (Parameters["Mode1"].count('|') != Parameters["Mode5"].count('|')): self.Log("Sources ("+Parameters["Mode1"]+") and names ("+Parameters["Mode5"]+") do not match! Using only sources", 1, 3) sourceOptions = {'LevelActions': '|'*Parameters["Mode1"].count('|'), 'LevelNames': Parameters["Mode1"], 'LevelOffHidden': 'false', 'SelectorStyle': '0'} # 1 = combobox, 0 = buttons else: sourceOptions = {'LevelActions': '|'*Parameters["Mode5"].count('|'), 'LevelNames': Parameters["Mode5"], 'LevelOffHidden': 'false', 'SelectorStyle': '0'} #ICONS if ("LGtvchanneldown" not in Images): Domoticz.Image('LGtvchanneldown.zip').Create() if ("LGtvchannelup" not in Images): Domoticz.Image('LGtvchannelup.zip').Create() if ("LGtvexit" not in Images): Domoticz.Image('LGtvexit.zip').Create() if ("LGtvvolmin" not in Images): Domoticz.Image('LGtvvolmin.zip').Create() if ("LGtvvolplus" not in Images): Domoticz.Image('LGtvvolplus.zip').Create() if ("LGtvok" not in Images): Domoticz.Image('LGtvok.zip').Create() if ("LGtvmute" not in Images): Domoticz.Image('LGtvmute.zip').Create() # create buttons if (1 not in Devices): Domoticz.Device(Name="Source", Unit=1, TypeName="Selector Switch", Switchtype=18, Image=2, Options=sourceOptions).Create() elif (Devices[1].Options != sourceOptions): self.Log("Sources or names have changed.", Level = 2, Type = 1) # update does not work, so delte it and readd it. Devices[1].Delete() Domoticz.Device(Name="Source", Unit=1, TypeName="Selector Switch", Switchtype=18, Image=2, Used=1, Options=sourceOptions).Create() if (2 not in Devices): Domoticz.Device(Name="Volume up", Unit=2, TypeName="Switch", Image=Images["LGtvvolplus"].ID).Create() if (3 not in Devices): Domoticz.Device(Name="Volume down", Unit=3, TypeName="Switch", Image=Images["LGtvvolmin"].ID).Create() if (4 not in Devices): Domoticz.Device(Name="Channel up", Unit=4, TypeName="Switch", Image=Images["LGtvchannelup"].ID).Create() if (5 not in Devices): Domoticz.Device(Name="Channel down", Unit=5, TypeName="Switch", Image=Images["LGtvchanneldown"].ID).Create() if (8 not in Devices): Domoticz.Device(Name="Mute", Unit=8, TypeName="Switch", Image=Images["LGtvmute"].ID).Create() else: self.UpdateDevice(8,0,"Off") if (9 not in Devices): Domoticz.Device(Name="Exit", Unit=9, TypeName="Switch", Image=Images["LGtvexit"].ID).Create() if (11 not in Devices): Domoticz.Device(Name="Channel", Unit=11, Type=243, Subtype=19, Switchtype=0).Create() else: self.UpdateDevice(11,0,"Off") self.lastConnected = False self.DumpConfigToLog() return
def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == "Debug": Domoticz.Debugging(1) else: Domoticz.Debugging(0) # Images # Check if images are in database if "xfr_windcentrale" not in Images: Domoticz.Image("xfr_windcentrale.zip").Create() image = Images["xfr_windcentrale"].ID Domoticz.Debug("Image created. ID: " + str(image)) # Validation of parameters # Check the selected Windmill Domoticz.Debug("Adress: " + Parameters["Address"]) try: windmill = self.__WINDMILLS[Parameters["Address"]] self.__id = windmill[0] self.__max_winddelen = windmill[1] except: Domoticz.Debug( "Invalid windmill selected") # Should not be possible! self.__id = -1 self.__max_winddelen = -1 # Check the number of winddelen Domoticz.Debug("Mode1: " + Parameters["Mode1"]) try: self.__number_winddelen = int(Parameters["Mode1"]) if self.__number_winddelen < 0 or self.__number_winddelen > self.__max_winddelen: self.__number_winddelen = -1 except: Domoticz.Debug("Invalid number of winddelen entered") self.__number_winddelen = -1 Domoticz.Debug("id: " + str(self.__id)) Domoticz.Debug("max winddelen: " + str(self.__max_winddelen)) Domoticz.Debug("number winddelen: " + str(self.__number_winddelen)) # Create devices if len(Devices) == 0: Domoticz.Device(Unit=self.__UNIT_POWERWND, Name="Power (" + str(self.__number_winddelen) + ")", TypeName="Custom", Options={ "Custom": "1;Watt" }, Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_POWERTOT, Name="Power (total)", TypeName="Custom", Options={ "Custom": "1;kW" }, Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_POWERREL, Name="Relative", TypeName="Custom", Options={ "Custom": "1;%" }, Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_WINDSPEED, Name="Wind speed", TypeName="Custom", Options={ "Custom": "0.0;bft" }, Image=image, Used=1).Create() # Domoticz.Device( Unit=self.__UNIT_WINDDIRECTION, Name="Wind direction", TypeName="Wind", Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_RPM, Name="RPM", TypeName="Custom", Options={ "Custom": "1;rpm" }, Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_OPERATIONAL, Name="Operational time", TypeName="Custom", Options={ "Custom": "1;%" }, Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_KWHWND, Name="Energy (" + str(self.__number_winddelen) + ")", TypeName="Custom", Options={ "Custom": "1;kWh" }, Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_KWHTOT, Name="Energy (total)", TypeName="Custom", Options={ "Custom": "1;MWh" }, Image=image, Used=1).Create() Domoticz.Device(Unit=self.__UNIT_HOURSYEAR, Name="Hours", TypeName="Custom", Image=image, Used=1).Create() DumpConfigToLog() Domoticz.Debug("self.__API_ADDRESS: " + self.__API_ADDRESS) self.__httpcon = Domoticz.Connection(Name="Windcentrale", Transport="TCP/IP", Protocol="HTTPS", Address=self.__API_ADDRESS, Port="443") self.__httpcon.Connect()
def onStart(self): #Domoticz.Log("path: " + str(sys.path)) Domoticz.Debug("onStart called") if Parameters["Mode6"] == 'Debug': self.debug = True Domoticz.Debugging(1) DumpConfigToLog() else: Domoticz.Debugging(0) self.connectIfNeeded() self.MyAir._timeout = 1 self.messageThread.start() Domoticz.Heartbeat(20) self.pollinterval = int(Parameters["Mode3"]) * 60 res = self.MyAir.status() Domoticz.Log(str(res)) self.variables = { self.FILTER_LIFE_REMAINING: { "Name": _("Filter life remaining"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "%" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.FILTER_WORK_HOURS: { "Name": _("Filter work hours"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "h" }, "Image": 7, "Used": 0, "nValue": 0, "sValue": 0, }, self.UNIT_AIR_QUALITY_INDEX: { "Name": _("Air Quality Index"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "AQI" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AVARAGE_AQI: { "Name": _("Avarage Air Quality Index"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "AQI" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, }, self.UNIT_AIR_POLLUTION_LEVEL: { "Name": _("Air pollution Level"), "TypeName": "Alert", "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_TEMPERATURE: { "Name": _("Temperature"), "TypeName": "Temperature", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_HUMIDITY: { "Name": _("Humidity"), "TypeName": "Humidity", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_MOTOR_SPEED: { "Name": _("Fan Speed"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "RPM" }, "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_CHILD_LOCK: { "Name": _("Child Lock"), "TypeName": "Switch", "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_BEEP: { "Name": _("Beep"), "TypeName": "Switch", "Image": 7, "Used": 0, "nValue": 0, "sValue": None, }, } if res.illuminance is not None: self.variables.update({ self.UNIT_ILLUMINANCE_SENSOR: { "Name": _("Illuminance sensor"), "TypeName": "Custom", "Options": { "Custom": "1;%s" % "lux" }, "Image": 7, "Used": 1, "nValue": 0, "sValue": None, } }) if (self.UNIT_ILLUMINANCE_SENSOR in Devices): Domoticz.Log("Device UNIT_ILLUMINANCE_SENSOR with id " + str(self.UNIT_ILLUMINANCE_SENSOR) + " exist") else: Domoticz.Device(Name="Illuminance sensor", Unit=self.UNIT_ILLUMINANCE_SENSOR, Type=244, Subtype=73, Switchtype=7, Image=7).Create() # Create switches - if not exist if self.UNIT_POWER_CONTROL in Devices: Domoticz.Log("Device UNIT_POWER_CONTROL with id " + str(self.UNIT_POWER_CONTROL) + " exist") else: Domoticz.Device(Name="Power", Unit=self.UNIT_POWER_CONTROL, TypeName="Switch", Image=7).Create() if self.UNIT_CHILD_LOCK in Devices: Domoticz.Log("Device UNIT_CHILD_LOCK with id " + str(self.UNIT_CHILD_LOCK) + " exist") else: Domoticz.Device(Name="Child Lock", Unit=self.UNIT_CHILD_LOCK, TypeName="Switch", Image=7).Create() if self.UNIT_BEEP in Devices: Domoticz.Log("Device UNIT_BEEP with id " + str(self.UNIT_BEEP) + " exist") else: Domoticz.Device(Name="Beep", Unit=self.UNIT_BEEP, TypeName="Switch", Image=7).Create() if self.UNIT_MODE_CONTROL in Devices: Domoticz.Log("Device UNIT_MODE_CONTROL with id " + str(self.UNIT_MODE_CONTROL) + " exist") else: Options = { "LevelActions": "||||", "LevelNames": "Idle|Silent|Favorite|Auto", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Mode", Unit=self.UNIT_MODE_CONTROL, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() if self.UNIT_MOTOR_SPEED_FAVORITE in Devices: Domoticz.Log("Device UNIT_MOTOR_SPEED_FAVORITE with id " + str(self.UNIT_MOTOR_SPEED_FAVORITE) + " exist") else: Options = { "LevelActions": "|||||||||||||||||", "LevelNames": "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Fan Favorite level", Unit=self.UNIT_MOTOR_SPEED_FAVORITE, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() if (self.UNIT_LED in Devices): Domoticz.Log("Device UNIT_LED with id " + str(self.UNIT_LED) + " exist") else: Domoticz.Device(Name="Fan LED", Unit=self.UNIT_LED, TypeName="Switch", Image=7).Create() self.onHeartbeat(fetch=False)
def onStop(self): Domoticz.Debug("onStop called") Domoticz.Debugging(0)
def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == 'Debug': self.debug = True Domoticz.Debugging(1) DumpConfigToLog() else: Domoticz.Debugging(0) Domoticz.Heartbeat(20) self.pollinterval = int(Parameters["Mode3"]) * 60 self.variables = { self.UNIT_TEMPERATURE: { "Name": _("Temperature"), "TypeName": "Temperature", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_HUMIDITY: { "Name": _("Humidity"), "TypeName": "Humidity", "Used": 0, "nValue": 0, "sValue": None, }, self.UNIT_TARGET_HUMIDITY: { "Name": _("Target Humidity"), "TypeName": "Humidity", "Used": 0, "nValue": 0, "sValue": None, } } #create switches if (len(Devices) == 0): Domoticz.Device(Name="Power", Unit=self.UNIT_POWER_CONTROL, TypeName="Switch", Image=7).Create() Options = { "LevelActions": "||||", "LevelNames": "Auto|Silent|Medium|High", "LevelOffHidden": "true", "SelectorStyle": "0" } Domoticz.Device(Name="Source", Unit=self.UNIT_MODE_CONTROL, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() HumidityTarget = { "LevelActions": "|||", "LevelNames": "50%|60%|70%", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Target", Unit=self.UNIT_TARGET_HUMIDITY, TypeName="Selector Switch", Switchtype=18, Image=7, Options=HumidityTarget).Create() Domoticz.Log("Devices created.") else: if (self.UNIT_POWER_CONTROL in Devices): Domoticz.Log("Device UNIT_MODE_CONTROL with id " + str(self.UNIT_POWER_CONTROL) + " exist") else: Domoticz.Device(Name="Power", Unit=self.UNIT_POWER_CONTROL, TypeName="Switch", Image=7).Create() if (self.UNIT_MODE_CONTROL in Devices): Domoticz.Log("Device UNIT_MODE_CONTROL with id " + str(self.UNIT_MODE_CONTROL) + " exist") else: Options = { "LevelActions": "||||", "LevelNames": "Auto|Silent|Medium|High", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Mode", Unit=self.UNIT_MODE_CONTROL, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create() if (self.UNIT_TARGET_HUMIDITY in Devices): Domoticz.Log("Device UNIT_TARGET_HUMIDITY with id " + str(self.UNIT_TARGET_HUMIDITY) + " exist") else: HumidityTarget = { "LevelActions": "|||", "LevelNames": "50%|60%|70%", "LevelOffHidden": "false", "SelectorStyle": "0" } Domoticz.Device(Name="Target", Unit=self.UNIT_TARGET_HUMIDITY, TypeName="Selector Switch", Switchtype=18, Image=7, Options=HumidityTarget).Create() self.onHeartbeat(fetch=False)
def onStart(self): #pylint: disable=undefined-variable global br, rf self.Error = False self.ShowMax = Parameters["Mode1"] if self.ShowMax == "" or self.ShowMax == "True": self.ShowMax = True if Parameters["Mode6"] != "Normal": Domoticz.Debugging(1) DumpConfigToLog() if CheckInternet() == False: self.Error = "You do not have a working internet connection." #Domoticz.Error(self.Error) # Get the location from the Settings if not "Location" in Settings: self.Error = "Location not set in Settings, please update your settings." Domoticz.Error(self.Error) if self.Error == False: # The location is stored in a string in the Settings loc = Settings["Location"].split(";") self.myLat = float(loc[0]) self.myLon = float(loc[1]) Domoticz.Debug("Coordinates from Domoticz: " + str(self.myLat) + ";" + str(self.myLon)) if self.myLat == None or self.myLon == None: Domoticz.Log("Unable to parse coordinates") return False # Get the interval specified by the user self.interval = int(Parameters["Mode2"]) if self.interval == None: Domoticz.Log( "Unable to parse interval, so set it to 10 minutes") self.interval = 10 # Buienradar only updates the info every 10 minutes. # Allowing values below 10 minutes will not get you more info if self.interval < 5: Domoticz.Log( "Interval too small, changed to 5 minutes because Buienradar only updates the info every 5 minutes" ) self.interval = 5 # Get the timeframe for the rain forecast self.timeframe = int(Parameters["Mode3"]) if self.timeframe == None: Domoticz.Log("Unable to parse timeframe, set to 30 minutes") self.timeframe = 30 if self.timeframe < 5 or self.timeframe > 120: Domoticz.Log( "Timeframe must be >=5 and <=120. Now set to 30 minutes") self.timeframe = 30 # Additional Sandolution # Get the forcast days, must lay between 0 and 5 self.forecastDays = int(Parameters["Username"]) br = Buienradar(self.myLat, self.myLon, self.interval, self.forecastDays) #Added forecast days rf = RainForecast(self.myLat, self.myLon, self.timeframe, self.ShowMax) # Check if devices need to be created createDevices() # Check if images are in database if 'BuienradarRainLogo' not in Images: Domoticz.Image('buienradar.zip').Create() if 'BuienradarLogo' not in Images: Domoticz.Image('buienradar-logo.zip').Create() # Get data from Buienradar br.getBuienradarXML() br.getNearbyWeatherStation() # Fill the devices with the Buienradar values fillDevices() Domoticz.Heartbeat(30)
def onStop(self): Domoticz.Debug("onStop called") Domoticz.Log("Theme is stopping.") #self.UpdatePythonPlugin("ycahome", "THEME-MANAGER", "THEME-MANAGER") Domoticz.Debugging(0)