Python arguments for executeCommandLine

I am trying to persist my data using influxdb. For this i have a python script which has arguments, and it’s not working for me when the script is triggered by rules.
In my rule file i have this line of code:
executeCommandLine("python /opt/openhab2/conf/scripts/ \"light_test,region=east value=\\\""+Switch2.state.toString+"\\\"\"")

Then, i can see in the logs the next:
executed commandLine 'python /opt/openhab2/conf/scripts/ "light_test,region=east value=\"OFF\""'

How can i pass parameters through executeCommandLine for Python?


  • Platform information:
    • Hardware: Raspberry pi 3
    • OS: Raspbian
    • Java Runtime Environment:1.8
    • openHAB version: 2.2.0

first of all: why do you need the quotes for your whole python arguments at all?

on the other hand, why don’t you use this one:

executeCommandLine('python /opt/openhab2/conf/scripts/ "light_test,region=east value="' + Switch2.state.toString + '"')

Why are you using python to persist values when you can you the persistence service?

because i want to add tags and more than one field for each record and, please correct me if i am wrong, that service is not customizable

i will give it a try

I did this:

executeCommandLine('python /opt/openhab2/conf/scripts/ "light_test,region=east value="' + Switch2.state.toString + '"')

and it didn’t work out. The log file shows:

 executed commandLine 'python /opt/openhab2/conf/scripts/ "light_test,region=east value="ON"'

two basic questions:

  1. does it work from the console
  2. does it work from the console using the openhab user?
  1. Yes, it does. To make it work i do:
python /opt/openhab2/conf/scripts/ "light_test,region=east value=\"OFF\""
  1. It should run. I ran this command yesterday.
sudo chmod 777 /opt/openhab2/conf/scripts/

(I still don’t get why you want your whole argument parsed as on in your python-script… :wink: ) - but:

  1. if you need escaped quotes in your script, of course you must escape then in the excutecommandline also:
executeCommandLine('python /opt/openhab2/conf/scripts/ "light_test,region=east value=\"' + Switch2.state.toString + '\"')
  1. it should isn’t enough in that case, please chown to the openhab user and try - or put some action in the python script which indicates, it was called in the first place. To be really sure, try to
  • make sure, which Linux-User openHAB2 is running and chown to this one and try to start the script
  • make sure this openhab user is also allowed to use whatever connection to the influx-db you’re using within the script
  1. I tried these two commands without success
executeCommandLine('python /opt/openhab2/conf/scripts/ "light_test,region=east value=\"' + Switch2.state.toString + '\""')
executeCommandLine('python /opt/openhab2/conf/scripts/ "light_test,region=east value=\\"' + Switch2.state.toString + '\\""')
  1. I put the next in the first two lines of my code, but nothing of this appeared in the logs
print 1
print (argv[1])

this won’t get into your logs anyway - you have to have something that has impact outside of OH2 to be sure.
But I still think, you don’t have the permission for the user running your openhab to execute the script in the first place.

I forgot to mention that i did this too:
sudo chown openhab /opt/openhab2/conf/scripts/

  1. are you sure openhab is the user running OH2?
  2. still, even if the script owner itself is the user openhab it could not be enough for OH2 to start the script

to be fair, I mixed the commands… :wink:
To be 100% sure, you don’t have to chown the file - but to start the file in the user for openhab to execute. If the user is openhab (see 1.), then please try:

su openhab
python /opt/openhab2/conf/scripts/ "light_test,region=east value=\"OFF\""

after the first command, you should see the prompt like this, which indicates you changed to the user openhab:

[17:57:49] openhab@openHAB2:/home/openhab$

Interesting, ‘su openhab’ command asks me for a password which i’ve never set up.

On the other hand, i see that the user openhab has a running process

oh. sorry - I figured from your path, that you didn’t use openHABian but a manual installation. Either way, to change to the user, you have to activate the user “openhab”, which doesn’t have a shell at the moment.

or you have a look in the linux system logs for some errors regarding the failed(?) attempt to start your script - and place something in the script (generate an empty file with a current timestamp?) to see, if it is started after all…