@@ -495,9 +495,29 @@ Store the following code using the WebGUI "Console" / "Manage File system".
495
495
496
496
ESP32 file ` neopool.be ` :
497
497
``` python
498
- class NeoPoolCommands
498
+ # Neopool definitions
499
+ var MBF_RELAY_STATE = 0x 010E
500
+ var MBF_NOTIFICATION = 0x 0110
501
+ var MBF_CELL_BOOST = 0x 020C
502
+
503
+ var MBF_PAR_TIMER_BLOCK_AUX1_INT1 = 0x 04AC
504
+ var MBF_PAR_TIMER_BLOCK_AUX2_INT1 = 0x 04BB
505
+ var MBF_PAR_TIMER_BLOCK_AUX3_INT1 = 0x 04CA
506
+ var MBF_PAR_TIMER_BLOCK_AUX4_INT1 = 0x 04D9
507
+ var PAR_TIMER_BLOCK_AUX = [
508
+ MBF_PAR_TIMER_BLOCK_AUX1_INT1 ,
509
+ MBF_PAR_TIMER_BLOCK_AUX2_INT1 ,
510
+ MBF_PAR_TIMER_BLOCK_AUX3_INT1 ,
511
+ MBF_PAR_TIMER_BLOCK_AUX4_INT1
512
+ ]
513
+ var MBV_PAR_CTIMER_ALWAYS_ON = 3
514
+ var MBV_PAR_CTIMER_ALWAYS_OFF = 4
515
+
516
+ # NeoPool command class
517
+ class Commands
499
518
var TEXT_OFF
500
519
var TEXT_ON
520
+ var TEXT_TOGGLE
501
521
502
522
# string helper
503
523
def ltrim (s )
@@ -514,12 +534,13 @@ class NeoPoolCommands
514
534
end
515
535
516
536
# NPBoost OFF|0|ON|1|REDOX|2
517
- # 0|OFF: Switch boost off
518
- # 1|ON: Switch boost on without redox control
519
- # 2|REDOX: Switch boost on with redox control
537
+ # 0|OFF: Switch boost off
538
+ # 1|ON: Switch boost on without redox control
539
+ # 2|REDOX: Switch boost on with redox control
520
540
def NPBoost (cmd , idx , payload )
521
541
import string
522
542
var ctrl, parm
543
+
523
544
try
524
545
parm = string.toupper(self .trim(payload))
525
546
except ..
@@ -536,21 +557,25 @@ class NeoPoolCommands
536
557
tasmota.resp_cmnd_error()
537
558
return
538
559
end
539
- tasmota.cmd(string.format(" Backlog NPWrite 0x020C,0x%04X ;NPSave;NPExec;NPWrite 0x0110,0x7F" , ctrl))
560
+ tasmota.cmd(string.format(" NPWrite 0x%04X ,0x%04X " , MBF_CELL_BOOST , ctrl))
561
+ tasmota.cmd(" NPSave" )
562
+ tasmota.cmd(" NPExec" )
563
+ tasmota.cmd(string.format(" NPWrite 0x%04X ,0x7F" , MBF_NOTIFICATION ))
540
564
else
541
565
try
542
- ctrl = compile (" return " + str ( tasmota.cmd(" NPRead 0x020C " ) [' NPRead' ][' Data' ]) )()
566
+ ctrl = compile (" return " .. tasmota.cmd(string.format( " NPRead 0x %04X " , MBF_CELL_BOOST )) [' NPRead' ][' Data' ])()
543
567
except ..
544
568
tasmota.resp_cmnd_error()
545
569
return
546
570
end
547
571
end
548
- tasmota.resp_cmnd(string.format(' {"NPBoost ":"%s "}' , ctrl == 0 ? self .TEXT_OFF : (ctrl & 0x 8500 ) == 0x 8500 ? self .TEXT_ON : " REDOX" ))
572
+ tasmota.resp_cmnd(string.format(' {"%s ":"%s "}' , cmd , ctrl == 0 ? self .TEXT_OFF : (ctrl & 0x 8500 ) == 0x 8500 ? self .TEXT_ON : " REDOX" ))
549
573
end
550
574
551
- # NPAux<x> OFF|0|ON|1 (<x> = 1..4)
552
- # 0|OFF: Switch aux x off
553
- # 1|ON: Switch aux x on
575
+ # NPAux<x> OFF|0|ON|1 t (<x> = 1..4)
576
+ # 0|OFF: Switch Aux x to off
577
+ # 1|ON: Switch Aux x to on
578
+ # 2|TOGGLE: Toggle Aux x
554
579
def NPAux (cmd , idx , payload )
555
580
import string
556
581
var ctrl, parm
@@ -567,40 +592,49 @@ class NeoPoolCommands
567
592
end
568
593
if parm != " "
569
594
if string.find(parm, ' OFF' )>= 0 || string.find(parm, self .TEXT_OFF )>= 0 || string.find(parm, ' 0' )>= 0
570
- ctrl = 4
595
+ ctrl = MBV_PAR_CTIMER_ALWAYS_OFF
571
596
elif string.find(parm, ' ON' )>= 0 || string.find(parm, self .TEXT_ON )>= 0 || string.find(parm, ' 1' )>= 0
572
- ctrl = 3
597
+ ctrl = MBV_PAR_CTIMER_ALWAYS_ON
598
+ elif string.find(parm, ' TOGGLE' )>= 0 || string.find(parm, self .TEXT_TOGGLE )>= 0 || string.find(parm, ' 2' )>= 0
599
+ try
600
+ ctrl = (compile (" return " ..tasmota.cmd(string.format(" NPRead 0x%04X " , MBF_RELAY_STATE ))[' NPRead' ][' Data' ])() >> (idx+ 2 )) & 1 ? MBV_PAR_CTIMER_ALWAYS_OFF : MBV_PAR_CTIMER_ALWAYS_ON
601
+ except ..
602
+ tasmota.resp_cmnd_error()
603
+ return
604
+ end
573
605
else
574
606
tasmota.resp_cmnd_error()
575
607
return
576
608
end
577
- tasmota.cmd(string.format(" Backlog NPWrite 0x%04X ,%d ;NPExec" , [0x 04AC , 0x 04BB , 0x 04CA , 0x 04D9 ][idx- 1 ], ctrl))
609
+ tasmota.cmd(string.format(" NPWrite 0x%04X ,%d " , PAR_TIMER_BLOCK_AUX [idx- 1 ], ctrl))
610
+ tasmota.cmd(" NPExec" )
578
611
else
579
612
try
580
- ctrl = (compile (" return " + str ( tasmota.cmd(" NPRead 0x010E " ) [' NPRead' ][' Data' ]) )() >> (idx+ 2 )) & 1
613
+ ctrl = (compile (" return " .. tasmota.cmd(string.format( " NPRead 0x %04X " , MBF_RELAY_STATE )) [' NPRead' ][' Data' ])() >> (idx+ 2 )) & 1
581
614
except ..
582
615
tasmota.resp_cmnd_error()
583
616
return
584
617
end
585
618
end
586
- tasmota.resp_cmnd(string.format(' {"NPAux%d ":"%s "}' , idx, ctrl == (parm != " " ? 4 : 0 ) ? self .TEXT_OFF : self .TEXT_ON ))
587
619
end
588
620
589
621
def init ()
622
+ # get tasmota settings
590
623
self .TEXT_OFF = tasmota.cmd(" StateText1" )[' StateText1' ]
591
624
self .TEXT_ON = tasmota.cmd(" StateText2" )[' StateText2' ]
592
- # Add commands
625
+ self .TEXT_TOGGLE = tasmota.cmd(" StateText3" )[' StateText3' ]
626
+ # add commands
593
627
tasmota.add_cmd(' NPBoost' , / cmd, idx, payload -> self .NPBoost(cmd, idx, payload))
594
628
tasmota.add_cmd(' NPAux' , / cmd, idx, payload -> self .NPAux(cmd, idx, payload))
595
629
end
596
630
597
631
def deinit ()
632
+ # remove commands
598
633
tasmota.remove_cmd(' NPBoost' )
599
634
tasmota.remove_cmd(' NPAux' )
600
635
end
601
636
end
602
-
603
- neopool_commands = NeoPoolCommands()
637
+ commands = Commands()
604
638
```
605
639
606
640
To activate the new commands go to WebGUI "Consoles" / "Berry Scripting console" and execute
0 commit comments