Code Monkey home page Code Monkey logo

Comments (8)

StefaanSeys avatar StefaanSeys commented on May 26, 2024 1

That could be implemented using this syntax:

<condition type="x" id="x" op="x" value="on" trigger="ontrue | onfalse | always | never">
  • ontrue = trigger when going from false to true
  • onfalse = trigger when going from true to false
  • always = the current trigger="true"
  • never = the current trigger="false"

from linknx.

2franix avatar 2franix commented on May 26, 2024

I think I understood what you are trying to achieve. But I may be wrong. What I understood is that at sunrise you want to execute action A if a second condition is true and action B is the second condition is false.
If I got it right, then triggers are not to blame. You can do what you need with two rules (one for sunset when other-condition is true, another for sunset when other-condition is false).
You can certainly do it in a single rule with conditional actions but that seems less natural to me.

If I misunderstood what you are aiming to do, please provide me with a XML sample of your config.

from linknx.

WasspOrd avatar WasspOrd commented on May 26, 2024

Thank you for your answer !
My explanation may have been a little tricky.
I actually have two different rules. One for sunrise, and one for sunset. Both have a second condition.
So, at sunrise, if condition 2 is true, I want action A to be executed, and if condition 2 is false, I want action B to be executed. And that's the same thing for my other rule evaluated at sunset.
The fact is that if sunrise is at 8:03:00 :
- at 8:02:59 that condition is "false"
- at 8:03:00 that condition becomes "true", then it trigs my rule, which is evaluated as "true" if condition 2 is also true and execute "if-true" actions, or evaluated as "false" if condition 2 is false and execute "if-false" actions --> And that's what I want
- at 8:03:01 that condition becomes "false", then it trigs my rule, which is evaluated as "false" (because "sunrise" condition is now false, no matter my second condition), and execute "if-false" actions --> And that's what I don't want

Here is the XML sample :

<rule id="LeverSoleilOuvrirVolets" description="Ouvrir les volets au lever du soleil si on est absent" init="false" active="yes">
<condition type="and">
<condition type="timer" trigger="true" >
<at  type="sunrise" offset="10" wdays="1234567"></at>
</condition>
<condition type="object" id="Etat_Presence-Absence" op="eq" value="on" trigger="false" ></condition>
</condition>
<actionlist type="if-true">
  <action type="set-value" value="0" id="Position_Volet-Bureau" delay="" ></action>
  <action type="set-value" value="0" id="Position_Volet-SdB" delay="1" ></action>
  <action type="set-value" value="0" id="Position_Volet-Dressing" delay="2" ></action>
  <action type="set-value" value="0" id="Position_Volet-Chambre" delay="3" ></action>
  <action type="set-value" value="0" id="Position_Volet-Salon_fenetre" delay="4" ></action>
  <action type="set-value" value="0" id="Position_Volet-Salon_baie" delay="5" ></action>
  <action type="set-value" value="0" id="Position_Volet-Cuisine" delay="6" ></action>
  <action type="send-email" to="[email protected]" subject="Fermeture volets automatique ${Temps-Date_actuelle}" var="true" delay="" >Lever du soleil, ouverture automatique des volets. Etat absence : ${Etat_Presence-Absence} Etat Jour : ${Scenes_Linknx-Etat_Jour-Soleil_leve_avec_offset}</action>

</actionlist>
<actionlist type="if-false">
  <action type="send-email" to="[email protected]" subject="Fermeture volets non automatique ${Temps-Date_actuelle}" var="true" delay="" >Lever du soleil, mais présent à la maison, donc pas d'ouverture automatique Etat absence : ${Etat_Presence-Absence} Etat Jour : ${Scenes_Linknx-Etat_Jour-Soleil_leve_avec_offset}</action>

</actionlist>
</rule>

from linknx.

StefaanSeys avatar StefaanSeys commented on May 26, 2024

So what he wants is the timer condition to only trigger when it goes from False to True and not when it switches from False to True...

from linknx.

2franix avatar 2franix commented on May 26, 2024

