Display blocks of text in UI received from MQTT or from executed pyhon script

You could, but it won’t render. You can display

<html>
  <header>....
</html>

as text from an Item. You can’t load up an Item with HTML and have OH render that.

You can do pretty much anything you want in that respect. But you’ll probably need to create a custom widget to display it reasonably. And by the time you’ve munged together a widget that can both parse JSON and use it as you want, you’ve done more work had you used Items in the first place.

No, I think it might be implemented as an iFrame or something like that. It’s not embedded in the page, it’s loaded into the page. It’s mostly used for things like showing a camera feed from an IP camera or the trash pick schedule from an external website and stuff like that.

I don’t know because this isn’t the sort of thing that OH is designed to handle. It works with its own Items and its own database information. It’s not designed to be a generic display to show stuff that is pretty much wholly outside itself. That’s not it’s job.

There are tons of ways to do this that do not involve an external Python script and a table of text. Presumably these are devices that are important to OH so it’s probably already subscribed to those topics so an expire timer on those Items could be used if it doesn’t report after a time. The devices should have a LWT so that an OFFLINE message is published when the MQTT Broker sees that it went offline. OH can see that and set the MQTT Thing as OFFLINE which can in turn update the Items as appropriate.

Rarely do such short cuts that seem simpler end up being simpler in the long run. When using Groups, the semantic model, and widgets like the oh_repeater widget, you’d only need to change it in one place in OH too.

The currency in OH is Items. If it’s something that is worth displaying in OH, it’s also probably something worth OH acting upon (e.g. send a Telegram message when a node goes offline, turn on a heater when the temp sensor gets too low, etc). To achieve that, each sensor and actuator needs to be its own Item. If all you want to do is display a bunch of information from various sources, some other product is going to be a better fit for you. If you want to do some automation around this information, it must be broken up into individual Items.

You can easily do this in OH. But you’ll need three different Channels for each piece of information, link those three pieces to three separate Items, and then create a custom UI widget that displays those three Items with the style and formatting you desire.

And once you’ve done that, not only can you display it, you can have OH actually do something with them. Remember the “A” in openHAB stands for “automation”.

Thank you Rich
A lot of good information for me in your response.
I will now go away and digest that and read up about all those things
It is very encouraging that all of that can be done via openHAB.
Obviously my knowledge of openHAB is still rather low, so I will study all those areas yo mehtioned a lot more.
Thank ou again for your time and effort. Much appreciated

Just a quick question …
I have started researching more based on your very informative response.
I get the impression that you can only use the webview widget in a sitemap and that a sitemap cannot be displayed on a browser web OH screen and that you need to use an OH app if you want to display webview widget. (ie like android OH app, etc…)
Have I missed something here and that I can use webview widgets in a normal layout page accessed via a web browser ?
Many thanks

Sitemaps can be displayed on phone apps or using BasicUI (a separate UI add-on that can be installed) in the browser. It’s a completely different UI from MainUI which is what you get by default.

MainUI has the oh-webframe widget used to display another web page in a frame in a MainUI layout page. MainUI can be displayed in a browser or the Android app. I think iOS app support is coming soon but MainUI is a PWA so adding it to your homescreen works nicely.

I don’t know what HABPanel has for displaying other web pages. It too is supported in the browser or the android app (don’t know about the iOS app).

Thanks Rich.
That oh-webframe card was in the card list and I did not spot it even though I looked at that list many times.
Yes, that works very well indeed
Many thanks for your help to point me in the right direction

Now that I have the webframe working, I would like to trigger the html to be created by publishing a MQTT topic that my python script will pick up and generate the html for the webframe.
Ideally I would like a “click button” of sorts, but there does not seem to be one in the list of cards
If I use a toggle switch, I can get the MQTT publish to happen, but not visually ideal as this is not really a toggle function, but a click button function
I have tried to use a “string” card but whatever I do I cannot get it to actually publish the MQTT message, although everything seems to be set up the same as the toggle setup.
Is there somewhere a proper “button” card that is available and if not, is there a way to use the “string” card to actually publish the MQTT message ?
Many thanks

See

From UI, you can send an arbitrary string to an Item as command.
What happens to it then depends on what bindings or rules it is linked with.

If you are looking to have your string embed details from other Items or calculations etc., it’s almost certainly better to process that in a rule rather than trying to build complex strings in the UI widget.

Thanks for that Ross
Good to hear that it should work with any of the cards
Perhaps me mentioning button confused what I was trying to explain
I just want to trigger an action, and it does not have to be a button as such
I have it working with a switch card but not with a string card

This is exactly what I was trying to do
I initially setup a switch card and that works fine and the MQTT message is published and everything works fine, but does not make visual sense as this is an on/off scenario but an MQTT push to control something at the other end, ie take a picture from the camera
If I change that from the switch to a string card, with everything setup up the same as for the switch, the MQTT publish does not happen when I click on the string and I cannot see why that is
Currently, the MQTT publish does not need a payload as it is just the subscribed topic that causes the camera node to take a picture and publish the image which is then picked up by my OH page in an image card

