Send the value from a slider to a script .py

Just “the blind leading the bewildered” again then.

I only mention it because I saw it as a suggestion in another thread

executeCommandLine("/bin/echo something >> /tmp/temp.txt",5000)

Rather than

executeCommandLine("echo something >> /tmp/temp.txt",5000)

Ok thanks, I did it and here is what the log shows

So it seems erverything is ok but my is still empty
I tried different command line but nothing is working

At least you’re progressing.

So give us an example of a working command line…

It’s probably something silly like spaces / capitals / file permissions / path

HoldOnAMo (a distant and reluctant relative to Geronimo)

Why are you trying to use Nano (an interactive text editor) to put the value permanently into the python script?

Surely the script just needs to see your value as a variable, supplied as part of the command line?

Just as @rossko57 has suggested, call Python to run your script, with your value being passed to your script from the command line.


Stuart @MDAR reminds me - we really, really ought to use a timeout with this, or it won’t wait for the script to work (or mess up)

var myResults = executeCommandLine("sudo python AbsolutePath/ " + value.toString, 5000)
logInfo("test", "My exec results " + myResults)
1 Like

nano was just a test :sweat_smile: I already tried call python to run my script from the command line and didn’t worked neither

I just tried with a timeout of 5000 and still not working

Arrr I see.

So I’ve just tried something super simple like this.

Try this bash script to echo a variable and append a text file, saved as /opt/

echo Value received from command line is $1 \\n
new=`expr $1 \* 66`
echo After some maths it becomes $new \\n
echo $1 $new >> /opt/test.txt
exit 0

The command line of

sh /opt/ 2

Puts 2 132 into test.txt

So if you put this into your rule… What happens?

var myResults = executeCommandLine("sh /opt/ " + value.toString, 5000)
logInfo("test", "My exec results " + myResults)

A bash script to play with

echo Value received from command line is $1 \\n
date > /opt/test.txt
echo inital value is $1 >> /opt/test.txt
new=`expr $1 \* $1`
echo $1 multipled by $1 is $new >> /opt/test.txt
echo $1 multipled by $1 is $new 
exit 0

Dare I suggest that there may be an issue with the Python script ?

How have you got it working in the past / while you created it?

Sorry for the reponding time, I took a coffee :sweat_smile:

1 Like

I thought so too but it just a empty, so I don’t see where could be the problem with the python script

Best suggestion of the morning

1 Like


Are you actually saying that you need to write the value into this empty file, so that something else, sometime later can read this file and take the contents? (Which begs the question, “why the Something can’t just use a curl command to get the openHAB2 Item state directly”, using the REST API…
For example

curl -X GET --header "Accept: text/plain" ""

This command is automatically generated and displayed in the REST API docs interface!/items/getPlainItemState


If so…

Take another slurp from the coffee and read the last few posts… Slowly… :wink:


I’ve just thought of something even easier to put into a rule to echo a value into a text file, but I’m not simply going to type it here (straight away), I think it would be a much better learning experience if you attempted it yourself.

(Although, obviously we’ll all carry on helping, it’s just we like teach, rather than “do for you” )

Sooo… I tried to echo the variable but I am stuck… I used

sudo sh -c 'echo "whatever I want" >>/file.txt'


echo 'whatever I want' | sudo tee -a /etc/

which worked on the terminal of course but the typo doesn’t match with the executeCommandLine. If you cand advise me about your thought :pensive:

** I have to use the sudo in order to have the permission, hence the tee -a **

@MDAR I need the permission… hence sudo tee

PS : I am a new user so I’ve reached the maximum comments/day, I only can edit :rofl:

1 Like

I can see that it won’t work…

just try

echo whatever I want >> file.txt

or start simply

echo TEST >> file.txt

or if you don’t want to append the file.txt, just try

echo TEST > file.txt

Careful when trying to redirect or pipe in executeCommandLine it does not run in a shell and so shell features will not work.
It’s not the same as the console and is not supposed to be.

why not letting the slider trigger a script that gets the value from the REST API as @MDAR suggested. I think that is much easier than worrying about how to get the value into the extnernal file resp. use it as a parameter.
As far as I understand you need to use the slider as a trigger anyway and you need to use a script anyway.

I finally decided to use curl command in order to have item state directly, and it works fine. So thanks for your help from the beginning ! :grin:

Before I end this topic, what was your idea, out of curiosity ? :face_with_monocle:

1 Like

As long as it’s working for you.

As others have said, there are other ways.

My “idea” was a simply comand like this in the rule

executeCommandLine("/bin/echo " + value.toString +" > /etc/", 5000)

It might work, it might not…