Ciao
Thanks for your wonderful job! Congratulations.
But... I need your help.
I need to use the dimmer as a normal switch, so I modify the autoexec.bat file in order to:
- Accept the toggle signal from the external electrical switch
- Accept the on/off command from Alexa (Wemo simulation)
- Use an automatic delay off of 2hr
I run it but:
- The switch runs all the time I reset the system; it seems that does not look to last state (SetStartValue 1 -1) or force power off (SetStartValue 1 0).
- Sometimes the system starts without reason
- The lamps start to blink (they are not dimmable) without reason
Maybe the two subroutines can't run together?
Thanks in advance.
Luca
This is my Autoexec:
//P0 = Switch extern
//P7 = Switch intern (fix to CH 0 so, not used)
//P8 = LED (Wifi_N)
//P24 = DIM- (NOT Used)
//P26 = DIM+ (NOT Used)
//CH10 = timer for poweroff
// this is not really tuyaMCU but we will treat it as such
startDriver TuyaMCU
// set baud rate
tuyaMcu_setBaudRate 115200
//Activate driver for wifi
startDriver SSDP
//Activate driver to simulate WEMO
startDriver WEMO
//Add powersave
//PowerSave 1
// display seconds timer
setChannelType 10 TimerSeconds
// set start values as "remember in flash"
// 0= POWER OFF 1= Remember last state
SetStartValue 1 -1
// 0= timer to zero
SetStartValue 10 60
//Check if timer expired
alias do_check if $CH10==0 then setChannel 1 0
alias do_tick backlog addChannel 10 -1; do_check
// create a toggle and a dimmer
setChannelType 1 toggle
//Dimmer slider Not used
//setChannelType 2 dimmer256
// invoke refresh on change
addEventHandler OnChannelChange 1 startScript autoexec.bat refresh
//addEventHandler OnChannelChange 2 startScript autoexec.bat refresh
refresh:
//Start timer or reset timer (7200 = 2h)
if $CH1==1 then setChannel 10 7200
if $CH1==0 then setChannel 10 0
// channel 5 is a temporary variable, from 0 to 255*3, multiplied also by toggle value
//setChannel 5 $CH2*3*$CH1
// split into two bytes
//setChannel 3 $CH5/256
//setChannel 4 $CH5%256
//FIX always the max value (ON) or zero (OFF)
setChannel 3 1*$CH1
setChannel 4 256*$CH1
// send the two bytes
tuyaMcu_sendCmd 0x30 00$CH3$$CH4$
again:
if $CH10!=0 then do_tick
delay_s 1
goto again