The only action you can trigger from UI is to command some Item.

Neither can we. Look in your events.log to see what command is sent to the associated Item.

I just checked the event log and nothing is sent when using the string card
When using the switch card it works fine and I get the following in the event log

  • openhab/items/RovingCameraTakeAPicture/statechanged

ItemStateChangedEvent

{“type”:“OnOff”,“value”:“ON”,“oldType”:“OnOff”,“oldValue”:“OFF”}

  • openhab/items/RovingCameraTakeAPicture/state

ItemStateEvent

{“type”:“OnOff”,“value”:“ON”}

  • openhab/items/RovingCameraTakeAPicture/statepredicted

ItemStatePredictedEvent

{“predictedType”:“OnOff”,“predictedValue”:“ON”,“isConfirmation”:false}

  • openhab/items/RovingCameraTakeAPicture/command

ItemCommandEvent

{“type”:“OnOff”,“value”:“ON”}

There is no such thing as a string card, so I assume that you mean an oh-label-card. Take a look at the label card doc page, you’ll see a section named Action. This is a list of all the things you can configure the label card to do when you push on it. You’ll note that most of them just impact the widget/interface (i.e., open popup, navigate, variable etc.). Only a few of these can actually directly impact something in the core system: command, options, toggle, and rule.

It sound like you want the command option which will send the specified command to the specified item (and it does not have to be the same item that the card is displaying in the label). You’ll need to only add two configuration options beyond Send Command: Action Item and Action Command:

Thank you Justin
Yes, I meant label card
That is pretty much what I have for both options, but with switch it works and with label it does not
Here is what I have defined

Edit label cards
image

take a photo item

Take a photo channel

What command are you sending to your item? That’s not shown in the top image.

If you have Action, Action Item, and Action Command all configured, now what does the event log show when you click the label card?

Does the state of the item have to reset to some other value between commands (does your item have to register a change instead of just receiving a command)? If so, how are you accomplishing this reset?

What’s the Action Command? What command should the widget send to the Item when the widget is clicked on? You’ve cut that field off in your screenshot. My understanding is that is not optional. You have to define the Action Command too, not just the Item.

Remember, commands are what causes openHAB to send messages out to the devices. But a command has to be something. There is no ‘’ command. In the MQTT case, a String Item would be linked to a text Channel so the command will be the actual contents of the message published to the MQTT topic.

Thanks Justin / Rich

In the case of the switch version that works, there is no place to provide an action command and that works
In the case of the label version that does not work there is an option for the action command but that I left blank as I did not need that for the switch version.
There is no text to be sent in the MQTT payload as the camera node just reacts to the topic and does not check for the content since receipt of the topic is sufficient to trigger the camera and indeed works fine with the switch version
I just tried to add some text to that action command but it made no difference and teh event log shows nothing and the generic MQTT client I use for testing shows nothing being published

That’s the nature of a switch widget; if it’s OFF now, you must meant to command ON; and vice-versa. There is no choice about that to be had.

When you use a toggle, the command is built in. It sends ON when toggled up and OFF when toggled down.

You need that for a label widget. Otherwise what’s the widget supposed to send as the command? There is nothing implied by the nature of the widget. With a toggle, ON/OFF can be implied. With a slider a number between a starting point (0 be default) and ending point (100 by default) can be implied. But clicking on a label? :person_shrugging:

You still have to send something or else OH won’t publish anything to MQTT. And as I said, there is no such thing as a “nothing” command in OH anyway.

Because it’s actually publishing “ON” and “OFF” to the topic.

Then there is something wrong with the configuration of the widget. Don’t mess around with screen shots. Click the Code tab and post the YAML so we can actually see everything. Use code fences.

```
code goes here
```

In addition to what has been said, the toggle card and the label card are functioning by different mechanism. The switch on the toggle card is its own widget with it’s own configuration. To make an oh-toggle-card an oh-toggle component has been placed on a regular card. The oh-toggle docs show you that there is only an item property for configuring what item the toggle interacts with because, as has been pointed out, On/Off is easy for the system to deduce in that case.

The system of widgets actions are availabe in many different widget, including the oh-label-card and require more configuration (see the link in my first post). You can even simulate toggling with the actions (that is the toggle action) but you have to specify both the true AND false state commands in that case because the action will not make the same On/Off assumption.

Aha … Looking again at Rich’s answer I went back and started afresh and created a new text channel and relinked that to the string item and also added some text to the action command again and this time it works, so yes, something must have been wrong with the previous config but I can’t see what it was as I can’t compare them now.
Thanks to everyone to help me getting this to work. Really appreciated
All I can say that I am glad I chose openHAB based on my research as to which software to use
I can’t say enough about how responsive and helpful you have all been
I am very happy and now looking to delve further into what I can do with openHAB
Best wishes to you all

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.