Problems with Whitelisting of scripts in OH 2.5.6

I cannot whitelist the python scripts with all combinations of possible parameters.
Wildcards must be made possible, somehow.

What makes no sense is to whitelist the following:

/usr/bin/python3 /etc/openhab2/scripts/balboa.py status
/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 20.0
/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 20.5
/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 21.0
/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 21.5

/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 40.0

and this is just for setting the tempretatures.
I did not yet cater for all the other parameters that might be used.

the following does not work:

/usr/bin/python3 /etc/openhab2/scripts/balboa.py %s

Any suggestions?

Try /etc/openhab2/scripts/balboa.py

That was the first thing I tried.
no chance.
the only thing that whitelists the script is the complete path like

/usr/bin/python3 /etc/openhab2/scripts/balboa.py status

which includes the exceutable, the script name and the script parameter.

What does not work:

/usr/bin/python3
/usr/bin/python3 %s
/usr/bin/python3 %s %s
/usr/bin/python3 /etc/openhab2/scripts/balboa.py %s
/etc/openhab2/scripts/balboa.py
/etc/openhab2/scripts/balboa.py status
/etc/openhab2/scripts/balboa.py %s

Can you expand “not work”? There are about a hundred ways for script calls to go wrong, not all are to do with whitelist.

I presume we are talking about exec binding here?
You probably haven’t got %s in your Thing, more like %2$s. Why not try it exactly as you defined it?

Yes, this is about the Exce-Bindiung
%2$s does also not work - and is useless.
According to the following thread: [SOLVED] OpenHAB2 exec Binding it will be replaced with the current status of the channel, and that does not help,

What I need is a placeholder for ANY parameter I will call the script with, without having to whitelist every single possible combination of parameters.

It was shown like that in an example on page https://www.openhab.org/addons/bindings/exec/ , but without any explanation regarding the syntax.

When not whitelisted with the exact command including all parameters, the error is currently always the same: “not whitelisted”.
The error shown is always:
12:08:51.058 [WARN ] [ing.exec.internal.handler.ExecHandler] - Tried to execute ‘/usr/bin/python3 /etc/openhab2/scripts/balboa.py status’, but it is not contained in whitelist.

the following have been tried and do not work:

/usr/bin/python3
/etc/openhab2/scripts/balboa.py
/usr/bin/python3 /etc/openhab2/scripts/balboa.py
/usr/bin/python3 /etc/openhab2/scripts/balboa.py %s
/usr/bin/python3 /etc/openhab2/scripts/balboa.py %2$s

So is there any way to have a kind of “universal placeholder for arguments”??

How are you passing these parameters to your exec binding Thing? May we see how you defined your exec binding Thing?

There is no thing, these are rules:

var lastAlert = now.minusMinutes(5) // set to five minutes ago so the Rule can run when OH first starts

var Number LoadingFor = 0

var Number NotLoadingFor = 0

var Number SwitchOffTries = 0

var Number SwitchOnTries = 0

rule “HeatUpManually”

when

Item BALBOA_MANUAL changed to ON or

Item Persistent_BALBOA_OPERATIONMODE received command or

Item Persistent_HOTTUB_MANUAL_TEMP changed

then

if (Persistent_BALBOA_OPERATIONMODE.state == ‘MANUAL’)

{

return;

}

logInfo("-18-balboa.R3", "Manual Heating On Received: " + Persistent_BALBOA_OPERATIONMODE.state)

if ((Persistent_BALBOA_OPERATIONMODE.state == “AUTO”) && (Persistent_BALBOA_OPERATIONMODE.state == “ON”))

{

logInfo("-18-balboa.R3", "Manual Heating On Received")

if (BALBOA_TEMP_RANGE.state == "Low")

{

    executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py temprange")

}

if (BALBOA_SET_TEMP.state < 38.5)

{

  executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp " + Persistent_HOTTUB_MANUAL_TEMP.state)

}

}

end

rule “SwitchOffTubOverNight”

when

//Every weekday at 14:00 hours

Time cron “0 0 22 ? * * *” or

Item Persistent_BALBOA_OPERATIONMODE changed

then

if((Persistent_BALBOA_OPERATIONMODE.state == ‘AUTO’) || (Persistent_BALBOA_OPERATIONMODE.state == ‘OFF’) || (Persistent_BALBOA_OPERATIONMODE.state == ‘MANUAL’))

