From sitemap to MainUI pages: switch as button

Hi,
I’ve migrated from OH2 to OH3 and now I’m converting my sitemap to MainUI pages using the semantic model.
In the OH2 sitemap I had this item:

Switch EntradaTVSalon "Entrada" <screen>

And this in the sitemap:

Switch item=EntradaTVSalon mappings=[ON='+']

Which translated to this UI:

When I push the “+” button I get ON as the command sent to the item EntradaTVSalon.
How can I replicate this in OH3 MainUI? Do I have to create a custom widget or is there an easier way?
Thanks.

You can add a Command Action Option to your Widget configuration like this:


or this:
grafik

Hi,
Thank you, but I forgot to mention that I am trying to get it to work in the Overview/Locations tab, so it is a list item widget and there is no action for list item widgets.
Also, I’d like to get a button with “+” inside, like I had in the sitemap.
Regards.

Yes there is. Just add a “Default List Item Wiget” to your item and then choose “List Item”. There you can add a commad option as action.

Hi,
I had already tried that. I added it to have visibility options, and I’m not getting the action option:


But if I add the action parameter in the item definition in the file, I’m getting an action! (I just tried a link to a page):

Switch EntradaTVSalon "Entrada" <screen> (smSalonTVSalon) ["Setpoint"] {commandDescription="" [options="ON=+"],listWidget="" [visible="=items['TVSalon'].state == 'ON'",action="navigate",actionPage="page:ChartSalonTemperatura"],widgetOrder="2"}

It isn’t reflected in the GUI options but it appears in MainUI and in the YAML code definition of the listWidget item metadata:

value: ""
config:
  action: navigate
  actionPage: page:ChartSalonTemperatura
  visible: =items['TVSalon'].state == 'ON'

But I’d still like to get a “+” button as I had before, instead of a switch and an arrow as I have now.

You have a very specific, non-standard, use case. It may seem like the conversion directly from sitemap to MainUI would be more “standard” but in all honesty, much of the functionality of sitemaps is so limiting that 1) there’s almost always a better way to do it with the MainUI, and 2) you’ve already customized the function in the sitemap as well with your mapping parameter so it’s already non-standard.

So, the bad news is that this is not really supported out of the box. The good news is, that’s where the beauty of the new flexible widget system comes in; you can create very nearly anything you need to fit non-standard use cases.

The getting started tutorial takes you through the basic steps of creating your own custom list widget and using that as the default list widget for an item. This won’t be to complicated a widget so going through that tutorial and looking up a few examples already on this forum and you can have exactly what you want pretty quickly.

There’s a bonus too: when you manage to make exactly what it is you want, you can add it to the marketplace and the next person who comes along and has this special. non-standard use case can benefit too.

1 Like

I don’t know if I understand you right. But if you just add a list item and not a toggle item you have the command action.
So you habe a “Button” sending your command by just clicking on it. And this is what you want, or not? :slight_smile:

No, I’d like a button with “+” inside, as I had before. I’ll try the custom widget route.
Thank you both, I’ll keep you posted.