Menu

Timercondition + LUA script

Help
uidas
2010-01-21
2012-12-14
1 2 > >> (Page 1 of 2)
  • uidas

    uidas - 2010-01-21

    Hi,

    I have several rules with the following scructure:

            <rule id="Prog1P1_rule">
                    <condition type="timer" trigger="true">
                            <at type="variable" time="Prog1P1_timer"  />
                    </condition>
                    <actionlist type="if-true" >
                            <action type="script">
                                    actuar=0
                                    if ( obj("es_festivo") == "on" ) then
                                            if ( obj("Prog1P1_festivo_enabled") == "on" ) then actuar=1 end
                                    else if ( os.date("%w") == "6" ) then
                                            if ( obj("Prog1P1_sabado_enabled") == "on" ) then actuar=1 end
                                         else if ( os.date("%w") == "0" ) then
                                                    if ( obj("Prog1P1_domingo_enabled") == "on" ) then actuar=1 end
                                              else if (obj("Prog1P1_laborable_enabled") == "on" ) then actuar=1 end
                                              end
                                         end
                                    end
                                    if (actuar == 1) then
                                            if ( obj("Prog1P1_tempdisable") == "on" ) then
                                                    set("Prog1P1_tempdisable","off")
                                            else
                                                    val=obj("Prog1P1_accion")
                                                    set("D35.8 1.3-A. Pasarela",val)
                                            end
                                    end
                           </action>
                    </actionlist>
            </rule>
    

    Prog1P1_timer has stateless flag

    Using linknx-SVN (compiled last week)

            <logging format="simple" level="INFO"/>
    

    No problem with first rule execution, then reschedules for next day,  but some times does not execute and linknx shows the following message several times:
    2010-01-21 09:38:00  TimerManager: TimerTask skipped due to clock skew or heavy load. 1263992400

    Thanks

     
  • JensH

    JensH - 2010-01-21

    Hi,
    serious question: are you sure your time-settings are correct and you don't have issues with NTP-autoupdate?
    Background: in the past I struggled for some time with a timer in the morning with the same error message until I found out, that my internet connection went down in the morning (=DSL reconnect) - afterwards the cron-job pulled and sat an incorrect time ….
    Linknx threw away the trigger for the timer and rescheduled the task to the next day… and half an hour the cronjob received the correct time. It took some time to find out… ( I checked the code and therefore I understood how the timer worked)
    Best Regards, auto-mate

     
  • jef2000

    jef2000 - 2010-01-21

    Hi,

    What's the value of object "Prog1P1_timer"? Is it changing or always the same?
    I see that the trace is logged at "2010-01-21 09:38:00" and the timestamp at end of log message 1263992400 mean "Wed, 20 Jan 2010 13:00:00 GMT". Can you give also the other traces before and after that one? Are the date/time of log messages always increasing or do you see some backward time-jumps? In which time zone are you located?

    Regards,

    Jean-François

     
  • uidas

    uidas - 2010-01-22

    Hi,

    Prog1P1_timer is a persistent object, It can be changed from knxweb. I set it to 09:35:00. I have 3 more rules at 09:36:00, 09:37:00 and 09:38:00, but errors are all shown at 09:38:00. none of the previous rules are executed.
    What I've done/seen:
    1. Start linknx
    2. Change Prog1P1_timer value (knxweb)
    3. Fist rule execution OK. Then reschedules for next day.
    4. Second rule execution often goes bad. Reschedules several minutes later.

    linknx is running on a XEN paravirtualized SuSE Linux Enterprise Server. Server's clock is synchronized with virtualization host's clock. I didn't have problems with any other time critical servers or services. Otherwise, I'm checking and testing clock and NTP settings.

    I'll also check timestamps of log messages and save traces.

    Thanks

     
  • uidas

    uidas - 2010-02-15

    Hi,
    i've checked clock and ntp updates. Changed clock settings to NTP sync. Every time I execute ntpupdate I got a time offset lesser than -0.05 sec. 

    My time zone is GMT+1 (Spain)

    Log sample below:

    error output:
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264455300
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264460340
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264460400
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264460400
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264460400
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264460400
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264485900
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264500960
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264486020
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264486080
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264486140
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264487100
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264489200
    2010-01-26 11:17:00 [ WARN] TimerManager: TimerTask skipped due to clock skew or heavy load. 1264490100
    linknx output:
    2010-01-26 11:17:00 [ INFO] TimerManager: TimerTask execution. 1264501020
    2010-01-26 11:17:00 [ INFO] Condition: TimerCondition evaluated as '1'
    2010-01-26 11:17:00 [ INFO] Condition: TimerCondition evaluated as '0'
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 11:17:0 (1264587420)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-26 22:35:0 (1264541700)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-26 23:59:0 (1264546740)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 0:0:0 (1264546800)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 0:0:0 (1264546800)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 0:0:0 (1264546800)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 0:0:0 (1264546800)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 7:5:0 (1264572300)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 11:16:0 (1264587360)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 7:7:0 (1264572420)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 7:8:0 (1264572480)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 7:9:0 (1264572540)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 7:25:0 (1264573500)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 8:0:0 (1264575600)
    2010-01-26 11:17:00 [ INFO] PeriodicTask: Rescheduled at 2010-1-27 8:15:0 (1264576500)
    2010-01-26 11:17:00 [ INFO] Action: Execute LuaScriptAction
    

    Some rules doesn't execute then,  when one is executed and previous rules are rescheduled.

    Best Regards

     
  • jef2000

    jef2000 - 2010-02-15

    Hi,

    Now I understand a bit more your problem. The linknx timer system uses a queue where all the TimerTasks are stored in the order they are supposed to happen. The timer looks only at the scheduled time of the first task and only when that task is executed it starts looking at the next one. In your case, it seems that the tasks are stored in the queue in a wrong order. So when the task at 11:17 executes, the next one is considered, the system see that is was supposed to be executed yesterday at 22:35 and think there was a clock problem. Now I still have to figure out why the tasks end up in the wrong order in the queue.

    To be continued…

     
  • uidas

    uidas - 2010-02-16

    Hi,  I have several objects like "Prog1P1_timer". I suppose linknx read its value when starts. But, sometimes I change its value from knxweb. "Prog1P1_timer" is variable timer object.

     
  • jef2000

    jef2000 - 2010-02-16

    I think I found the bug. When the time is modified (using knxweb), the timer condition is rescheduled using the new time, but I forgot to remove it from the timer queue before reschedule, so the task is twice in the  queue, and one of them is at the wrong place. If it's correct, you should only see the problem after  you modify one of the timers with knxweb.
    I'll try to fix it in CVS soon.

    Regards,

    Jean-François

     
  • Ben

    Ben - 2010-02-23

    Hi,

    Like uidas, I've got rules that sometimes do not execute.
    I use linknx syno-x07 ipk on my ds207+, and my log file give me no indication.

    How could I improve my log file ?

    Thanks.

    Ben

     
  • JensH

    JensH - 2010-04-15

    Hi Jean-Francois,
    have you already fixed this?
    I have compiled the sources 2 days ago and I still have a similar problem.
    (sometimes with sunset / sunrise triggers but also with "time-counter"  triggers.)
    Is it possible, that a "time-counter"-kind of  conditions create this wrong orders?
    i saw, you have created something to read rule / timer status. How can I use this?

    Thanks, best Regards, Jens

     
  • jef2000

    jef2000 - 2010-04-16

    Hi,

    Yes, I fixed the issue I discovered, but there could be other bugs.
    If you want tu check the rule / timer status, you can use the <read><status/></read> command on the XML interface.
    This will give you the chronological list of timer tasks to be executed in the future. If the order is wrong, that means there is still something to fix there.
    It will also give the internal state of all rules (the one that's used to execute "on-true" and "on-false" actions only when a state change is observed)

    Kr,

    Jean-François

     
  • JensH

    JensH - 2010-04-16

    Ok, I'll test this. I don't know yet, how to access the XML interface, but I'll find out (I guess I have to use the linknx.php in some apache and assume, that the linknx.php shows some dialog, where I can enter the command?
    (I have no clue of php)
    This morning I had 3 skipped timers at sunrise. (I scan now daily for "skew" in the log files)
    Will keep you posted.
    Thank you for the work and permanent support of "users" like me :-)
    Best Regards, Jens

     
  • jef2000

    jef2000 - 2010-04-16

    To show status in php, you can put something like this in a php file (e.g. status.php):
    I hope sourceforge forum will not mess all the text formatting….
    I just wrote it based on another example php file. I hope I didn't make errors. I'll test it this evening.

    <html>
    <head>
    <title>Linknx status</title>
    </head>
    <body>
    <?php
    function knxstatus($fp)
    {
        $in = "<read><status/></read>\n\4";
        fwrite($fp, $in);
        $ret = '';
        $cnt = 0;
        while ($cnt < 1000 && $fp && !feof($fp)) {
            $ret .= fgets($fp, 128);
            $c = fgetc($fp);
            if ($c == "\4") {
                break;
            }
            $ret .= $c;
            $cnt++;
        }
        return $ret;
    }
    $address = "127.0.0.1";
    $port = 1028;
    $fp = fsockopen($address, $port, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    }
    else {
        $status = knxstatus($fp);
        echo "$status"
    fclose($fp);
    }
    ?>
    </body>
    </html>
    
     
  • JensH

    JensH - 2010-04-16

    Hi,
    when I use

    $in = "<read><config/></read>\n\4";
    

    I get the list of objects back in the browser. (therefore php / XML seems to work in general)
    When I use

    $in = "<read><status/></read>\n\4";
    

    I just get a blank screen.
    Hm, can you help me?
    Thanks, best Regards, Jens

     
  • jef2000

    jef2000 - 2010-04-16

    Hi,

    I think the code is working, but the result is not shown in the browser because the XML tags look like html tags and are ignored.
    You can replace:
    $status = knxstatus($fp);
    by:
    $status = htmlspecialchars(knxstatus($fp));
    To fix it.

    Or you can just look at the HTML source of the page.

    Kr,

    Jean-François

     
  • jef2000

    jef2000 - 2010-04-16

    Here's another PHP tool to send and receive XML commands:

    http://ouaye.net/linknx/other/linknx-cmd-php.txt

    You can fill the command box by clicking the buttons or writing our own XML then press Exec button to send it to linknx.

    Kr,

    Jean-François

     
  • JensH

    JensH - 2010-04-16

    Thanks for your patience with guys like me :-)
    I have monitored my system in the last few hours. Here are the results. (and possible the reason for the problem).
    I use a time-counter rule to let the control automatically detect, when nobody is at home. For this I monitor 3 motion detectors.
    After 8 hours of no-motion, the "away" mode is triggered. (we have kids - 8h is a long time :-)
    here is the code:

        <rule id="Is_Away_8h"> 
            <condition type="time-counter" threshold="8h">
                <condition type="and">
                    <condition type="object" id="EG_Flur_Bewegung_Meldung" value="off" trigger="true" />
                    <condition type="object" id="OG_Flur_Bewegung_Meldung" value="off" trigger="true" />
                    <condition type="object" id="DG_Flur_Bewegung_Meldung" value="off" trigger="true" />
                </condition>                    
            </condition>                    
            <actionlist>
                <action type="set-value" id="Status_Abwesend_8h" value="on" />
            </actionlist>       
        </rule>
    

    …i.e. if all 3 detectors are "off" at the same time, the countdown starts and after 8 hours it reaches "away".

    I used <read><status><timers/></status></read> with the XMLServer to check the timers:
    Result & Problem:
    Before midnight I had more than 140 timers in the list. The overall XML.response had overall ~150timers listed. (probably also some XML / browser buffer issue occured, because the later timers were missing…but this shouldn't be the focus.
    As I said: I had many - exactly the same -  lines as the following:

    <task type="time-counter" next-exec="2010-4-17 7:30:43" counter="0"> <condition type="and"> <condition type="object" id="EG_Flur_Bewegung_Meldung" value="off" trigger="true" /> <condition type="object" id="OG_Flur_Bewegung_Meldung" value="off" trigger="true" /> <condition type="object" id="DG_Flur_Bewegung_Meldung" value="off" trigger="true" /> </condition> </task>
    

    After Midnight some cleanup occured and the list was shortened, but still contained doubled entries now with updated times.

    It seems, that the following happens: (I checked at 4 different timestamps)
    With each trigger of "my" time-counter rule above, a new(!) task is added to the list.
    The new task is inserted in the correct timely place in the task-list. BUT: the other entries stay in the list in their place, but are updated with the new calculated "threshold" time.
    -> that's the reason, why the overall list gets out of order… and the timermanager waits until the first task is due for execution (i.e. the updated threshold time) … executes it  (many times?) …and finds then tasks, which should have come before.

    Does this help to fix the problem?
    (and I really like the tresholds!!!!!!)
    Thanks Jean-Francois!

    Best Regards, Jens

     
  • jef2000

    jef2000 - 2010-04-17

    You are right. That's the same problem as with variable timers. I'll fix it soon.

     
  • jef2000

    jef2000 - 2010-04-17

    Fix added to CVS (not tested).

     
  • JensH

    JensH - 2010-04-18

    Hi,
    it seems to work. I have compiled the changed version this afternoon and after dozens of reschedules of time-counters, the timer-list is still stable.
    Thanks!!!
    Best Regards, Jens

     
  • hd88

    hd88 - 2010-04-18

    Hi,
    The linknx version from CVS finished with it:
    Memory access error when using with Knxweb
    the rule will be displayed.
    Best Regards, Hans

     
  • Ben

    Ben - 2010-04-19

    Hi all

    This xml request :

    <read><status/></read>\n\4
    

    returns me this :

    <read status='error'>Unknown read element</read>
    

    Any idea?
    I use th syno-x07 linknx binaries.

    Thanks,
    Ben

     
  • jef2000

    jef2000 - 2010-04-19

    Hi,

    This feature is not yet released. It will be part of 0.0.1.28.
    Now it's only available if you get the latest sources from CVS and compile it yourself

    Regards,

    Jean-François

     
  • uidas

    uidas - 2010-06-01

    I've also tested CVS linknx version for weeks. Several reschedules. Working fine.

    Thanks.

     
  • JensH

    JensH - 2010-06-01

    Hi Jean-Francois,
    I've also tested the CVS over some weeks now, but there is still a (different) bug. I was sometimes missing after some certain timeframe some timers especially in the morning.
    To identify the problem, I have created a script, which logs the timer-status every 2 hours.
    Analysis and cause of the problem:
    I have implemented some "away"-functionality which is done with time-counters (see above: https://sourceforge.net/projects/linknx/forums/forum/743670/topic/3525849  mailing  #17):
    When these are "removed" after execution from the timerlist, the following timer is also removed from the list forever.
    Could you please check?
    Thanks, Best Regards, Jens

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.