예제 #1
0
 def onStart(self):
     global errmsg
     if errmsg == "":
         try:
             Domoticz.Heartbeat(10)
             self.debugging = Parameters["Mode6"]
             if self.debugging == "Verbose":
                 Domoticz.Debugging(2 + 4 + 8 + 16 + 64)
             if self.debugging == "Debug":
                 Domoticz.Debugging(2)
             self.base_topic = "shellies"  # hardwired
             self.mqttserveraddress = Parameters["Address"].strip()
             self.mqttserverport = Parameters["Port"].strip()
             self.mqttClient = MqttClientSH2(self.mqttserveraddress,
                                             self.mqttserverport, "",
                                             self.onMQTTConnected,
                                             self.onMQTTDisconnected,
                                             self.onMQTTPublish,
                                             self.onMQTTSubscribed)
         except Exception as e:
             Domoticz.Error("MQTT client start error: " + str(e))
             self.mqttClient = None
     else:
         Domoticz.Error(
             "Your Domoticz Python environment is not functional! " +
             errmsg)
         self.mqttClient = None
예제 #2
0
    def onStart(self):
        self.base_topic = Parameters['Mode2'].strip()
        self.otgw_topic = Parameters['Mode3'].strip()
        self.otgwserveraddress = Parameters['Mode1'].strip()
        self.mqttserveraddress = Parameters['Address'].strip()
        self.mqttserverport = Parameters['Port'].strip()

        self.mqttClient = MqttClientSH2(self.mqttserveraddress,
                                        self.mqttserverport, "",
                                        self.onMQTTConnected,
                                        self.onMQTTDisconnected,
                                        self.onMQTTPublish,
                                        self.onMQTTSubscribed)

        Domoticz.Debug("Started Heartbeat")
        Domoticz.Heartbeat(10)
