Menu

Simplify rules by using a script?!

netsrac69
2011-11-04
2012-12-14
  • netsrac69

    netsrac69 - 2011-11-04

    Okay…one last thing for today :-)

    I have the following rule sets which are used to combine various Window Status Displays using BJs Waveline Window sensors. If a window is open, it's sending a 255, if it's just flip-open, it's sending 89 and if it's closed, it's sending a 0.

    You can use the same values to show the status via a LED - 0 = green, 89 = yellow, 255 = red.

    I now use the below rule set to combine the sensors, so the highest value is always the one that counts.

    I'm pretty sure that there is an easier way using Lua scripting.I tried it once, but debugging is a pain :-)

    Basically you would need to get the highest value of the sensors - so something like:

    value = max(Sensor1, Sensor2, Sensor3);
    set("status", value)

    should do the trick.

    Any ideas?

      <rule id="WaveLine_Status_Gesamt_DG_open">
        <condition type="or">
            <condition type="object" id="WavelineFensterDGTerrasse" value="255" trigger="true" />
            <condition type="object" id="WavelineFensterDGStrasse" value="255" trigger="true" />
            <condition type="object" id="WavelineFensterDGBad" value="255" trigger="true" />
        </condition>
        <actionlist>
          <action type="set-value" id="WavelineStatusGesamtDG" value="255" delay="1s" />
        </actionlist>
      </rule>
      <rule id="WaveLine_Status_Gesamt_DG_close">
        <condition type="and">
            <condition type="object" id="WavelineFensterDGTerrasse" value="0" trigger="true" />
            <condition type="object" id="WavelineFensterDGStrasse" value="0" trigger="true" />
            <condition type="object" id="WavelineFensterDGBad" value="0" trigger="true" />
        </condition>
        <actionlist>
          <action type="set-value" id="WavelineStatusGesamtDG" value="0" delay="1s" />
        </actionlist>
      </rule>
      <rule id="WaveLine_Status_Gesamt_DG_kipp">
        <condition type="and">
          <condition type="not">
            <condition type="object" id="WavelineFensterDGTerrasse" value="255" trigger="true" />
          </condition>
          <condition type="not">
            <condition type="object" id="WavelineFensterDGStrasse" value="255" trigger="true" />
          </condition>
          <condition type="not">
            <condition type="object" id="WavelineFensterDGBad" value="255" trigger="true" />
          </condition>
          <condition type="or">
            <condition type="object" id="WavelineFensterDGTerrasse" value="89" trigger="true" />
            <condition type="object" id="WavelineFensterDGStrasse" value="89" trigger="true" />
            <condition type="object" id="WavelineFensterDGBad" value="89" trigger="true" />
          </condition>
        </condition>
        <actionlist>
          <action type="set-value" id="WavelineStatusGesamtDG" value="89" delay="1s" />
        </actionlist>
      </rule>
    
     
  • Anthony

    Anthony - 2011-11-04

    hi,

    Sensor1=obj("Sensor1");
    Sensor2=obj("Sensor2");
    Sensor3=obj("Sensor3");
    value = math.max(Sensor1, Sensor2, Sensor3);
    set("status", value)
    

    you can look at :
    http://www.lua.org/manual/5.1/manual.html
    http://lua-users.org/wiki/MathLibraryTutorial

    Anthony.

     

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.