I try increase a varable every incomming update of an ITEM
That is no problem in rules:
for example:
var Number counter = 1
rule “counter is an even Numer”" then do something"
when
Item YYYY changed from OPEN to CLOSED
then
counter = counter + 1
Now I would like to send a command to an item every two events or in other words only when the variable is an even number (or uneven number - but is the same …)
What is the correct syntax for the arithmetic if advise:
if ( counter == even)
didn´t work - but can explain what i’m looking for.
Thanks for helping me.
I´m using at the moment OH2.5.8-1 on a tinkerboard with “buster”
you want a mod operator, normally used as 5 mod 2 = 1, 6 mod 2 = 0 it gives you the remainder after a division operation not the answer. In C# it’s a percent symbol maybe the same in java - yes looks like it might be.
If it’s only to run on even or uneven you can also use a boolean. Instead of + 1 you inverse the value and when testing if the rule should run just test the boolean if (value) {
The problem was the variable declaration!
“var Number” does not work with modulo operator!
You have to use int instead of Number in declaration if you want to use the modulo_operator with the Integer 2.
Thanks all for helping and pointing me to the solution
Summary: Rules solution is:
var int counter = 1
rule EVEN // “counter is EVEN ” then do something"
when
Item YYYY changed from OPEN to CLOSED
then
counter = counter + 1
if (counter % 2 == 0) {
logInfo("Test", "EVEN")
sendcommand ..... //*do something*
} else {
logInfo("Test","ODD")
// *do nothing*
}
var run = true// global variables need to go above all rules in the file
rule "EVEN"
when
Item YYYY changed from OPEN to CLOSED
then
run = !run
if (run) {
logInfo("Test", "true")
sendcommand ..... //*do something*
} else {
logInfo("Test", "false")
// *do nothing*
}
end
@sjheinz hope you didn’t find this offensive (apologies if you did!), this is a legitimate question, just happened that this tweet was popular just a few days ago, and it was just sarcasm
That´s why i use the communitiy web and not twitter!
I thing in generell The comunnity should focus in one support szenario and not in every! Same as the system, they work on every stage and nowhere in a good stable shape! that is not sarcasm - unfortunately from simple user point of view