OK, that was what I understood from your first description.
The only way I can see to address your need is with the two rules below. (I did not test them, there may be syntax errors...)

<rule id="LeverSoleilOuvrirVolets" description="Ouvrir les volets au lever du soleil si on est absent" init="false" active="yes">
  <condition type="and">
  <condition type="timer" trigger="true" >
    <at  type="sunrise" offset="10" wdays="1234567"></at>
  </condition>
  <condition type="object" id="Etat_Presence-Absence" op="eq" value="on"/>
  </condition>
  <actionlist type="on-true">
        <action type="set-value" value="0" id="Position_Volet-Bureau" delay="" ></action>
        <action type="set-value" value="0" id="Position_Volet-SdB" delay="1" ></action>
        <action type="set-value" value="0" id="Position_Volet-Dressing" delay="2" ></action>
        <action type="set-value" value="0" id="Position_Volet-Chambre" delay="3" ></action>
        <action type="set-value" value="0" id="Position_Volet-Salon_fenetre" delay="4" ></action>
        <action type="set-value" value="0" id="Position_Volet-Salon_baie" delay="5" ></action>
        <action type="set-value" value="0" id="Position_Volet-Cuisine" delay="6" ></action>
        <action type="send-email" to="[email protected]" subject="Fermeture volets automatique ${Temps-Date_actuelle}" var="true" delay="" >Lever du soleil, ouverture automatique des volets. Etat absence : ${Etat_Presence-Absence} Etat Jour : ${Scenes_Linknx-Etat_Jour-Soleil_leve_avec_offset}</action>
  </actionlist>
</rule>
<rule id="LeverSoleilNePasOuvrirVolets" description="Ne pas ouvrir les volets au lever du soleil si on est présent" init="false" active="yes">
  <condition type="and">
  <condition type="timer" trigger="true" >
    <at  type="sunrise" offset="10" wdays="1234567"></at>
  </condition>
  <condition type="object" id="Etat_Presence-Absence" op="eq" value="off"/>
  </condition>
  <actionlist type="on-true">
      <action type="send-email" to="[email protected]" subject="Fermeture volets non automatique ${Temps-Date_actuelle}" var="true" delay="" >Lever du soleil, mais présent à la maison, donc pas d'ouverture automatique Etat absence : ${Etat_Presence-Absence} Etat Jour : ${Scenes_Linknx-Etat_Jour-Soleil_leve_avec_offset}</action>
  </actionlist>
</rule>`

from linknx.

2franix avatar 2franix commented on May 26, 2024

Tagging as enhancement for the record. Stefaan's proposal looks consistent. But we have to handle changes on rules with extra care. Further investigation is required.

from linknx.

WasspOrd avatar WasspOrd commented on May 26, 2024

Thank you for the enhancement label !
I already thought about your proposal... But that means multiplying rules, and when you need to change a condition, you have to change it in each other rule... That added to my second "feature request", the workarounds are not elegant at all. :-/

I really think that these two enhancements would greatly make linknx more powerful and useful. To me, linknx will reach perfection for my needs...
But you're right to be careful. I was used to code in C++ 15 years ago, and I'm not skilled anymore... And what I could think to be "quite easy" to implement could be in fact very hard... So, I know that what I'm asking you requires a lot of work, and I really appreciate your attention and your help !

from linknx.

StefaanSeys avatar StefaanSeys commented on May 26, 2024

Been looking at the documentation of linknx, and you could also do this by putting a condition inside the action:

conditional

One condition child elements that is evaluated when the action is executed.
One or more action child elements to execute if condition above is true.
Example

<action type="conditional">
  <condition type="object" id="alarm_email_enabled" value="on" />
  <action type="send-email"  to="[email protected]" subject="Foreign contaminant">Intrusion in your shrubbery!</action>
</action>

So you just repeat the condition that triggered the event inside the action and you effectively have an "ontrue". By reversing the "value" parameter, you get an "onfalse".

Not ideal (because you have to repeat the condition and remember to make changes to both, but will solve your problem.

from linknx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.