Push button not working in Sitemap. Only a switch is displayed

Hi@all,

I am quite new to openhab. I am migrating from Pimatic, which has a great ruleset and many usefull items, a button for example, very easy to create. I am trying to achive this goal in openhab, but as I read, this is not possible. I tried to do this with a sitemap but I am not able to create a button. Only a switch will be displayed in BasicUI although I used mappings. I used this code:

Switch item=sBedroomMainLight label="Bedroom main light []" icon="light" mappings=[ON="PUSH"]

The sitemap works, but only a switch will be displayed. Am I doing something wrong or does that not work in Openhab 4.3.2?

Thanks in advance
Amon

It definitely should work in OH 4.

Are you using MainUI to create the sitemap or a .sitemap file?

The syntax looks correct. Are there any errors in the logs?

Try removing the [ ] from the label. That shouldn’t matter but it’s been many years since I’ve used sitemaps and much has changed in that time.

Thank you rlkoshak,

I am so stu***. I tried only the code without an item behind it. I just changed the code to an existing item and bam, it works.
But now I have another question. After I pushed the button it gets highlighted and stays highlighted. Is there a way, that you push it once and it moves back to an unhighlighted button?

Thanks
Amon

I had a similar situation for a garage door opener button. This worked for me.

Item

Switch GarageDoor "Garage Door" {expire="1s,command=OFF"}

Sitemap

Switch item=GarageDoor label="Opener []" icon="" mappings=[ON="Open / Close"]

Sitemap
image

To elaborate a bit on @JimH’s answer, he set an expire timer to command the Item back to OFF after one second. You might want to update it to OFF instead which will not go out to the end device and just change the state of the Item.

Beware though as commands go to the device and are not just changes to the Item’s state.

The button will remain highlighted as long as the Item’s current state matches the mapping.

Great, thank you for this valuable information. This is exactly what I wanted to know.

Only a button element in a buttongrid can be stateless.
Switch element with buttons is stateful.

Even though sitemaps are supported, as a beginner I would recommend the UI to setup openHAB in the beginning.

see Getting Started - First Steps | openHAB

and Pages - Introduction | openHAB