Change Switch from ON to OFF and back without a rule

Hello,

have read about items and manipulating with them in rules https://www.openhab.org/docs/configuration/rules-dsl.html#manipulating-item-states
but have not found i simple function.

Can i switch the switch without a rule like this?

rule "Change Switch"
when
    Item SocketItemController received command
then
    if (SocketItem.state == ON) {
        SocketItem.sendCommand(OFF)
    } else {
        SocketItem.sendCommand(ON)
    }
end

i mean without this part of it

 if (SocketItem.state == ON) {
        SocketItem.sendCommand(OFF)
    } else {
        SocketItem.sendCommand(ON)
    }

using something to change it like

 SocketItem.changeState()

The background: i want to turn of and off the switch with only one button on remote controller.

Thanks a lot!

With only one button I think the rule will be needed. Is there a reason you do not want to use a rule?

I find it better to use native function if there is to optimise rules.

The link posted above is about using rules and for what you are wanting to do the rule you have should work fine.

It is unclear how your Items are configured and if they have Channels linked to them. If so, take a look at the rawbutton-toggle-switch profile…