Python script import issues in hass.io

Has anyone figured out a workaround for not being able to import in hassio python scripts? I just moved over to hassio and want to implement a script like this, but the python_script section in hassio doesn’t allow for imports in scripts.

Is there a workaround for this?

Just found this, think it might be a good workaround. I’ll have to check it out later on today

I tried to use the official script function but couldn’t migrate to it.

But for command_line switches regular python scripts seem to work. There’s at least two of us :slight_smile:

So I can call this in hass.io no problem:

- platform: command_line
  switches:
    mote_custom_switch_rgb:
      command_on: "python3 /config/mote-hass-api-call-for-hassio.py"
      command_off: "python3 /config/mote-hass-api-call-for-hassio.py"
      friendly_name: Illuminate

So I guess the advice is turn the script into python3, put it in the /config folder, and it’ll probably work!

2 Likes

I’ll have to take a look at that when I get back home. Thanks!

Would be nice to have python_scripts working on Hassio as I’m assuming regular python scripts don’t have access to hass.states etc. I could call the HA API using requests I suppose, but bit of a hassle.

Thanks Bit-River, that worked a treat!

I did initially leave the remote.py file in the config/python_scripts folder where it was initially developed (for) but after realising I couldn’t run the import function (import requests) for HTTP POST’s I eventually gave your suggestion a try.

In the python_scripts folder, even run from the command line switch as ‘python3 /config/python_scripts/remote.py’ - it just showed an event in the hass log “component failed”…so I moved the script to the config directory and updated the switch with the new location - tested it, works fine. Tres odd.

I really, really, wish the guys would get the import function working like native python - it’d open up so many more opportunities and blow the doors off hass.

But thanks again!

5 Likes