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 file.py, so I donā€™t see where could be the problem with the python script

Best suggestion of the morning

1 Like

Soooooo

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" "http://192.168.1.50:8080/rest/items/VMB7IN_0A_Counter_1/state"

This command is automatically generated and displayed in the REST API docs interface
http://192.168.1.50:8080/doc/index.html#!/items/getPlainItemState

)

If soā€¦

Take another slurp from the coffee and read the last few postsā€¦ Slowlyā€¦ :wink:

2 Likes

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'

and

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

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/ReadValue.py", 5000)

It might work, it might notā€¦