Reading variabels out of scripts = EXEC Binding?

Hello Communitiy,

i would like to read data out of a script, that reads a S0-Energycounter.
in the wiki i’ve read that the exec - Binding is the solution with:

in: exec="<[<commandLine to execute>:<refreshintervalinmilliseconds>:(<transformationrule>)]"
How does it work ? How do i tell the item which variable should be read ?

THX 4 Help !

The exec binding gets assigned to an Item. See the Items wiki page.

<commandLine to execute> is your script as you would execute it from the command line.

<refreshintervalmilliseconds> is how often to run the script

<transformationrule> is how to process the text the script spits out to get the value you actually want to apply to your Item.

When working with exec binding I highly recommend instead starting using the executeCommandLine(cmd, timeout) action within a rule so you can print out the result of the script. Otherwise you never know what the script is generating when it fails. Working with the commandline is challenging in OH because OH runs under a different user and getting the permissions right tricks up most users.

if i run sudo /var/s0_zahler/s0_zaehler
i get my inkrementing counter for the s0 impulses.

so my item looks like this:

Number s0_zeahler1 "S0 [%.1f Wh]" {exec="<[sudo /var/s0_zahler/s0_zaehler]"}

since i dont see values on my sitemap Text item= s0_zaehler

Do i need to refresh ?
should the script be in openhab/configurations/scripts where openhab should have permissions?

How would the rule look like to print the values via oh ?

I’m going to recommend again moving the call to your script to a Rule and use:

var String results = executeCommandLine("sudo /var/s0_zahler/s0_zaehler", 5000)
logInfo("Test", results)

Watch your openhab.log for the results from calling the script which will show you what error it is printing out.

If I had to guess what the problem was it would either be that the openhab user is not configured to not require a password when it runs sudo on that script and the exec binding is waiting around for a password.

NOTE: the openhab user that gets created when you install openHAB via apt-get is a non-loginable account meaning it has no password.

1 Like