def getCachedRSSI(urssi=-1): global _lastRSSIval, _lastRSSItime if ((time.time()-_lastRSSItime)>=3) and (urssi==-1): _lastRSSIval = OS.get_rssi() _lastRSSItime = time.time() try: if urssi != -1: rssi = urssi else: rssi = int(_lastRSSIval) except: pass return str(rssi)
def p026_get_value(self, ptype): value = 0 if ptype == 1: value = rpieTime.getuptime(0) elif ptype == 2: value = OS.FreeMem() elif ptype == 3: value = OS.get_rssi() elif ptype == 4: value = OS.read_cpu_usage() elif ptype == 5: value = OS.read_cpu_temp() return value
def display_wifibars(self): connected = True try: rssi = int(OS.get_rssi()) except: rssi = -100 connected = False if rssi < -99: connected = False nbars_filled = (rssi + 100) / 8 x = self.device.width - 23 # 105 y = 0 size_x = 15 if self.width != 128: # correct x coords size_x = int(size_x * (self.width / 128)) x = int(x * (self.width / 128)) size_y = 10 if self.height != 64: # correct y coords size_y = int(size_y * (self.height / 64)) nbars = 5 width = int(size_x / nbars) size_x = width * nbars - 1 if self.lastwifistrength != nbars_filled: self.lastwifistrength = nbars_filled draw = ImageDraw.Draw(self.dispimage) draw.rectangle(((x, y), (x + size_x, y + size_y)), fill="black") if connected: for ibar in range(0, nbars): height = size_y * (ibar + 1) / nbars xpos = x + ibar * width ypos = y + size_y - height if (ibar <= nbars_filled): draw.rectangle( ((xpos, ypos), (xpos + width - 1, ypos + height)), fill="white") else: draw.rectangle( ((xpos, ypos), (xpos + width - 1, ypos + 1)), fill="white") draw.rectangle(((xpos, y + size_y - 1), (xpos + width - 1, y + size_y)), fill="white") return True
def mapRSSItoDomoticz(urssi=-1): global _lastRSSIval, _lastRSSItime res = 12 if ((time.time() - _lastRSSItime) >= 3) and (urssi == -1): _lastRSSIval = OS.get_rssi() _lastRSSItime = time.time() try: if urssi != -1: rssi = urssi else: rssi = int(_lastRSSIval) if (-50 < rssi): res = 10 elif (rssi <= -98): res = 0 else: res = int(round((rssi + 97) / 5, 0) + 1) except: pass return str(res)
def getglobalvar(varname): global SysVars svname = varname.strip().lower() res = "" if svname in SysVars: if svname == SysVars[0]: #%systime% 01:23:54 return datetime.now().strftime('%H:%M:%S') elif svname == SysVars[1]: #%systm_hm% 01:23 return datetime.now().strftime('%H:%M') elif svname == SysVars[2]: #%lcltime% 2018-03-16 01:23:54 return datetime.now().strftime('%Y-%m-%d %H:%M:%S') elif svname == SysVars[3]: #%syshour% 11 Current hour (hh) return datetime.now().strftime('%H') elif svname == SysVars[4]: #%sysmin% 22 Current minute (mm) return datetime.now().strftime('%M') elif svname == SysVars[5]: #%syssec% 33 Current second (ss) return datetime.now().strftime('%S') elif svname == SysVars[6]: #%sysday% 16 Current day of month (DD) return datetime.now().strftime('%d') elif svname == SysVars[7]: #%sysmonth% 3 Current month (MM) return datetime.now().strftime('%m') elif svname == SysVars[8]: #%sysyear% 2018 4 digits (YYYY) return datetime.now().strftime('%Y') elif svname == SysVars[9]: #%sysyears% 18 2 digits (YY) return datetime.now().strftime('%y') elif svname == SysVars[ 10]: #%sysweekday% 5 Weekday (integer) - 1, 2, 3... (1=Sunday, 2=Monday etc.) return str(int(datetime.now().strftime('%w')) + 1) elif svname == SysVars[ 11]: #%sysweekday_s% Fri Weekday (verbose) - Sun, Mon, Tue return datetime.now().strftime('%a') elif svname == SysVars[ 12]: #%unixtime% 1521731277 Unix time (seconds since epoch, 1970-01-01 00:00:00) return str(int(time.time())) elif svname == SysVars[13]: #%uptime% 3244 Uptime in minutes return str(rpieTime.getuptime(2)) elif svname == SysVars[14]: #%rssi% -45 WiFi signal strength (dBm) return str(OS.get_rssi()) elif svname == SysVars[15]: #%ip% 192.168.0.123 Current IP address return str(OS.get_ip()) elif svname == SysVars[16]: #%ip4% ipcim 4.byte res2 = str(OS.get_ip()) resarr = res2.split(".") if len(resarr) > 3: return resarr[3] elif svname == SysVars[17]: #%sysname% name return Settings.Settings["Name"] elif svname == SysVars[18]: #%unit% 32 Unit number return Settings.Settings["Unit"] elif svname == SysVars[19]: #%ssid% H4XX0R njietwork! wdev = False try: wdev = Settings.NetMan.getfirstwirelessdev() except: wdev = False if wdev: res = str(Network.get_ssid(wdev)) elif svname == SysVars[20]: #%mac% 00:14:22:01:23:45 MAC address pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd < 0 and len(Settings.NetworkDevices) > 0: pd = 0 if pd != "" and pd >= 0: return Settings.NetworkDevices[pd].mac elif svname == SysVars[ 21]: #%mac_int% 2212667 MAC address in integer to be used in rules (only the last 24 bit) pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd < 0 and len(Settings.NetworkDevices) > 0: pd = 0 if pd >= 0: try: res2 = Settings.NetworkDevices[pd].mac resarr = res2.split(":") if len(resarr) > 5: res = str( int("0x" + resarr[3] + resarr[4] + resarr[5], 16)) except: res = "" return res
def getglobalvar(varname): global SysVars, suntimesupported svname = varname.strip().lower() par = "" if ("-" in svname): resarr = svname.split("-") svname = resarr[0] par = "-" + resarr[1] if ("+" in svname): resarr = svname.split("+") svname = resarr[0] par = "+" + resarr[1] res = "" if svname in SysVars: if svname == SysVars[0]: #%systime% 01:23:54 return datetime.now().strftime('%H:%M:%S') elif svname == SysVars[1]: #%systm_hm% 01:23 return datetime.now().strftime('%H:%M') elif svname == SysVars[2]: #%lcltime% 2018-03-16 01:23:54 return datetime.now().strftime('%Y-%m-%d %H:%M:%S') elif svname == SysVars[3]: #%syshour% 11 Current hour (hh) return int(datetime.now().strftime('%H')) elif svname == SysVars[4]: #%sysmin% 22 Current minute (mm) return int(datetime.now().strftime('%M')) elif svname == SysVars[5]: #%syssec% 33 Current second (ss) return int(datetime.now().strftime('%S')) elif svname == SysVars[6]: #%sysday% 16 Current day of month (DD) return int(datetime.now().strftime('%d')) elif svname == SysVars[7]: #%sysmonth% 3 Current month (MM) return int(datetime.now().strftime('%m')) elif svname == SysVars[8]: #%sysyear% 2018 4 digits (YYYY) return datetime.now().strftime('%Y') elif svname == SysVars[9]: #%sysyears% 18 2 digits (YY) return datetime.now().strftime('%y') elif svname == SysVars[ 10]: #%sysweekday% 5 Weekday (integer) - 1, 2, 3... (1=Sunday, 2=Monday etc.) return str(int(datetime.now().strftime('%w')) + 1) elif svname == SysVars[ 11]: #%sysweekday_s% Fri Weekday (verbose) - Sun, Mon, Tue return datetime.now().strftime('%a') elif svname == SysVars[ 12]: #%unixtime% 1521731277 Unix time (seconds since epoch, 1970-01-01 00:00:00) return str(int(time.time())) elif svname == SysVars[13]: #%uptime% 3244 Uptime in minutes return str(rpieTime.getuptime(2)) elif svname == SysVars[14]: #%rssi% -45 WiFi signal strength (dBm) return str(OS.get_rssi()) elif svname == SysVars[15]: #%ip% 192.168.0.123 Current IP address return str(OS.get_ip()) elif svname == SysVars[16]: #%ip4% ipcim 4.byte res2 = str(OS.get_ip()) resarr = res2.split(".") if len(resarr) > 3: return resarr[3] elif svname == SysVars[17]: #%sysname% name return Settings.Settings["Name"] elif svname == SysVars[18]: #%unit% 32 Unit number return Settings.Settings["Unit"] elif svname == SysVars[19]: #%ssid% H4XX0R njietwork! wdev = False try: wdev = Settings.NetMan.getfirstwirelessdev() except: wdev = False if wdev: res = str(Network.get_ssid(wdev)) elif svname == SysVars[20]: #%mac% 00:14:22:01:23:45 MAC address pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd < 0 and len(Settings.NetworkDevices) > 0: pd = 0 if pd != "" and pd >= 0: return Settings.NetworkDevices[pd].mac elif svname == SysVars[ 21]: #%mac_int% 2212667 MAC address in integer to be used in rules (only the last 24 bit) pd = -1 try: pd = Settings.NetMan.getprimarydevice() except: pd = -1 if pd < 0 and len(Settings.NetworkDevices) > 0: pd = 0 if pd >= 0: try: res2 = Settings.NetworkDevices[pd].mac resarr = res2.split(":") if len(resarr) > 5: res = str( int("0x" + resarr[3] + resarr[4] + resarr[5], 16)) except: res = "" return res elif svname == SysVars[22]: #%build% bstr = str(rpieGlobals.BUILD) return bstr elif svname == SysVars[23]: #sunrise try: from suntime import Sun suntimesupported = 1 except: suntimesupported = 0 if suntimesupported == 1: try: sun = Sun(Settings.AdvSettings["Latitude"], Settings.AdvSettings["Longitude"]) abd_sr = sun.get_local_sunrise_time(datetime.now()) if par != "": abd_sr = addtoTime(abd_sr, par) res = abd_sr.strftime('%H:%M') except Exception as e: res = "00:00" return res elif svname == SysVars[24]: #sunset try: from suntime import Sun suntimesupported = 1 except: suntimesupported = 0 if suntimesupported == 1: try: sun = Sun(Settings.AdvSettings["Latitude"], Settings.AdvSettings["Longitude"]) abd_ss = sun.get_local_sunset_time(datetime.now()) if par != "": abd_ss = addtoTime(abd_ss, par) res = abd_ss.strftime('%H:%M') except Exception as e: res = "00:00" return res elif svname == SysVars[25]: #sun altitude try: from pytz import reference from pysolar.solar import get_altitude pysolarsupported = 1 except: pysolarsupported = 0 res = "0" if pysolarsupported == 1: try: localtime = reference.LocalTimezone() today = datetime.now(localtime) res = get_altitude(Settings.AdvSettings["Latitude"], Settings.AdvSettings["Longitude"], today) except Exception as e: print(e) res = "0" return res elif svname == SysVars[26]: #sun azimuth try: from pytz import reference from pysolar.solar import get_azimuth pysolarsupported = 1 except: pysolarsupported = 0 res = "0" if pysolarsupported == 1: try: localtime = reference.LocalTimezone() today = datetime.now(localtime) res = get_azimuth(Settings.AdvSettings["Latitude"], Settings.AdvSettings["Longitude"], today) except Exception as e: print(e) res = "0" return res elif svname == SysVars[27]: #sun radiation try: from pytz import reference from pysolar.solar import get_altitude from pysolar.radiation import get_radiation_direct pysolarsupported = 1 except: pysolarsupported = 0 res = "-1" if pysolarsupported == 1: try: localtime = reference.LocalTimezone() today = datetime.now(localtime) altitude_deg = get_altitude( Settings.AdvSettings["Latitude"], Settings.AdvSettings["Longitude"], today) res = get_radiation_direct(today, altitude_deg) except Exception as e: print(e) return res return res