{

if (BALBOA_MANUAL.state == ON)

{

  BALBOA_MANUAL.postUpdate(OFF)

}

}

if((Persistent_BALBOA_OPERATIONMODE.state == ‘AUTO’) || (Persistent_BALBOA_OPERATIONMODE.state == ‘OFF’)) {

executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 30");

}

else

{

executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp " + (Persistent_HOTTUB_MANUAL_TEMP.state));

}

end

rule “HeatUpWhenEnoughPower”

when

//Every weekday at 14:00 hours

Time cron “*/30 * 09-15 ? * * *”

//Item KebaPower changed or

//Item PV_Meter changed

then

if ((Persistent_BALBOA_OPERATIONMODE.state == ‘AUTO’) || (Persistent_BALBOA_OPERATIONMODE.state == ‘ON’) || (Persistent_BALBOA_OPERATIONMODE.state == ‘MANUAL’))

{

var Number Available = -(PV_Meter.state as DecimalType)

logInfo("-18-balboa.R3", "Available: " + Available.toString() )

if (((Available > 2000) && (KebaPlugLocked.state == OFF)) || (Available > 3000))

{

  SwitchOnTries += 1;

  SwitchOffTries = 0;

  logInfo("-18-balboa.R3", "SwitchOn: " + SwitchOnTries);

}

if (((Available < -1500) && (KebaPlugLocked.state == OFF)) || (Available < -1000))

{

  if (BALBOA_MANUAL.state == ON) // No need to care if ON anyway

  {

    executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp " + (Persistent_HOTTUB_MANUAL_TEMP.state));

    logInfo("-18-balboa.R3", "SetTemp: " + (Persistent_HOTTUB_MANUAL_TEMP.state))

  }

  else

  {

    SwitchOffTries += 1;

    SwitchOnTries = 0;

  logInfo("-18-balboa.R3", "SwitchOff: " + SwitchOffTries);

  }

} 

if (SwitchOnTries >= 5) {

  if (BALBOA_SET_TEMP.state < 40)

  {

    executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 40")

    logInfo("-18-balboa.R3", "HeatUp: 40")

  }

}

if (SwitchOffTries >= 5) {

  if (BALBOA_MANUAL.state == ON) // No need to care if ON anyway

  {

    if  (BALBOA_SET_TEMP.state > 38)

    {

      executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 38");

      logInfo("-18-balboa.R3", "SetTemp: 38")

    }

  }

  else

  {

    if (Persistent_BALBOA_OPERATIONMODE.state == 'MANUAL')

    {

      if (BALBOA_SET_TEMP.state > (Persistent_HOTTUB_MANUAL_TEMP.state)) {

        executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp " + (Persistent_HOTTUB_MANUAL_TEMP.state));

        logInfo("-18-balboa.R3", "SetTemp: " + (Persistent_HOTTUB_MANUAL_TEMP.state));

      }

    }

    else

    {

      if (BALBOA_SET_TEMP.state > 30) {

        executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 30");

        logInfo("-18-balboa.R3", "SetTemp: 30")

      }

    }

  }

}

}

// update item to switch on light here

end

rule “NormalizeTemperature”

when

//Every weekday at 14:00 hours

Time cron “0 10 15-17 ? * * *”

//Item KebaPower changed or

//Item PV_Meter changed

then

if (Persistent_BALBOA_OPERATIONMODE.state == ‘MANUAL’)

return;

if ((Persistent_BALBOA_OPERATIONMODE.state == ‘AUTO’) || (Persistent_BALBOA_OPERATIONMODE.state == ‘ON’))

{

if (BALBOA_SET_TEMP.state > 38)

{

  executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp 37.5")

  logInfo("-18-balboa.R3", "HeatUp: 37.5")

}

}

// update item to switch on light here

end

rule “Hot Tub: Parsing (SPARaw) JSON output to individual Items”

when

Item SPARaw changed

then

