ady624 / CoRE

CoRE - Community's own Rule Engine
GNU General Public License v3.0
222 stars 663 forks source link

Loops #16

Closed krlaframboise closed 8 years ago

krlaframboise commented 8 years ago

This isn't a bug or feature request, but you said I should post it here so it doesn't get lost...

Any suggestions on how to implement the logic below or if it's even possible at this point?

IF Contact changes to closed
  set x = 0

while contact is closed and x < 5
  wait 4 minutes
  for 0 to x
    using siren
        speakText("beep ${x * 50}")
        wait 1 second
  x++

I'm trying to avoid having to do something like:

If Contact is closed
  Using Siren
    wait 4 minutes
    beep 0
    wait 4 minutes
    beep 50
    wait 1 second
    beep 50
    wait 4 minutes
    beep 100
    wait 1 second
    beep 100
    wait 1 second
    beep 100
    wait 4 minutes
    beep 150
    wait 1 second
    beep 150
    wait 1 second
    beep 150
    wait 1 second
    beep 150
    etc...
else
  using siren
    cancel pending actions
ady624 commented 8 years ago

Let's add the variable formatting here too? :) Some of the above functionality can be achieved by using Follow-Up pistons, but that would be cumbersome. Haven't given up the idea of having loops. There is also a "Repeat whole action" task that would repeat all the tasks of an action indefinitely. Loops are close.

krlaframboise commented 8 years ago

I actually got the beeping escalation portion to work using the repeat action and a variable that gets incremented each time it ran, but I couldn't find a way to use that variable to make it stop repeating. I'll play around with the new Follow-Up piston feature tonight.

Variable Formatting:

Last week a user reported the Thermostat Operating State wasn't evaluating to true, but it ended up being because the SmartThings DTH they were using sets that attribute to something like "cooling to 74F" instead of just "cooling".

Considering how flexible CoRE is, I wanted to see if I could create a way to get around that so I created a variable that stored the thermostat operating state in it. I also created a variable that combined the words "cooling to " with the cooling setpoint and the temperature unit.

If the Thermostat Operating State is cooling, those variables should have the same value.

Unfortunately I wasn't able to get it to work because when the cooling setpoint was saved to the variable, it formatted it as 74.0 instead of 74 so that's the main reason I asked about the ability to format variables.

The ability to apply regular expressions would be really cool, but that's probably pushing it...

ady624 commented 8 years ago

I can add a few more comparisons for strings:

contains does not contain starts with does not start with ends with does not end with matches pattern (regexp) - nothing is "pushing it"

One other thing I could do is modify the cast from string to int/float to remove all non-digit characters before attempting to convert. This would fix your problem.

krlaframboise commented 8 years ago

I think adding those comparisons options would be a huge help.

The matches pattern comparison should allow you to compare anything you want so removing the non-digit characters probably isn't need and might not be wanted in some situations.

Edit: You said "modify the cast from string to int/float to remove all non-digit characters", wouldn't that be the other way around or did I misinterpret what you were suggesting?

Would the matches pattern comparison have an implicit cast to string so it would work with all data types?

ady624 commented 8 years ago

Can this be closed?

krlaframboise commented 8 years ago

Yes, it works exactly as I hoped it would. Thanks.