[Solved] How to reset the state of UI buttons?

Dear all

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?

Thanks & Regards
John

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.

If that doesn’t work then the answer is “no”.

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.
2 Likes

That was the hint that I needed :slight_smile:
Thank you @ThomDietrich and @rlkoshak

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

Any hints?
Greetings

Did you already restart openHAB? Sometimes the UI is no longer updated automatically after making some changes to the configuration.

What type of Item is VacuumRoboterWohnzimmer?

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.

Thx for replys!!!
mmmh
this is the item:

Switch	VacuumRoboterWohnzimmer "Vacuum Cleaner Wohnzimmer"	{mqtt=">[mosquitto:Openhab/out/set/Vacuum/Wohnzimmer/command:command:ON:2], >[mosquitto:Openhab/out/set/Vacuum/Wohnzimmer/command:command:OFF:1]"}

I would like to start the robot.
Its like starting a Scene but without response status.
In the Sitemap i have to mappings for “2” and “1” .

To sumerize:

I only want to push a button in basicUI send out mqtt command (this works) and after that reset the the button on the sitemap.
…that could’t be done?

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:

Switch	VacuumRoboterWohnzimmer "Vacuum Cleaner Wohnzimmer"	{mqtt=">[mosquitto:Openhab/out/set/Vacuum/Wohnzimmer/command:command:ON:2], >[mosquitto:Openhab/out/set/Vacuum/Wohnzimmer/command:command:OFF:1]", expire="3s,state=OFF" }
1 Like

Thy a lot for helping out!
I Learn every day :blush:

The expire Binding is super!!!
Worked out!!!

Best regards

Is it also possible to get the state updated to “NULL” ? i tried it out with some rules and the rest api, but without success.

Just leave off the ,state= part with the Expire binding or use ,state=NULL which I think works as well.

What did you try exactely. I think postUpdate(NULL) should work in most cases. sendCommand will not work though.

1 Like

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.

thanks for your help!