Overview Page Items - Read Only?

Latest hasbian.

I am trying to use the Toggle Switch item to show the status, reading an MQTT item. Is there a way to make it read only? The UI config doesn’t have option, can you do it in the code?

Also is it possible to make a Toggle item “write” a value to MQTT when toggle, but also respond to a MQTT message to show the resulting status?

You can set the Item as read only in the State Description metadata. But I think that will change the default UI widget to be a simple label instead of a toggle. There is no way to make a toggle read only. It is by design and intended to be a control and therefore interactive.

You configure the MQTT Channel with a state topic and command topic. Commands sent to the Item get passed on to the Channel and sent to the command topic. Messages received on the state topic results in an update to the Item linked to the Channel.

The oh-toggle component (and I believe the -card and -item versions) has a disabled property. If you set this property to true then the component will be slightly grayed out and unavailable for user interaction but will still respond to changes of the linked item.

That wasn’t in the reference. Is that some global property like visibility perhaps?

That one comes through from the underlying f7-toggle. I don’t think most of those f7 properties show up in the auto generated reference docs, you have to head over to the f7 docs to find those. It does show up in the context menu in the widget editor though.

1 Like

Maybe it would be possible to add a link to the relevant f7 docs on the reference pages. Because they are autgenerated I’m not sure how much control over that we would have though.

The disabled property does indeed work, but it greys out the title text and widget.

Using the toggle to display a status isn’t ideal anyway, but I can’t see an alternative in the standard widgets. I think an alternative will be text with a different colour or a custom widget in the form of a coloured square or circle.

Which type of widget are you looking for? If a stand alone widget, use an oh-label-card. If a list item widget use an oh-label-item. You have access to a title, subtitle, icons and with expressions you can change the color and icon based on the states of the Items.

It’s worth looking into, but whether or not the various properties pass through to the f7 components is not 100% consistent across the oh components. So, it’s still not trivial to make 100% clear what works and what doesn’t.

That can be fixed by just adding:

  opacity: 1 !important

to the toggle’s config.

But, you’re definitely right the toggle is just not the ideal solution here. This is the sort of thing that I handle most often with an expression that changes an icon based on the item state. For example the connection status of various relevant devices on my network:

iconF7: "=(items[loop.activeItem.name + '_Online'].state=='ON') ? 'wifi' : 'wifi_slash'"


Thanks I will take a look at that.

I am playing with a custom widget example from Rich Koshak in the forum here that look like they will do the trick as well.