Run thing action from within module

I can run a thing action fine when I do it from within the body of a rule. But, when I try to run a thing action from inside a module (e.g. in automation/lib/python/personal/somemodule.py), I get an error. Is there something I need to import, or is it more complicated than that?

Example error:

    mailActions = actions.get("mail", "mail:smtp:somemailserver")
AttributeError: 'module' object has no attribute 'get'

Modules do not have the default script scope, so you will need to import actions…

from core.jsr223.scope import actions

Here is a link, but there is an update pending for this. It’s better to use format in the example I gave.

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

1 Like