I have Simon blinds controller, which works with Zwave.
In the morning I have Alexa raising the blinds to 3% but then I always have to manually click quickly on the down button to close a little the blinds, so that they are not fully oppened (on the horizontal pads or whatever the name of that thing).
Well, anyway, this is what I want to do: Each time blinds go UP, whether clicking on the button manually or via OH or whatever, I want it to go DOWN for only 0.3 seconds.
I have setup this rule but problem is, if I remove the STOP trigger, this won’t start and if I setup with STOP rule, then this will always be triggered in an infinite loop.
var Timer offTimer = null
rule "Fechar ligeiramente estores escritorio"
when
Item brisa_escritorio received command UP or
Item brisa_escritorio received command STOP
then
offTimer = createTimer(now.plusSeconds(5), [|
sendCommand(brisa_escritorio, DOWN)
])
offTimer = createTimer(now.plusMillis(300), [|
sendCommand(brisa_escritorio, STOP)
])
end
First of all .3 seconds is just not going to happen. OH cannot respond that fast and more importantly, it will take longer than that for the Zwave device to report the button was pressed and for your stop command to be sent in response. If this can be done is less than a second I’ll be surprised.
Beyond that, check to see if the receivedCommand is STOP and only schedule the timer if it isn’t. That will break the loop.
I basically solved the problem, but now I have another one.
My other problem is: what if I want blinds to go all the way up? I’ve just tested and it stops after those 5 seconds and starts going ALL THE WAY DOWN (WOT?!?).
I’ve now changed my cod to this:
var Timer offTimer = null
rule "Fechar ligeiramente estores escritorio"
when
Item brisa_escritorio received command UP
then
offTimer = createTimer(now.plusSeconds(5), [|
sendCommand(brisa_escritorio, DOWN)
offTimer = createTimer(now.plusMillis(400), [|
sendCommand(brisa_escritorio, STOP)
])
])
end
This is working. The STOP function always work now, I even had to change from 300 to 400 because it was just not closing enough. 1 second it’s too much time and it closes more than I want, so that’s why I want it specifically to close a certain way.
Problem here now is only that this will stop going UP when it’s active and going UP.
Is it possible to make it move 0.5% instead of 1%? Because if that’s possible, then that may be the solution for this problem because I wouldn’t need to have this milliseconds and I could put it waiting on the first part 1 minute to guarantee that it has time to fully reach the top if that’s the case.
Only if you have an Item linked to a Channel that tells you that it’s in motion. Then you can have an if statement to ignore the event if it’s already in motion.
I can’t say. I don’t have this device. I don’t know how it works. But assuming that the device reports it’s current position, I would expect that Channel to provide that information.
I chosed to increase the time waiting on the first part to 1 minute so that it gives time for blinds to go all the way up. So this is solved and here’s the final code:
var Timer offTimer = null
rule "Fechar ligeiramente estores escritorio"
when
Item brisa_escritorio received command UP
then
offTimer = createTimer(now.plusMinutes(1), [|
sendCommand(brisa_escritorio, DOWN)
offTimer = createTimer(now.plusMillis(400), [|
sendCommand(brisa_escritorio, STOP)
])
])
end
Although I will mark this topic as solved, because this solves the problem, I still have a different question here.
What if I really want to leave it all the way open without it slides this little bit (meaning, not running this rule)? Can you think of a way to do this?
Thank you for your help, but I just leave it with a timer of 1 minute and that’s enough for my case.
Also, when I arrived to the office this morning I noticed the blinds were not as I wanted. So I went to investigate and had to change my code for this, which now allows me to set it how I want, order it to stop and it will just not run the rule and leave the blinds as I wanted.
var Timer offTimer = null
rule "Fechar ligeiramente estores escritorio"
when
Item brisa_escritorio received command
then
if(receivedCommand !== DOWN
&& receivedCommand !== STOP
&& receivedCommand !== 0
&& receivedCommand !== 100) {
offTimer = createTimer(now.plusMinutes(1), [|
sendCommand(brisa_escritorio, DOWN)
offTimer = createTimer(now.plusMillis(400), [|
sendCommand(brisa_escritorio, STOP)
])
])
}
end
So that’s it, this topic is now fully solved and with the solution for future reference.
That’s true in JavaScript but not Rules DSL. Your overall description on the difference about what === and !== means is generally correct, but in Rules DSL "ON" == ON will not return true. In Rules DSL, === only returns true if the operand on the left is pointing at the exact same Object (i.e. same place in memory) as the operand on the right. Thus, it can make sense to use === with enumerated types like ON/OFF but you should never use it in any other case. In general though, there is a whole bunch of stuff going on behind the scenes that might make the ON carried by an Item come from some other instance of OnOffType than the instance of OnOffType imported into the Rules context. If that were to occur, MySwitch.state === ON could return false even when MySwitch.state is ON.
Therefore the recommendation is to only use === and !== when null is one of the operands. In all other cases, even for enum types, use == and != in Rules DSL.
When using Scripted Automation, use what ever is correct and makes sense for the language you are using, only be aware that many of the Objects you will be working with are Java Objects so they may or may not behave as expected.