Skip to content

Commit b192cd3

Browse files
committed
Fix NeoPool cmd script
1 parent a859b8d commit b192cd3

File tree

1 file changed

+68
-56
lines changed

1 file changed

+68
-56
lines changed

docs/NeoPool.md

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ Additional advantage is that you can also use Tasmota Timer switching Power1 (=f
569569

570570
The following enhancements are made using the [Berry Scripting Language](Berry) which is available on ESP32 only.
571571

572-
The class `NeoPoolCommands` below adds two new commands to Tasmota:
572+
The class `NeoPoolCommands` below adds new commands to Tasmota:
573573

574574
Command|Parameters
575575
:---|:---
@@ -663,18 +663,19 @@ Store the following code into a Tasmota file by using the WebGUI "Console" / "Ma
663663

664664
# Timer base addr index
665665
PAR_TIMER_BLOCK = [
666-
MBF_PAR_TIMER_BLOCK_FILT_INT1,
667-
MBF_PAR_TIMER_BLOCK_FILT_INT2,
668-
MBF_PAR_TIMER_BLOCK_FILT_INT3,
669-
MBF_PAR_TIMER_BLOCK_LIGHT_INT,
670-
MBF_PAR_TIMER_BLOCK_AUX1_INT1,
671-
MBF_PAR_TIMER_BLOCK_AUX1_INT2,
672-
MBF_PAR_TIMER_BLOCK_AUX2_INT1,
673-
MBF_PAR_TIMER_BLOCK_AUX2_INT2,
674-
MBF_PAR_TIMER_BLOCK_AUX3_INT1,
675-
MBF_PAR_TIMER_BLOCK_AUX3_INT2,
676-
MBF_PAR_TIMER_BLOCK_AUX4_INT1,
677-
MBF_PAR_TIMER_BLOCK_AUX4_INT2,
666+
# addr, function
667+
[MBF_PAR_TIMER_BLOCK_FILT_INT1, MBV_PAR_CTIMER_FCT_FILTRATION],
668+
[MBF_PAR_TIMER_BLOCK_FILT_INT2, MBV_PAR_CTIMER_FCT_FILTRATION],
669+
[MBF_PAR_TIMER_BLOCK_FILT_INT3, MBV_PAR_CTIMER_FCT_FILTRATION],
670+
[MBF_PAR_TIMER_BLOCK_LIGHT_INT, MBV_PAR_CTIMER_FCT_LIGHTING],
671+
[MBF_PAR_TIMER_BLOCK_AUX1_INT1, MBV_PAR_CTIMER_FCT_AUXREL4],
672+
[MBF_PAR_TIMER_BLOCK_AUX1_INT2, MBV_PAR_CTIMER_FCT_AUXREL4],
673+
[MBF_PAR_TIMER_BLOCK_AUX2_INT1, MBV_PAR_CTIMER_FCT_AUXREL5],
674+
[MBF_PAR_TIMER_BLOCK_AUX2_INT2, MBV_PAR_CTIMER_FCT_AUXREL5],
675+
[MBF_PAR_TIMER_BLOCK_AUX3_INT1, MBV_PAR_CTIMER_FCT_AUXREL6],
676+
[MBF_PAR_TIMER_BLOCK_AUX3_INT2, MBV_PAR_CTIMER_FCT_AUXREL6],
677+
[MBF_PAR_TIMER_BLOCK_AUX4_INT1, MBV_PAR_CTIMER_FCT_AUXREL7],
678+
[MBF_PAR_TIMER_BLOCK_AUX4_INT2, MBV_PAR_CTIMER_FCT_AUXREL7]
678679
]
679680
PAR_TIMER_BLOCK_AUX = [
680681
MBF_PAR_TIMER_BLOCK_AUX1_INT1,
@@ -856,48 +857,48 @@ Store the following code into a Tasmota file by using the WebGUI "Console" / "Ma
856857

857858
# NPTimer<x> 0|OFF|<hh:mm hh:mm>( <period>)|<json> (<x> = 1..12)
858859
def GetTimer(cmd, idx)
859-
var timer_enable = self.Read(cmd, "NPRead", PAR_TIMER_BLOCK[idx - 1] + MBV_TIMER_OFFMB_TIMER_ENABLE);
860+
var timer_enable = self.Read(cmd, "NPRead", PAR_TIMER_BLOCK[idx - 1][0] + MBV_TIMER_OFFMB_TIMER_ENABLE);
860861
if nil == timer_enable
861862
return nil
862863
end
863-
var data = self.Read(cmd, "NPReadL", PAR_TIMER_BLOCK[idx - 1] + MBV_TIMER_OFFMB_TIMER_ON, 7)
864+
var data = self.Read(cmd, "NPReadL", PAR_TIMER_BLOCK[idx - 1][0] + MBV_TIMER_OFFMB_TIMER_ON, 7)
864865
if nil == data
865866
return nil
866867
end
867868

868869
var period_str
869-
if (data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] == 0)
870+
if (int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) == 0)
870871
period_str = "0"
871-
elif ((data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] % (86400 * 7)) == 0)
872-
period_str = string.format("%dw", data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] / (86400 * 7))
873-
elif ((data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] % 86400) == 0)
874-
period_str = string.format("%dd", data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] / 86400)
875-
elif ((data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] % 3600) == 0)
876-
period_str = string.format("%dh", data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] / 3600)
877-
elif ((data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] % 60) == 0)
878-
period_str = string.format("%dm", data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] / 60)
872+
elif ((int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) % (86400 * 7)) == 0)
873+
period_str = string.format("%dw", int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) / (86400 * 7))
874+
elif ((int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) % 86400) == 0)
875+
period_str = string.format("%dd", int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) / 86400)
876+
elif ((int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) % 3600) == 0)
877+
period_str = string.format("%dh", int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) / 3600)
878+
elif ((int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) % 60) == 0)
879+
period_str = string.format("%dm", int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) / 60)
879880
else
880-
period_str = string.format("%ds", data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX])
881+
period_str = string.format("%ds", int(data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]))
881882
end
882883
var state = self.TEXT_OFF
883884
if (timer_enable == MBV_PAR_CTIMER_ENABLED &&
884-
(data[MBV_TIMER_OFFMB_TIMER_ON_IDX] != (data[MBV_TIMER_OFFMB_TIMER_ON_IDX] + data[MBV_TIMER_OFFMB_TIMER_INTERVAL_IDX])) )
885+
(int(data[MBV_TIMER_OFFMB_TIMER_ON_IDX]) != (int(data[MBV_TIMER_OFFMB_TIMER_ON_IDX]) + int(data[MBV_TIMER_OFFMB_TIMER_INTERVAL_IDX]))) )
885886
state = self.TEXT_ON
886887
end
887888
return string.format('{"%s%d":{"State":"%s","Function":"%s","Start":"%s","End":"%s","Period":"%s"}}',
888889
cmd, idx,
889890
state,
890-
MBV_PAR_CTIMER_FCT.find(data[MBV_TIMER_OFFMB_TIMER_FUNCTION_IDX], "undefined"),
891-
tasmota.strftime("%H:%M", data[MBV_TIMER_OFFMB_TIMER_ON_IDX]),
892-
tasmota.strftime("%H:%M", data[MBV_TIMER_OFFMB_TIMER_ON_IDX] + data[MBV_TIMER_OFFMB_TIMER_INTERVAL_IDX]),
891+
MBV_PAR_CTIMER_FCT.find(int(data[MBV_TIMER_OFFMB_TIMER_FUNCTION_IDX]), "undefined"),
892+
tasmota.strftime("%H:%M", int(data[MBV_TIMER_OFFMB_TIMER_ON_IDX])),
893+
tasmota.strftime("%H:%M", int(data[MBV_TIMER_OFFMB_TIMER_ON_IDX]) + int(data[MBV_TIMER_OFFMB_TIMER_INTERVAL_IDX])),
893894
period_str
894895
)
895896
end
896897

