Can't get Python Scripts working

I am running Home Assistant 0.83.3 on Windows Server 2012

So far I have done the following;

  • Added the following to the configuration.yaml python_script:
  • created a directory called python_scripts in %appdata%.homeassistant
  • copied hello_world.py example from the wiki page into the folder
  • granted permissions to everyone on the folder and the hello_world.py

The only Python script related service that I can see in the developer tools/services is python_script.reload

Did you restart HA, or at least run the python_script.reload service?

Is %appdata%.homeassistant the same place that configuration.yaml exists in?

The guide I read specifically mentioned that is has to be python_scripts with an “s”.

I have restarted HA and also ran the python_script.reload.

%appdata%.homeassistant is the same place as the configuration.yaml file.

The directory is named ‘python_scripts’ - with an “s”. The configuration entry is ‘python_script:’. - I am quite sure that is correct because I get an error in the logs saying that it can not find ‘python_scirpts:’ when I have tried that.

Why? You are two versions behind.

Hmm, yes, it does sound like you’ve done everything correctly. Could you post the code inside hello_world.py? Also, do you see any error messages inside home-assistant.log that might be related? E.g., I have a script named update_cameras_view.py, and if I search the log for it I see:

pi@raspberrypi:/home/homeassistant/.homeassistant $ grep update_cameras_view home-assistant.log
2019-01-15 13:43:55 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=python_script, service=update_cameras_view>
2019-01-15 13:44:21 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=python_script, service=update_cameras_view, service_data=>
2019-01-15 13:44:21 INFO (Thread-10) [homeassistant.components.python_script] Executing update_cameras_view.py: {}

The first line is when the script is first loaded, creating a service. The next two lines are from it being executed.

Updated to version 0.85.1. Still the same problem.

I do not see anything in the logs related to hello_world.py, just that the module was loaded.
2019-01-16 12:04:24 INFO (MainThread) [homeassistant.loader] Loaded python_script from homeassistant.components.python_script
2019-01-16 12:04:24 INFO (MainThread) [homeassistant.setup] Setting up python_script
2019-01-16 12:04:24 INFO (MainThread) [homeassistant.setup] Setup of domain python_script took 0.5 seconds.

hello_world.py contains the following, taken from here: https://www.home-assistant.io/components/python_script/

name = data.get(‘name’, ‘world’)
logger.info(“Hello {}”.format(name))
hass.bus.fire(name, { “wow”: “from a Python script!” })

That INFO message about the module being loaded is about homeassistant.components.python_script, not your hello_world module.

After that last message do you see another one like in the second line here:

2019-01-16 13:14:49 INFO (MainThread) [homeassistant.setup] Setup of domain python_script took 3.2 seconds.
2019-01-16 13:14:49 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=python_script>

Do you have DEBUG messages enabled? (See Logger.)

I have debug messages enabled but there is nothing about the script.
It seems to be looking in the a different path but I am not sure how that is possible.

Thank you for your help with this.

I have been following this thread, simply out of interest.

Does the script need to be executable?

I believe @eds2020 is running on Windows, so I don’t know if that applies. FWIW, I’m running HA on Linux on a pi, I have two python_scripts, and neither have execute permission, just read.

@eds2020, who owns the files, and what account is HA running under? I know you said you gave everyone read permission, but have you verified that whatever account that is running HA can actually read the files?

Currently running as my logged-in admin account.
I have granted full permissions on the folder and script and still have the same issue :frowning: