I have configures various buttons (timer). But as soon as one of the button is pushed, it stays in this “active mode” (the red buttons) despite the timer is gone.
Is there a possibility that this button goes back to “inactive” (blue button) as soon as the timer is expired?
Whatever state the Item is in determines which button is highlighted. I’ve not done this myself, but once the timer goes off if you set the Item to a state that is not in your MAPPINGS on the sitemap theoretically none of the buttons should be highlighted. I’ve never tried it though so can’t say for sure that will happen.
Just do a myItem.sendCommand(0) or some other state that isn’t in the mappings as the last thing your timer does.
Hey John,
Rich is completely right, that’s how I do it with a bunch of buttons.
rule "Demo Unset Buttons"
when
Item Buttons received command
then {
switch (receivedCommand){
case 0: ...
case 1: ...
case 2: ...
}
createTimer(now.plusSeconds(3)) [|
Buttons.postUpdate(-1)
]
}
end
A few notes:
you can set the item to whatever you like, it just has to be not part of your mappings (-1, 3, 99,…).
the Timer is not needed! It is just my personal preference to have a short delay.
Hi.
thx for the example.
But i could’t get it to work.
Thats what I did.
rule "Vaccum Wohnzimmer Reset"
when
Item VacuumRoboterWohnzimmer received command
then {
switch (receivedCommand){
case 0 : VacuumRoboterWohnzimmer.sendCommand(ON)
case 1 : VacuumRoboterWohnzimmer.sendCommand(OFF)
}
createTimer(now.plusSeconds(3)) [
VacuumRoboterWohnzimmer.postUpdate(-1)
]
}
end
If it is a Switch then this Rule will never do anything because receivedCommand will never be 0 or 1. A Switch can only be ON/OFF.
Similarly, if it is a Number then you can’t sendCommand(ON) or sendCommand(OFF) so you should see errors in your log.
But assuming that both of these were set, you would end up with an infinite loop. The Rule triggers on a command and then you immediately send a command to that same Item.
The Item you send the command to in the case statements must be a DIFFERENT Item from the one that triggered the Rule.
Of course it can be done. Just not the way you are trying to do it.
rule "Vaccum Wohnzimmer Reset"
when
Item VacuumRoboterWohnzimmer received command ON
then
createTimer(now.plusSeconds(3)) [
VacuumRoboterWohnzimmer.postUpdate(OFF)
]
end
Notice the following:
You don’t put curly barckets after the then and before the end.
The Item is a Switch. It only has ON/OFF as states. No numbers.
Any mappings you have in your sitemap only affect how it is displayed, not the actual Item’s state
The above will turn off the VacuumRoboterWohnzimmer Item after three seconds, but it only does an update so the OFF command doesn’t get sent to the actual device.
However, there is an even easier way give the Expire binding:
at first i tried it at a rule with nearly the same code as mentioned here - the online difference was, that i was using sendCommand.
In the rest-api i also tried out updating the state - without success. today i tried it again and it works fine now in rest-api and in the rule (both with postUpdate command).
i dont know what my mistake was, but i am happy that it is working now.