Addon.cfg load market binding?

No, I assume it’s just not possible, yet.

Installing market bindings automagically doesn’t work (yet) with addons.cfg, so I created the following rule to install them manually after each server start (which I just assume is always preceded by an openhab update):

rule "Systemstart"
when 
	System started
then
	[...]
	Thread::sleep(30000)
	executeCommandLine("/etc/openhab2/marketbindings.sh")			
end

Contents of /etc/openhab2/marketbindings.sh:

curl -X POST -H "Content-Type: text/plain" --data "id=market:binding-3670618" http://192.168.1.253:8080/rest/extensions/market:binding-3670618/install
curl -X POST -H "Content-Type: text/plain" --data "id=market:binding-3499123" http://192.168.1.253:8080/rest/extensions/market:binding-3499123/install

Here I add the eBUS 2.0 Binding and the Openhab Xiaomi Mi IO Binding, but this works with any binding.
Not very beautiful, but working!

Don’t forget to put the binding id in both the link and the submitted data & put in your own server’s IP.

EDIT: previously I posted a solution with installing the bindings directly via executeCommandLine and curl, but according to https://github.com/openhab/openhab/wiki/Samples-Tricks#how-to-use-the-lifx-beta-api-via-executecommandline-and-curl this would require loads of @@, which don’t look good and are quite confusing,
Another solution would be to use sendHttpPostRequest. The idea stays the same.

4 Likes

This is actually a nice idea. We could change your script to read the addons.cfg and iterate over the market bindings. This way we still have a single location to install bindings.

1 Like

An even nicer idea! Took me a while, since regex in bash is highly non-intuitive (no global capture, no non-greedy matches, no line break matches), but finally got it working using a few hacks:

#!/bin/bash
content=`cat /etc/openhab2/services/addons.cfg`
regex="(market:[^, $]*)"
ip="YOUR IP"
port="YOUR PORT"
install_extensions() { 
    local s=$1 regex=$2 
    while [[ $s =~ $regex ]]; do 
	read extension < <(echo "${BASH_REMATCH[1]}" | grep "market:")		
	read blen < <(echo "$extension" | wc -c)		
	if [ $blen -gt 8 ];
	then
	    curl -X POST -H "Content-Type: text/plain" --data "id=$extension" http://$ip:$port/rest/extensions/$extension/install
	fi
        s=${s#*"${BASH_REMATCH[1]}"}
    done
}
install_extensions "$content" "$regex" 

This scans addons.cfg for any extensions beginning with “market:” and installs them. The string length check is not really necessary, this just prevents empty entries like “market:,” from being installed.

6 Likes

@_tom

That is very good indeed. And what format are you using in the addons.cfg itself, please?

Just add the string as seen in Paper UI next to any other bindings etc.

binding1, binding2, market:binding-1234567, binding3
1 Like

“market:123456” works for me.
“binding-1234567” does not.

This does not work for me, could you explain in detail?

I have the market add-on installed.

binding = binding-123456 does not work unfortunately.

Just use my script, for me it never worked without it.

@_tom I am using your script, but it seems that I need to add the binding as: market:binding-xxxxxxxx

You have to add the bindings exactly as they are shown in PaperUI.

For the Xiaomi Mi IO Binding this is e.g.

market:binding-3499123

@vzorglub can u please share an example what should be exactly written in the cfg file to have auto installation of market binding (not from paperUI)?

I want to install: market:binding-3499123

addons.cfg:

binding= ???

Thx

@smhgit
I should withdraw that post.
I worked once. I don’t know how and has never worked since.

I hope they will support it as now I have to run script for that :frowning:

The script runs well, I use that now

Might be wrong topic - I dont use addon.cfg only PaperUI - would there be a similar approach to install via paperUI binding installs? (even if its not reading a file)

You should install the Eclipse IoT Market addon (Paper UI > Addons > Misc). See here.

I have but i thought bindings still “disappear” on upgrade

They do … but that is not an error, it’s by design.

Yes I understand that - but am looking for an option as no matter I usually install the market bindings again after an update - if there was a scripted way id love it.