@@ -569,7 +569,7 @@ Additional advantage is that you can also use Tasmota Timer switching Power1 (=f
569
569
570
570
The following enhancements are made using the [ Berry Scripting Language] ( Berry ) which is available on ESP32 only.
571
571
572
- The class ` NeoPoolCommands ` below adds two new commands to Tasmota:
572
+ The class ` NeoPoolCommands ` below adds new commands to Tasmota:
573
573
574
574
Command|Parameters
575
575
:---|:---
@@ -663,18 +663,19 @@ Store the following code into a Tasmota file by using the WebGUI "Console" / "Ma
663
663
664
664
# Timer base addr index
665
665
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]
678
679
]
679
680
PAR_TIMER_BLOCK_AUX = [
680
681
MBF_PAR_TIMER_BLOCK_AUX1_INT1,
@@ -856,48 +857,48 @@ Store the following code into a Tasmota file by using the WebGUI "Console" / "Ma
856
857
857
858
# NPTimer<x> 0|OFF|<hh:mm hh:mm>( <period>)|<json> (<x> = 1..12)
858
859
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);
860
861
if nil == timer_enable
861
862
return nil
862
863
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)
864
865
if nil == data
865
866
return nil
866
867
end
867
868
868
869
var period_str
869
- if (data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX] == 0)
870
+ if (int( data[MBV_TIMER_OFFMB_TIMER_PERIOD_IDX]) == 0)
870
871
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)
879
880
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]) )
881
882
end
882
883
var state = self.TEXT_OFF
883
884
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]) )) )
885
886
state = self.TEXT_ON
886
887
end
887
888
return string.format('{"%s%d":{"State":"%s","Function":"%s","Start":"%s","End":"%s","Period":"%s"}}',
888
889
cmd, idx,
889
890
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]) ),
893
894
period_str
894
895
)
895
896
end
896
897
897
898
def NPTimer(cmd, idx, payload)
898
899
var parm
899
900
900
- if idx < 1 || idx > 12
901
+ if idx < 1 || idx > size(PAR_TIMER_BLOCK)
901
902
tasmota.resp_cmnd_error()
902
903
return
903
904
end
@@ -915,39 +916,50 @@ Store the following code into a Tasmota file by using the WebGUI "Console" / "Ma
915
916
parm = ''
916
917
end
917
918
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)
931
935
end
932
- parm = json.dump(_json)
936
+ except ..
937
+ tasmota.resp_cmnd_error()
938
+ return
933
939
end
934
940
935
941
parm = json.load(parm)
936
942
if (nil != parm)
937
- # set start and end
938
943
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
947
958
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))
951
963
952
964
var period_str = string.toupper(self.trim(parm.find("Period", "0")))
953
965
var period = int(period_str)
0 commit comments