How to call a function in a different script?

I have a script file, say, 100_rules.py with rules and functions, a function, say, getColorTable() can be called from one of the rules, send parameters, receive returned data, works.
Now from a second script file, 200_rules.py: how can I reach the function in the first file?
They don’t seem to share a namespace and ‘see’ each other. Is there anything like scriptName.functionName() to reach the function in the other script file?

From a script, you cannot access a function in another script. However, you can put the function into a module and import it into the script. Just copying your script into /automation/lib/python/personal/ to make it a module will probably not be enough, since the scope of modules is different than scripts. You can find some more detail here…

https://openhab-scripters.github.io/openhab-helper-libraries/Python/Reference.html#custom-packages-and-modules

If you need more, just ask!

2 Likes