Python script beginners question

I have a python script in /config/python_scripts/convert_to_json.py. I am testing the script by calling it under services i.e. service: python_script.convert_to_json. The two lines of my script are

import json
entity_ids = data.get("entity_id")

I see an error in the log

Traceback (most recent call last):
 File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 224, in execute
   exec(compiled.code, restricted_globals)  # noqa: S102
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "convert_to_json.py", line 1, in <module>
ImportError: __import__ not found

I don’t understand why. I searched and I see a lot of scripts that begin this way.

Thanks
Kurt

A note from the docs:

It is not possible to use Python imports with this integration. If you want to do more advanced scripts, you can take a look at AppDaemon or pyscript

Thanks. I searched for pyscripts in integrations. Is it not available there?

It’s a custom_component.

1 Like