Send the value from a slider to a script .py

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…