897898
def NPTimer(cmd, idx, payload)
898899
var parm
899900

900-
if idx < 1 || idx > 12
901+
if idx < 1 || idx > size(PAR_TIMER_BLOCK)
901902
tasmota.resp_cmnd_error()
902903
return
903904
end
@@ -915,39 +916,50 @@ Store the following code into a Tasmota file by using the WebGUI "Console" / "Ma
915916
parm = ''
916917
end
917918

918-
if (nil == json.load(parm))
919-
# convert none json parm to json parm
920-
var params = self.GetParm(parm)
921-
var keys = ["START", "END", "PERIOD"]
922-
if size(params) > size(keys)
923-
tasmota.resp_cmnd_error()
924-
return
925-
end
926-
var _json = {}
927-
while params.size() > 0
928-
_json[keys[0]] = params[0]
929-
keys.remove(0)
930-
params.remove(0)
919+
try
920+
if (nil == json.load(parm))
921+
# convert none json parm to json parm
922+
var params = self.GetParm(parm)
923+
var keys = ["START", "END", "PERIOD"]
924+
if size(params) > size(keys)
925+
tasmota.resp_cmnd_error()
926+
return
927+
end
928+
var _json = {}
929+
while params.size() > 0
930+
_json[keys[0]] = params[0]
931+
keys.remove(0)
932+
params.remove(0)
933+
end
934+
parm = json.dump(_json)
931935
end
932-
parm = json.dump(_json)
936+
except ..
937+
tasmota.resp_cmnd_error()
938+
return
933939
end
934940

