On/off switch with 2 buttons

Can someone help me with an on/off representation of a particular switch in a sitemap?
I have a push button that controls ON (PushON) and another button that controls OFF (PushOFF) to control a light. I need to send an ON command to one of them to turn on or off the light:

PushON.sendCommand(ON) //turns ON the light
PushOFF.sendCommand(ON) //turns OFF the light

Is there a possibility to have one single switch button in a sitemap that when toggled left it sends ON to PushON and when toggled right it sends ON to PushOFF?

I am running OH2.4 stable

You can use a virtual switch. When it’s on, it sends a command to pushOn, when it’s off, it sends a command to pushOff

Like @ljsquare said

Create a virtual switch item

Switch proxy_light

and create a rule to “convert”

rule "proxy light"
when Item proxy_light received command
then    if (receivedCommand == ON) {
        PushON.sendCommand(ON)
        }
        if (receivedCommand == OFF) {
        PushOFF.sendCommand(ON)
        }
end

Use the virtual item in your sitemap

Default item=proxy_light label="whatever" icon="light"

If you’ve not already done it, you may like to use the expire binding to “un-push” the Items PushON, PushOFF after use.

An other alternative is using the visibility in your sitemap

Is this also possible with the new profile feature?
If not I have to create 30 rules :frowning:

You might want to look into use of an “Associated Item” naming convention, and Group triggered rules.

Thanks all!

Hi,
I’m trying to follow this example, but I can’t get i working. I’m new to openHAB and using Visual Studio.

I’ve created an item files “switch.items” and inserted the switch command, it seems to work, since I can find it in the PaperUI.

The rule doesn’t seem to work, it says there are 2 problems, the problems are PushON and PushOFF. It’s like it’s not included in the library or something like that?

The sitemap is a little confusing too, but I’ve tried to follow guides, don’t know if it works since the rule is not working.

It would be very helpful if I could see screenshots of the different files. I think this could be helpfull to all who just start with openHab, since the “demo” is very big and confusing.

-CP

PushON and PushOFF are two example Items. The original poster wanted one line on his sitemap that could eventually send commands to either of them.
I guess you don’t have those Items defined.

What is it that you are trying to achieve?

All I want is to create a switch in the UI which can turn my yeelight lamp on and off

Okeydoke. Do you have an Item representing your lamp, linked to the Yeelight binding’s channel? Which UI are you using, a sitemap based one?

I have not defined anything yet, since everything I’ve tried have failed. What I need is just an example on how to set it up

I have not set up any sitemap

Okay, you are probably starting at the wrong end of the stick.

I would suggest trying to follow the Yeelight binding documentation to end up with your lamp represented as an Item in openHAB.
At that stage, you should be able to at least see it the admin PaperUI, and move on to creating a sitemap to be used with the end-user BasicUI.

If you have problems with that, best to start your own new thread, since this has little to do with simulating pushbuttons via a rule.