logo elektroda
logo elektroda
X
logo elektroda

Inconsistent addRepeatingEvent Behavior for Smart Plug Auto Power Off

lbelleboni 471 5
ADVERTISEMENT
  • #1 21051244
    lbelleboni
    Level 3  

    Ciao.

    I have a not constant work of addRepeatingEvent function; I used it as timeout to power off a smart plug but sometimes works quite fine and sometimes power off in short time.

    The original idea is to power ON a coffee machine in the morning at a fixed time and to power off automatically after 10 minutes. The same if we power ON by web or with the integrated button on smart plug.

    This is the autoexec file:

    // Used channels:
    // Channel 1 - relay1
    // Channel 2 - Btn on device
    // Channel 5 - cycles counter CH1

    //Reduce used module's power
    PowerSave 1

    // NTP driver must be enabled for its functions to work
    startDriver ntp

    // It might be useful to configure a local NTP server on your LAN so that devices do not need to connect to the internet
    ntp_setServer 193.204.114.232

    // Set the local timezone as NTP server only provide UTC time
    ntp_timeZoneOfs 2

    // Setting the devices location will allow for calculating sunrise and sunset times
    //ntp_setLatlong 45.4722 9.1922

    // Time values are available once NTP finishes initializing
    waitFor NTPState 1

    addEventHandler OnClick 2 POWER 1 toggle

    // this will make channel 5 save in memory
    setStartValue 5 -1

    alias turnoff backlog SetChannel 1 0 echo TurnOFF

    //Counter number of power on
    // event triggers for channel 1 changing to 1: set countdown and inc cycles' counter
    backlog addChangeHandler Channel1 == 1 addRepeatingEvent 600 -1 turnoff; addChannel 5 1

    alias turnon backlog SetChannel 1 1 echo TurnON

    //Power on device @6AM
    //[TimerSeconds or Time or sunrise or sunset] [WeekDayFlags] [UniqueIDForRemoval][Command]
    addClockEvent 5:58 0x3e 123 turnon


    and this is the beginning and end log of the state:

    Info:MAIN:Time 1486, idle 72338/s, free 73496, MQTT 0(93), bWifi 1, secondsWithNoPing 1415, socks 2/38 POWERSAVE
    Info:MAIN:Time 1487, idle 69850/s, free 64888, MQTT 0(93), bWifi 1, secondsWithNoPing 1416, socks 3/38 POWERSAVE
    Info:MAIN:Time 1488, idle 75541/s, free 73496, MQTT 0(93), bWifi 1, secondsWithNoPing 1417, socks 2/38 POWERSAVE
    Info:MAIN:Time 1489, idle 66908/s, free 73496, MQTT 0(93), bWifi 1, secondsWithNoPing 1418, socks 2/38 POWERSAVE
    Info:MQTT:Channel has changed! Publishing 1 to channel 1
    Info:EVENT:EventHandlers_ProcessVariableChange_Integer: executing command addRepeatingEvent 600 -1 turnoff
    Info:CMD:addRepeatingEvent: interval 600.000000, repeats -1, command [turnoff]
    Info:MAIN:Time 1490, idle 70175/s, free 73448, MQTT 0(93), bWifi 1, secondsWithNoPing 1419, socks 2/38 POWERSAVE
    Info:GEN:dhcp=0 ip=192.168.1.227 gate=192.168.1.254 mask=255.255.255.0 mac=1c:90:ff:bf:07:66
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-60,ssid=XXXXXX,channel=6,cipher_type:CCMP
    ......
    Info:MAIN:Time 1887, idle 74507/s, free 71304, MQTT 0(118), bWifi 1, secondsWithNoPing 1816, socks 2/38 POWERSAVE
    Info:MAIN:Time 1888, idle 76229/s, free 61752, MQTT 0(118), bWifi 1, secondsWithNoPing 1817, socks 3/38 POWERSAVE
    Info:MAIN:Time 1889, idle 69711/s, free 73448, MQTT 0(118), bWifi 1, secondsWithNoPing 1818, socks 2/38 POWERSAVE
    Info:GEN:CHANNEL_Set channel 1 has changed to 0 (flags 0)

    Info:MQTT:Channel has changed! Publishing 0 to channel 1
    Info:MAIN:Time 1890, idle 71338/s, free 73448, MQTT 0(118), bWifi 1, secondsWithNoPing 1819, socks 2/38 POWERSAVE
    Info:GEN:dhcp=0 ip=192.168.1.227 gate=192.168.1.254 mask=255.255.255.0 mac=1c:90:ff:bf:07:66
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-65,ssid=XXXXXX,channel=6,cipher_type:CCMP
    Info:MAIN:Time 1891, idle 79693/s, free 72520, MQTT 0(118), bWifi 1, secondsWithNoPing 1820, socks 2/38 POWERSAVE
    Info:MAIN:Time 1892, idle 72681/s, free 61752, MQTT 0(118), bWifi 1, secondsWithNoPing 1821, socks 3/38 POWERSAVE

    As you can see the power OFF come after 400" instead of 600".

    What it is wrong?

    Thanks in advance.
    Luca
  • ADVERTISEMENT
  • #2 21052612
    miegapele
    Level 15  

    That's strange problem. Is it always 400 seconds or does time varies? Maybe try disabling Power save?
  • ADVERTISEMENT
  • #3 21055467
    lbelleboni
    Level 3  

    Ciao.

    It's variable all the time.
    I made just now a new test disabling the powersave but the result was the same.

    //Reduce used module's power
    //PowerSave 1

    It is not crucial for me to use this command; I can use another example you made for countdown but the autoexec with this event is very "clean"...

    Thanks for your time.
    Luca
  • ADVERTISEMENT
  • #4 21055946
    miegapele
    Level 15  
    I set up my own spare socket to try if I can get the same behavior, will monitor


    Added after 1 [hours] 41 [minutes]:

    okay, found the issue, you are using incorrect command, this
    
    backlog addChangeHandler Channel1 == 1 addRepeatingEvent 600 -1 turnoff; addChannel 5 1
    

    creates permanent repeating relay turn of every ten minutes. And every button press add another permanent repeating event.
    you should use this:
    
    backlog addChangeHandler Channel1 == 1 addRepeatingEvent 600 1 turnoff; addChannel 5 1
    

    So 1 instead of -1, that makes event fire only once.
    Even better would be to use addRepeatingEventId and cancel old event
  • ADVERTISEMENT
  • #5 21057912
    lbelleboni
    Level 3  

    You are a star!
    it works as should be.

    Just a last question: is there a possibility to see the countdown value?
    Thanks & Regards,
    Luca
  • #6 21058493
    miegapele
    Level 15  

    No, currently there is no way to see countdown value unfortunately.
ADVERTISEMENT