935941
parm = json.load(parm)
936942
if (nil != parm)
937-
# set start and end
938943
var timer_start, timer_end, strp
939-
strp = tasmota.strptime(parm.find("START", "00:00"), "%H:%M")
940-
timer_start = (strp.find("hour", 0) * 3600) + (strp.find("min", 0) * 60)
941-
strp = tasmota.strptime(parm.find("END", "00:00"), "%H:%M")
942-
timer_end = strp.find("hour", 0) * 3600 + strp.find("min", 0) * 60
943-
if (timer_start > timer_end)
944-
var tmp = timer_end
945-
timer_end = timer_start
946-
timer_start = tmp
944+
try
945+
# set start and end
946+
strp = tasmota.strptime(parm.find("START", "00:00"), "%H:%M")
947+
timer_start = (strp.find("hour", 0) * 3600) + (strp.find("min", 0) * 60)
948+
strp = tasmota.strptime(parm.find("END", "00:00"), "%H:%M")
949+
timer_end = strp.find("hour", 0) * 3600 + strp.find("min", 0) * 60
950+
if (timer_start > timer_end)
951+
var tmp = timer_end
952+
timer_end = timer_start
953+
timer_start = tmp
954+
end
955+
except ..
956+
tasmota.resp_cmnd_error()
957+
return
947958
end
948-
tasmota.cmd(string.format("NPWrite 0x%04X,%d", PAR_TIMER_BLOCK[idx - 1] + MBV_TIMER_OFFMB_TIMER_ENABLE, MBV_PAR_CTIMER_ENABLED))
949-
tasmota.cmd(string.format("NPWriteL 0x%04X,%d", PAR_TIMER_BLOCK[idx - 1] + MBV_TIMER_OFFMB_TIMER_ON, timer_start))
950-
tasmota.cmd(string.format("NPWriteL 0x%04X,%d", PAR_TIMER_BLOCK[idx - 1] + MBV_TIMER_OFFMB_TIMER_INTERVAL, timer_end - timer_start))
959+
tasmota.cmd(string.format("NPWrite 0x%04X,%d", PAR_TIMER_BLOCK[idx - 1][0] + MBV_TIMER_OFFMB_TIMER_ENABLE, MBV_PAR_CTIMER_ENABLED))
960+
tasmota.cmd(string.format("NPWriteL 0x%04X,%d", PAR_TIMER_BLOCK[idx - 1][0] + MBV_TIMER_OFFMB_TIMER_FUNCTION, PAR_TIMER_BLOCK[idx - 1][1]))
961+
tasmota.cmd(string.format("NPWriteL 0x%04X,%d", PAR_TIMER_BLOCK[idx - 1][0] + MBV_TIMER_OFFMB_TIMER_ON, timer_start))
962+
tasmota.cmd(string.format("NPWriteL 0x%04X,%d", PAR_TIMER_BLOCK[idx - 1][0] + MBV_TIMER_OFFMB_TIMER_INTERVAL, timer_end - timer_start))
951963

952964
var period_str = string.toupper(self.trim(parm.find("Period", "0")))
953965
var period = int(period_str)

0 commit comments

Comments
 (0)