Skip to content

Commit

Permalink
reduced screen updates to lower mqtt noise
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaskalov committed Nov 11, 2023
1 parent f8a1527 commit 97d2f1c
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions src/ShellyPro4PM.be
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ class ShellyPro4PM

var relay_names
var relay_labels
var secs
var wifi_sum
var wifi_cnt

def init()
var status = tasmota.cmd("status", true)['Status']
var device = status['DeviceName']
self.relay_names = status['FriendlyName']
self.relay_labels = []
self.secs = 0
self.wifi_sum = 0
self.wifi_cnt = 0

self.clear_screen()
self.set_header(device)
Expand Down Expand Up @@ -52,25 +58,26 @@ class ShellyPro4PM
ShellyPro4PM.display_text(f"[x{x}y{y+1}Ci{col}U{width}:{height}:{radius}x{cX}y{cY}Ci1K{cR}]")
end

static def wifi(x, y, percent)

static def status(x, y, percent)
var bars = 0
if percent
if percent >= 20 bars = 1 end
if percent >= 40 bars = 2 end
if percent >= 60 bars = 3 end
if percent >= 80 bars = 4 end
end
var cmd = ""
for ofs: 0..3
var col = bars > ofs ? 1 : 15
ShellyPro4PM.display_text(f"[Ci{col}x{x+ofs*4}y{y-ofs*2+10}v{(ofs+1)*2}x{x+ofs*4+1}y{y-ofs*2+10}v{(ofs+1)*2}]")
cmd += f"Ci{col}x{x+ofs*4}y{y-ofs*2+10}v{(ofs+1)*2}x{x+ofs*4+1}y{y-ofs*2+10}v{(ofs+1)*2}"
end
cmd += f"x{x+20}y{y+2}Ci1Bi4f1t"
ShellyPro4PM.display_text(f"[{cmd}]")
end

def set_header(device)
self.line(0,"", 1, 4)
self.update_time()
self.update_wifi()
self.line(0, device, 1, 4)
self.status(100, 5, 0)
end

def set_relays()
Expand All @@ -83,27 +90,36 @@ class ShellyPro4PM
end
end

static def update_time()
ShellyPro4PM.display_text(f"[x3y7Ci1Bi4f1tS]")
end

static def update_wifi()
var wifi = tasmota.wifi()
var quality = wifi.find("quality")
ShellyPro4PM.wifi(138, 5, quality)
end

static def update_relay(relay, powered)
ShellyPro4PM.switch(123, relay*21+4, powered)
end

def every_second()
self.update_time()
self.update_wifi()

self.secs += 1

if self.secs % 10 == 0
var wifi = tasmota.wifi()
var quality = wifi.find("quality")
self.wifi_sum += quality ? quality : 0
self.wifi_cnt += 1
end

if self.secs > 59
var avrg = self.wifi_sum / self.wifi_cnt
self.status(100, 5, avrg)

self.wifi_sum = 0
self.wifi_cnt = 0

var rtc = tasmota.rtc()['local']
self.secs = tasmota.time_dump(rtc)['sec']
end
end

end

return ShellyPro4PM
#shelly.del()
#shelly = ShellyPro4PM()
# shelly.del()
# shelly = ShellyPro4PM()

0 comments on commit 97d2f1c

Please sign in to comment.