def humStatDomoticz(humidity): res = 3 try: hum = misc.str2num(humidity) if (hum < 30): res = 2 elif (hum < 40): res = 0 elif (hum < 59): res = 1 except: pass return str(res)
def getstatusjson(st, globdata): rstr = "" if st == "Status": rstr += '"Status": {"Module": ' + str( globdata.modtype) + ',"DeviceName":"' + str( Settings.Settings["Name"]) + '",' rstr += '"FriendlyName": ["' + str(globdata.datas[0][1]) + '"' if globdata.taskdevicepluginconfig[0] > 1: for n in range(1, globdata.taskdevicepluginconfig[0]): rstr += ',"' + str(globdata.datas[n][1]) + '"' rstr += '],"Topic": "","ButtonTopic": "0","PowerOnState": 0,"LedState": 0,"SaveData": 1,"SaveState": 1,"ButtonRetain": 0,"PowerRetain": 0,' if getswitchstate(0, globdata): s = 1 else: s = 0 rstr += '"Power": ' + str(s) + '}' elif st == "StatusPRM": rstr += '"StatusPRM": {"Baudrate": 115200,"GroupTopic": "","OtaUrl": "","Sleep": 0,"BootCount": 1,"SaveCount": 1,"SaveAddress": "FB000",' rstr += '"Uptime": "' + rpieTime.getuptime(3) + '"}' elif st == "StatusNET": try: defaultdev = Settings.NetMan.getprimarydevice() if Settings.NetworkDevices[defaultdev].ip == "": defaultdev = -1 except: defaultdev = -1 if defaultdev == -1: try: defaultdev = Settings.NetMan.getsecondarydevice() except: defaultdev = -1 rstr += '"StatusNET": {"Webserver": 2,"WifiConfig": 4,' rstr += '"Hostname": "' + str(Settings.Settings["Name"]) + '",' rstr += '"IPAddress": "' + str( Settings.NetworkDevices[defaultdev].ip) + '",' rstr += '"Gateway": "' + str( Settings.NetworkDevices[defaultdev].gw) + '",' rstr += '"Subnetmask": "' + str( Settings.NetworkDevices[defaultdev].mask) + '",' dnss = Settings.NetworkDevices[defaultdev].dns.strip().split(" ") rstr += '"DNSServer": "' + str(dnss[0]) + '",' rstr += '"Mac": "' + str( Settings.NetworkDevices[defaultdev].mac).upper() + '"}' elif st == "StatusSNS": rstr += '"StatusSNS": {"Time": "' + datetime.now().strftime( '%Y-%m-%dT%H:%M:%S') + '",' if globdata.taskdevicepluginconfig[0] == 1: if getswitchstate(0, globdata) == 1: st = "ON" else: st = "OFF" rstr += '"Switch1": "' + st + '"' else: for s in range(int(globdata.taskdevicepluginconfig[0])): if getswitchstate(s, globdata) == 1: st = "ON" else: st = "OFF" rstr += '"Switch' + str(s + 1) + '": "' + st + '"' if s < (int(globdata.taskdevicepluginconfig[0]) - 1): rstr += "," rstr += '}' elif st == "StatusSTS": rstr += '"StatusSTS": {"Vcc": 3.1415,' # Pi= 3.14 rstr += '"Time": "' + str( datetime.now().strftime('%Y-%m-%dT%H:%M:%S')) + '",' rstr += '"Uptime": "' + rpieTime.getuptime(3) + '",' if globdata.taskdevicepluginconfig[0] == 1: rstr += '"POWER": "' if getswitchstate(0, globdata) == 1: rstr += "ON" else: rstr += "OFF" rstr += '",' else: for s in range(globdata.taskdevicepluginconfig[0]): rstr += '"POWER' + str(s + 1) + '": "' if getswitchstate(s, globdata) == 1: rstr += "ON" else: rstr += "OFF" rstr += '",' rstr += '"Wifi": {"AP": 1,' rstr += '"SSId": "' + str(Settings.NetMan.WifiSSID) + '",' rstr += '"RSSI": ' + str(OS.get_rssi()) + ',' rstr += '"APMac": "","Channel":1}}' elif st == "StatusTIM": rstr += '"StatusTIM": {' rstr += '"UTC": "' + str( datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')) + '",' rstr += '"Local": "' + str( datetime.now().strftime('%Y-%m-%dT%H:%M:%S')) + '",' rstr += '"StartDST": "1970-01-01T00:00:00","EndDST": "1970-01-01T00:00:00",' rstr += '"Timezone": "+00:00"}' elif st == "StatusMEM": rstr += '"StatusMEM": {"ProgramSize": 2048,"Free": 2048,"ProgramFlashSize": 4096,"FlashSize": 4096,"FlashMode": 3,' rstr += '"Heap": ' + str(OS.FreeMem()) + '}' elif st == "StatusFWR": rstr += '"StatusFWR": {"Version": "5.12.0a","Boot": 1,' rstr += '"BuildDateTime": "' + str(globdata.btime) + '",' rstr += '"Core": "' + rpieGlobals.PROGNAME + ' ' + rpieGlobals.PROGVER + '",' rstr += '"SDK": "Python ' + sys.version.replace( '\n', '') + " " + platform.platform() + '",' cpui = OS.get_cpu() frarr = str(cpui["speed"]).split() try: fr = str(int(misc.str2num(frarr[0]))) except: fr = str(frarr[0]) rstr += '"CpuFrequency": "' + fr + '","Hardware":"' + str( cpui["model"]) + '"}' return rstr
def plugin_write(self, cmd): # handle incoming commands res = False cmdarr = cmd.split(",") cmdarr[0] = cmdarr[0].strip().lower() if self.initialized == False: return False if cmdarr[0] == "eq3": try: rname = cmdarr[1].strip() except: rname = "" if rname.lower() != self.gettaskname().lower(): return False # command arrived to another task, skip it if cmdarr[2] == "sync": if self.thermostat is not None: try: self.thermostat.update() jstruc = { "target temperature": self.thermostat.target_temperature, "mode": self.thermostat.mode_readable } res = str(jstruc).replace("'", '"').replace(', ', ',\n') res = res.replace("{", "{\n").replace("}", "\n}") except Exception as e: print(e) return res elif cmdarr[2] == "mode": mode = "" try: mode = str(cmdarr[3].strip()).lower() except: mode = "" tmode = -1 if mode == "closed": tmode = Mode.Closed elif mode == "open": tmode = Mode.Open elif mode == "auto": tmode = Mode.Auto elif mode == "manual": tmode = Mode.Manual elif mode == "away": tmode = Mode.Away elif mode == "boost": tmode = Mode.Boost if (self.thermostat is not None) and int(tmode) > -1: try: self.thermostat.mode = tmode misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "EQ3 mode " + str(mode)) res = True except Exception as e: print(e) elif cmdarr[2] == "temp": temp = -1 try: temp = misc.str2num(cmdarr[3].strip()) except: temp = -1 if (self.thermostat is not None) and temp > 4 and temp < 31: try: self.thermostat.target_temperature = temp misc.addLog(rpieGlobals.LOG_LEVEL_DEBUG, "EQ3 target temperature " + str(temp)) res = True except Exception as e: print(e) return res