{

logInfo("-18-balboa.R2", “### Hot Tub: Parsing (SPARaw) JSON output to individual Items ###”)

val String json = (SPARaw.state as StringType).toString

gHotTub_Parse_json.members.forEach [ value |

  var String name = value.name.replace('BALBOA_','$.')

  var String type = value.type

  if (type == "Switch")

  {

    var String newValue = transform("JSONPATH", name, json).replaceAll('"','')

    if (newValue != "Off")

    {

      value.postUpdate(ON)

    }

    else

    {

      value.postUpdate(OFF)

      //value.postUpdate(transform("JSONPATH", name, json).replaceAll('"',''))

    }

  } 

  else

  {

    value.postUpdate(transform("JSONPATH", name, json).replaceAll('"',''))

  }

  //logInfo("-18-balboa.R3", " " )

]

SPARaw_LastChanged.postUpdate( new DateTimeType() )

}

end

rule ToggleLights

when

Item BALBOA_LIGHTS received command

then

   executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py lights")

end

rule TogglePump1

when

Item BALBOA_PUMP1 received command

then

   executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py pump1")

end

rule TogglePump2

when

Item BALBOA_PUMP2 received command

then

   executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py pump2")

end

rule TogglePump3

when

Item BALBOA_PUMP3 received command

then

   executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py pump3")

end

rule SetTargetTemp

when

Item BALBOA_SET_TEMP received command

then

var String commandline = "/usr/bin/python3 /etc/openhab2/scripts/balboa.py settemp "  + (BALBOA_SET_TEMP.state)

executeCommandLine(commandline)

logInfo("-18-balboa.R3", "Set target temp: " + commandline)

end

rule ToggleTempRange

when

Item BALBOA_TEMP_RANGE received command

then

   executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py temprange")

end

rule ToggleHeatingMode

when

Item BALBOA_HEATING_MODE received command

then

   executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py heatingmode")

end

please use code fences in this forum

Okay, then you are not using exec binding here.
The calls in your rules are Actions, these are not an add-on and are documented here -

These actions do not use the whitelist.
Maybe you have some left over experiment using the binding?
I say that because your error message comes from the binding, not your rules.

If you must use Python 3 instead of Jython somebody here wrote an integration fir Python 3.

Well, it says
executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py temprange")

That is EXEC-Binding, no?

No experiments, just an update from OH2.2 to 2.5.6 - which I should never have done.

What is Jython? I never installed jython, all I have is Python3 on the machine.

That’s my point.
executeCommandLine() is a core Action.
You can uninstall the exec binding add-on and that will still work.
executeCommandLine() is not described in the exec binding docs.
executeCommandLine() is described in the Action docs.
The Action docs do not describe a whitelist.

Where does the error message then come from?

Just came across another setting in the items:

String SPARaw “SPA: [%s]” (gHotTub) {channel=“exec:command:spa:output”} //defined in spa.things

and the thing referenced:
Thing exec:command:spa [command="/usr/bin/python3 /etc/openhab2/scripts/balboa.py status", interval=30, timeout=5]

Sorry for forgetting that, just thought about the config and recognized that there is no status request in the rule I sent.

1 Like

it appears to come from the exec binding. Have you that installed?
You might be using it somewhere else, that’s fine. It’s not obviously involved in your rules, but it looks to me like you may have previously attempted to get something working with Things? And there are leftovers.

executeCommandLine() doesn’t use whitelist. At least it hasn’t before - that could have secretly changed, of course.

You’re not giving us very much context to work with here.
Are you able to remove the binding, do your rules still work?
Do your rules actually do what is expected, even though you get an error message?
Maybe we can find out, example -

when
   Item BALBOA_PUMP1 received command
then
   logInfo("test", "doing exec")
   var results = executeCommandLine("/usr/bin/python3 /etc/openhab2/scripts/balboa.py pump1")
   logInfo("test", "done exec " + results)
end

Alright, got there now.
So you are presumably still having trouble with this, but it is nothing to do with placeholders at all?

I think your whitelist file is in the wrong folder.

Jython is basically Python 2 compatible but written in Java. There are helper libraries to help write OH rules too.

@5iver or @rlkoshak can enlighten you further.

No, as I said, when entering exactly the correct (and full) path:

/usr/bin/python3 /etc/openhab2/scripts/balboa.py status

so executable, script path and script parameters, it works.
The question was just if the arguments (status, as an example) can be replaced by a placeholder, so I would not have to whitelist every single possible parameter.

Anyway, as I meanwhile agree that the script calls are not EXEC bindings, but actions, that should not be required anymore (in this case).

The answer to parameter/placeholder whitelisting is exactly as per exec binding docs.
In short, put in the whitelist exactly what you put in your Thing (which may have placeholder like %2$s).
There is an example in the docs.

Can the docs be improved, which part misled you?

Exactly that part.
Not explained, just used in the example - with no cross reference.
Asking Google for things like “%2$s” does not get you any far.