Link item to an external url

Tags: #<Tag:0x00007f6173f29000>

My eyes must be wrong today or this is not possible?

I simply cant find any examples of how to make an item which is linked to an external url…
This is what I have, and though i get no error, it doesnt work:

String  Dahua1ForHub     "hovedindgang"       { url="http://10.4.28.127:54322/ipcamera.m3u8", ga="Camera" [ protocols="hls" ] }

Background.
I´m having some difficulties on my main Rpi3B+ which I believe is because its beeing pushed to hard. So I moved ipcamera binding to my Rpi4, to run my camera as well as demuxing with ffmpeg for HLS streaming…
My main Rpi3B+ is setup to use GA. So I had this idea, I just insert the url for the .m3u8 file created on my Rpi4, into the link (as the example) and then I would be good to go… But it doesnt work… Google wont show the url…

I know the link works fine, cause if I use it in Microsoft Edge, the streaming works just fine.

Any suggestion anyone?

Ps. This may be releated to the same issues Herbert seems to be having in this thread:

You can’t just make up syntax.

If you want to connect an Item with an external device or service, you use a binding. Same applies here - there is an HTTP binding.
https://www.openhab.org/addons/bindings/http1/.

I’m not surprised there is no error because that is valid Item metadata. But it’s not functional because there is nothing in your system that is looking for or using url metadata.

Links on Items are only to Thing Channels. Items do not support links to random URLs or any other random stuff. Google can’t see that url Item metadata and wouldn’t know what to do with it if it did. It can only see the ga Item metadata and the Item’s state (and tags).

You can use the REST API or Karaf Console to set that String Item to the URL in question so it has the URL as the Item’s state, but I don’t know if that would be sufficient to allow GA to stream it.

Hmm…
Two things. Its a bit hard to explain, and now I´m really confused:

First - The above item and link do seem to work, (I didnt mentioned I do have the http binding installed on my main Rpi)… But there is a very strange issue

I started the streaming manually (a switch which ipcamera binding provide to start the stream, which will starte the ffmpeg demuxing).
After that, I asked Google to “show hovedindgang”, and the stream starts to play just fine… Thats weird!
But if the stream is not already running, Google will not play it, and it wont start the switch to the demuxing stream either.

Using a “normal” single Rpi setup, the switch (ipcamera binding) will turn on automaticly when a client (player) connects to the stream, and the streaming starts.
This I can confirm,when I start the streaming from Microsoft Edge (or any other HLS player).
It also happens just fine, if I use the normal provided channel (url) from ipcamera.

But using the setup above, Google do NOT start the stream (the switch doesnt turn on). Thats why I first thought the url wasnt beeing parsed to Google.

Somewhere between ipcamera binding and openhab GA integration something seems to go wrong when using an external link like I´m using it above. And I cant really figure out why.

I need to make a few more test to be absolutly sure this is the case… Right now I dont really trust anything… And I have no idea whats going on, specially since you now tell me, it shouln´t work :thinking:

EDIT - Ignore the above… I just noticed that when I start the stream, it starts the streaming on my main setup Rpi3B+, even though I have changed the item… (some crappy cache I assume :face_with_symbols_over_mouth:). Microsoft Edge do start the stream on my Rpi4.

This is really driven me nuts… I need to get rid of the ipcamera binding on my main Rpi3B+ to make 100% sure its not doing any “fancy” stuff.

Thanks Rich.
I just used karaf to set the url for the item. And it do actually works. I can start the stream just fine on my Rpi4 through Google Home, even though the item is linked to GA on my Rpi3B+. Thats pretty awesome. Thanks for the hint!

But its not a good solution though, cause either I´ll have to persist this item to make sure it works on restart of openhab, or I have to update the item through a rule at start.
And I can´t keep wondering how come a direct url in the “channel” is not possible. It makes no sense not having this option.

{ url="blah blah blah" }

What binding is that a configuration for? What binding reads that? Where have you ever seen a URL applied to an Item like that before?

Google Assistant only reads ga=blah blah blah. Nowhere does it say that GA knows how to read anything else (besides tags of course).

The channel= that appears between the { } is a Link to a Things Channel on that instance of openHAB. It’s not generic information. You can’t link to a channel on some other instance of OH. You can’t link to some random web page or video stream. Only Channels on Things.

@Kim_Andersen

As Rich is trying to explain the String has a state which is not changed by adding a metadata called url on it.

Think of the String item as a physical box. The box is empty. You have stuck a sticker on the outside of the box that reads url=Foo/Bar.htm but the sticker is on the outside of the box and the box is actually EMPTY inside.

Another way which “May” work is to create a rule triggered when the system has started that sets the STATE of the item to your url. The STATE of the item must be set otherwise the (box will remain empty) String is just an empty string.

Of course the easiest way is to follow the working and tested examples from a readme :wink: They are there to make your life easier.

I understand what you´re both saying. But I dont understand how come I can not fill something “into the box” from a channel with an url, which is basicly what you´re saying isnt possible, because openhab dont know what to do with the url…

Yes, I believe using a rule to update the string item will do fine as well.

I must have missed that part of the doc for ipcamera. Will have yet another look again soon.

In this context, url is not a magic word.

String someItem {rhubarb="custard"}

This is a valid Item definition. There is no action taken for keyword rhubarb, but it is legitimate to put it there. Maybe you will later install a binding called rhubarb. Maybe you have a rule that searches for metadata tagged rhubarb, and does something with it. But openHAB isn’t going to do anything with it.

Which I understand from your saying, but dont understand how come openhab doesnt do as default (ie when there is no linked device/binding , use url as default). Specially for Strings it would, in this case, become usefull.

Why, what do you think is special about url= ? This is just a String Item, there’s nothing to say if its content represents an alarm state, the dog’s name, a phone directory entry, or a url. It’s just a string.

There have previously been suggestions about pre-loading (any kind of) Items at startup. Maybe one way would be with a magic keyword
{preLoadState="22.375"}
But it’s never been implemented. There are workarounds, and little point in an Item that acts like a constant.

I’ve had it on my list to post a Python script to do this. It’s really simple to implement really and the code is already there in the Python Time of Day implementation. It’s just not bumped high enough on the priority list.

It would look and work exactly as you describe, when the .py file is loaded it looks for all the Items with preLoadState and calls postUpdate on that Item with the value. However, there are problems with this as it only works at the time that the rule is loaded. If you later edit an Item to add a preLoadState, that Item won’t get initialized to that value until the .py file is reloaded.

To solve that you’d have to run a cron polling to re-run that rule periodically and pick up any new Items that have had preLoadState added. But this raises a new issue.

What about the use case where you want an Item to be initialized to a certain value at system startup, but then modify it after that point. You wouldn’t want to have your new sate overwritten by this cron driven rule. You would only want it to initialize the Item at system startup.

So even for something like this, it’s way more complicated than it first appears.

I’ve got rules that “preset” only if Item content is NULL, but yes it’s complication and some users will want this and not that etc.