I’ve read Exec - Transformation Services | openHAB and other related documentation
What I’m trying to do is whenever I receive a message in mqtt, I want to use exec transformation to run lets say a python script which turns the item state to uppercase and updates item (or updates to another item)
how do I pass %s to a python program and how do I read that in the python script? where do I place this exec command in the gui?
If you want to use exec and phyton you maybe overengineering things. OH has build in functions to do some coding if needed.
If you want to have all mqtt input uppercase you can either e.g.:
- add a JS transformation to your thing
- add a profile to the channel link
- maybe formatting on the item / GUI level will also bring what you need
If you want to update one item based on another item input you can use rules
Using the exec transformation for this is indeed way overkill. It’s super slow and really heavy weight since it has to spin up a whole separate program.
It’s not clear what you mean by “how do I pass %s to a python program”. From openHAB’s side, it’s pretty straight forward. The
%s gets replaced with the contents of the string to be transformed. From the Python side, you need to research how to process command line arguments in a Python program which is out of scope for this forum really.
If all you are looking for is a to upper, you can use
| to tell it that it’s an inline script and the incoming string is
I actually would love to use JS but I’m using certain node libraries that didn’t work for me using js scripiting on opennhab…that’s why I thought it might be easier to just call a script using exec and let the script do whatever it wants and return the value I need using whatever libraries it needs
I used js transform, I just wanted to see how the calling a separate script thing works…because I’ll have to use some libraries that aren’t supported in oh js scripting i think (some node libraries)…so I thought it’d be easier to have an independent program use the libraries it needs and just pass and input and get the output using openhab