Menu

rule does only work once with lua action

Help
Ronny H
2010-04-05
2012-12-14
  • Ronny H

    Ronny H - 2010-04-05

    Hi

    in my last question, i used a electric meter. Now i will convert this value always to a smaller value. This is not the problem. But i see that my defined condition in the rule only work once. I did not find the problem. Can anyone help me?

    <objects>
      <object id="bigenergie" gad="1/6/216" type="29.xxx" init="persist">bigenergie</object>
      <object id="smallenergie" gad="1/6/218" type="EIS11" init="persist" forcewrite="true">smallenergie</object>
    </objects>
    <rules>
      <rule id="energy_convert">
        <condition type="object" id="bigenergie" trigger="true"/>
        <actionlist>
          <action type="script">
            value = tonumber(obj("bigenergie"));
            lowvalue = math.floor(value/1000);
            set("smallenergie", lowvalue);
          </action>
        </actionlist>
      </rule>
    </rules>
    

    In the logfile i can see only the first action of the rule:

    1270471643 INFO KnxConnection : KnxConnection: Group socket opened. Waiting for messages.
    1270471682 INFO Object : New value 3511860 for object bigenergie (type: 29.xxx)
    1270471682 INFO Condition : ObjectCondition (id='bigenergie') evaluated as '1'
    1270471682 INFO FilePersistentStorage : Writing '3511860' for object 'bigenergie'
    1270471682 INFO Action : Execute LuaScriptAction
    1270471682 INFO KnxConnection : write(gad=3802, buf, len=6):
    1270471682 INFO Object : New value 3511 for object smallenergie (type: 12.xxx)
    1270471682 INFO FilePersistentStorage : Writing '3511' for object 'smallenergie'
    1270471753 INFO Object : New value 3512110 for object bigenergie (type: 29.xxx)
    1270471753 INFO Condition : ObjectCondition (id='bigenergie') evaluated as '1'
    1270471753 INFO FilePersistentStorage : Writing '3512110' for object 'bigenergie'
    1270471756 INFO Object : New value 3512120 for object bigenergie (type: 29.xxx)
    1270471756 INFO Condition : ObjectCondition (id='bigenergie') evaluated as '1'
    1270471756 INFO FilePersistentStorage : Writing '3512120' for object 'bigenergie'
    1270471801 INFO Object : New value 3512270 for object bigenergie (type: 29.xxx)
    1270471801 INFO Condition : ObjectCondition (id='bigenergie') evaluated as '1'
    1270471801 INFO FilePersistentStorage : Writing '3512270' for object 'bigenergie'
    

    regards Ronny

     
  • jef2000

    jef2000 - 2010-04-05

    Hi,

    It's because the action is executed only when the condition changes from false to true. Since the condition you use will always evaluate to "true", the action is only executed once. That's one of the reasons why I added "stateless" rules in 0.0.1.27. If you use that version or a more recent one, you can add the parameter  type="if-true"  in the actionlist tag (the default is  type="on-true" ). With that parameter, the action will be executed every time the condition is evaluated to "true".

    Jean-François

     
  • Ronny H

    Ronny H - 2010-04-05

    Hi

    the parameter was the missed thing. It works now!

    <actionlist type="if-true">...</actionlist>
    

    Thanks!

     
  • hd88

    hd88 - 2010-04-05

    hello hronny,

    how it works:

    <rules>
      <rule id="energy_convert">
      <condition type="object" id="bigenergie" trigger="true"/>
      <actionlist type="if-true">
      <action type="script">
         value = tonumber(obj("bigenergie"));
         lowvalue = math.floor(value/1000);
         set("smallenergie", lowvalue);
      </action>
      </actionlist>
      </rule>
    </rules>

    hans

     
  • Ronny H

    Ronny H - 2010-04-05

    Yes i know, thanks :-)

    Ronny

     

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.