I have a script in /config/python_scripts that works fine from terminal inside HA.
However if i call the same script via an automation I get the following error:
Error loading script getwatts.py: Line 28: "__init__" is an invalid attribute name because it starts with "_"., Line 29: "_stop" is an invalid attribute name because it starts with "_"., Line 53: "_stop" is an invalid attribute name because it starts with "_"., Line 56: "_stop" is an invalid attribute name because it starts with "_".
any ideas hive mind?
As suspected, you are using the python_script integration which runs in a sandboxed environment with several constraints (like inability to use import). Basically, your python code is incompatible with what the python_script integration permits.
I believe the workaround may be to execute getwatts.py as a shell command.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.