예제 #3
0
    def onStart(self):
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)
        Domoticz.Log("onStart called")
        #MQTT if enabled
        if len(Parameters["Address"].split(',')) >= 2:
            import socket
            hostname = socket.gethostname().split('.')[0]
            self.base_topic = 'domoticz/slaves/' + hostname
            self.mqttserveraddress = Parameters["Address"].strip().split(
                ',')[1]
            self.mqttserverport = Parameters["Port"].strip()
            Domoticz.Status("MQTT Domoticz Remote enabled on:" +
                            self.base_topic + ", " + self.mqttserveraddress +
                            ":" + self.mqttserverport)
            self.mqttClient = MqttClientSH2(self.mqttserveraddress,
                                            self.mqttserverport, "",
                                            self.onMQTTConnected,
                                            self.onMQTTDisconnected,
                                            self.onMQTTPublish,
                                            self.onMQTTSubscribed)
            if len(
                    Parameters["Address"].split(',')
            ) == 3 and Parameters["Address"].split(',')[2] == 'no_slave_mode':
                pass
            else:
                self.slaveMode = True

        DumpConfigToLog()
        self._bus = smbus.SMBus(1)
        self._mask = [
            int(Parameters["Mode1"].split(',')[0], 2),
            int(Parameters["Mode2"].split(',')[0], 2)
        ]
        self._inversionMask = [
            int(Parameters["Mode1"].split(',')[1], 2),
            int(Parameters["Mode2"].split(',')[1], 2)
        ]
        self._addr = int(Parameters["Address"].split(',')[0], 16)
        self._fullIODir = (Parameters["Mode2"][2:10] +
                           Parameters["Mode1"][2:10])[::-1]
        toUpdate = []
        #Update devices which have changed
        for i in range(1, 17):
            if self._fullIODir[i - 1] == '0' and i in Devices:
                Devices[i].Delete()
            elif self._fullIODir[i - 1] == '1' and not i in Devices:
                toUpdate.append(i)
        self.__createDevice(toUpdate)
        #Initialise ports
        self._it = int(Parameters["Mode3"])
        it = [False, False]
        if self._it >= 4:
            it[0] = True
        if self._it >= 2 and self._it != 4:
            it[1] = True
        for i in range(0, 2):
            if (self._mask[i] > 0):
                self.__initPort(i, it[i])
                self.updateState(i)
        #It mirroring
        if self._it == 7:
            Domoticz.Debug("Activate Interruption mirroring")
            self._bus.write_byte_data(self._addr, MCP23017Plugin.IOCONA, 0x40)
            self._bus.write_byte_data(self._addr, MCP23017Plugin.IOCONB, 0x40)
        else:
            self._bus.write_byte_data(self._addr, MCP23017Plugin.IOCONA, 0x00)
            self._bus.write_byte_data(self._addr, MCP23017Plugin.IOCONB, 0x00)

        #GPIO for interruption
        if self._it != 0:
            import RPi.GPIO as GPIO
            GPIO.setmode(GPIO.BCM)
            for gpio in map(int, Parameters["Mode4"].split(',')):
                Domoticz.Log("Activate Interruption on GPIO  %d" % gpio)
                GPIO.setup(gpio, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                try:
                    GPIO.add_event_detect(gpio,
                                          GPIO.FALLING,
                                          callback=self.__interruptCall)
                except Exception as e:
                    Domoticz.Error("%s" % str(e))
        else:
            Domoticz.Log("No interruption")
        #Set heartbeat to polling value
        pooling = int(Parameters["Mode5"])
        if pooling == 0:
            Domoticz.Log("Disable pooling")
            self._pooling = False
        elif pooling <= 20:
            Domoticz.Heartbeat(pooling)
        else:
            self._poolingTime = pooling / 10
예제 #4
0
    def onStart(self):
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)
        Domoticz.Log("onStart called")
        DumpConfigToLog()

        #Activate DB
        BasePlugin.dbConn = sqlite3.connect(os.getcwd() + '/domoticz.db')
        BasePlugin.dbCursor = BasePlugin.dbConn.cursor()
        #
        if str(Parameters["Mode1"]) == 'MCP23017':
            Domoticz.Debug('Actuator type %s' % (Parameters["Mode1"]))
            self.actuator = MCP23017(
                int(Parameters['Address'].split(',')[0], 16),
                int(Parameters["Mode2"]))
            #MQTT if enabled
            if len(Parameters["Address"].split(',')) == 2:
                import socket
                hostname = socket.gethostname().split('.')[0]
                self.base_topic = 'domoticz/slaves/' + hostname
                self.mqttserveraddress = Parameters["Address"].strip().split(
                    ',')[1]
                self.mqttserverport = Parameters["Port"].strip()
                Domoticz.Status("MQTT Domoticz Remote enabled on:" +
                                self.base_topic + ", " +
                                self.mqttserveraddress + ":" +
                                self.mqttserverport)
                self.mqttClient = MqttClientSH2(self.mqttserveraddress,
                                                self.mqttserverport, "",
                                                self.onMQTTConnected,
                                                self.onMQTTDisconnected,
                                                self.onMQTTPublish,
                                                self.onMQTTSubscribed)
        elif str(Parameters["Mode1"]) == 'USR-R16':
            self.actuator = USR(Parameters['Address'], Parameters['Port'],
                                Parameters['Username'], Parameters['Password'])
            self.passwd = Parameters['Password']
        else:
            Domoticz.Error('Actuator type %s unknowned' %
                           (Parameters["Mode1"]))

        self.relayNb = abs(int(Parameters["Mode2"]))
        if Parameters["Mode3"]:
            self.relaySwitch = list(
                map(int,
                    str(Parameters["Mode3"]).split(',')))
        if Parameters["Mode4"]:
            self.relayImpuls = list(
                map(int,
                    str(Parameters["Mode4"]).split(',')))
        if Parameters["Mode5"]:
            self.relayThermo = list(
                map(int,
                    str(Parameters["Mode5"]).split(',')))
        #CreateNew
        if (len(Devices) == 0):
            self.__createDevices(range(1, self.relayNb + 1))
        #Update
        else:
            to_update = []
            for i in range(1, self.relayNb + 1):
                if not i in Devices:
                    to_update += [i]
                elif (i in self.relaySwitch and not (Devices[i].Type==244 and Devices[i].SubType==72)) or \
                     (i in self.relayImpuls and not (Devices[i].Type==244 and Devices[i].SubType==5)) or \
                     (i in self.relayThermo and not (50+i) in Devices) or \
                     (i not in self.relayThermo and (50+i) in Devices) or \
                     ( (i not in self.relayImpuls and i not in self.relaySwitch) and not (Devices[i].Type==244 and Devices[i].SubType==73)):

                    Domoticz.Log("Status of Unit %d has changed" % i)
                    to_update += [i]
                    #Delete Unit
                    if (50 + i) in Devices:
                        #Delete Thermo
                        if self.mqttClient is not None:
                            self._deleted += [Devices[50 + i].ID]
                            self._deleted += [Devices[100 + i].ID]
                            self._deleted += [Devices[150 + i].ID]
                        Devices[(50 + i)].Delete()
                        Devices[(100 + i)].Delete()
                        Devices[(150 + i)].Delete()
                        query = 'DELETE FROM UserVariables WHERE NAME LIKE "thermo_' + str(
                            Parameters["HardwareID"]) + '_%_hour_' + str(
                                i) + '"'
                        BasePlugin.dbCursor.execute(query)
                        BasePlugin.dbConn.commit()
                        os.remove('%s/plugins/Relay/conf/pid_%d.json' %
                                  (os.getcwd(), i))
                    if self.mqttClient is not None:
                        self._deleted += [Devices[i].ID]
                    Devices[i].Delete()
            if len(to_update) > 0:
                Domoticz.Log(str(to_update))
                self.__createDevices(to_update)
        for i in self.relayThermo:
            self.pids += [PID(i)]
        self._nbPids = len(self.pids)