No python script work

Hi, i try to make a python script but I don’t work. I installed home assistant in my raspberry pi with All-In-One Installer.
This is my python script:

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

Is esactly the hello word script bring to the official home assistant website : https://home-assistant.io/components/python_script/1

When I call the service:


Yes, is not show me anything

Have you checked the log?

Yes, but it doesn’t tell me anything about that.
Can I run the script by terminal? because when I run, it tells me:

pi@raspberrypi:/home/homeassistant/.homeassistant/python_scripts $ python3 hello_world.py
Traceback (most recent call last):
File “hello_world.py”, line 1, in
name = data.get(‘name’, ‘world’)
NameError: name ‘data’ is not defined

Did you add python_script: to your configuration.yaml?

yes, I put it

So what is the output in the log?
Have you sat the correct log level? https://home-assistant.io/components/logger/

1 Like

Oh yes now it’s working, thank you. I don’t want to close this topic, in case I need to ask you something other about python script.

Hallo @Danielhiversen,
I tried the same script as @Matteo_Lando. I put the script into root/homeassistant/python_scripts
(I don’t know why the docker container was installed in root)

In the services I tried to call python_script.hello_world and got an error that the script cannot be called.

So I tried in the Terminal:
/root/homeassistant/python_scripts $ python3 hello_world.py
and got
-bash: /root/homeassistant/python_scripts: Permission denied

Also I copied the scripts intp PATH_TO_YOUR_CONFIG tried to start the command in the Terminal because I found it in the / structure (edited also the configuration.yaml like discribed below):
/PATH_TO_YOUR_CONFIG/python_scripts $ python3 hello_world.py
but I got
-bash: /PATH_TO_YOUR_CONFIG/python_scripts: Is a directory

Further more I didn’t get a error log.
The configuration.yaml were edit

python_script:

logger:
  default: info
  logs:
    homeassistant.components.yamaha: critical
    custom_components.my_integration: critical

Could you give me a hint pls what I’m doing wrong?

almost the same here.
like described in ; https://www.home-assistant.io/integrations/python_script, “Writing your first script”

for logging:

logger:
  default: info
  logs:
    homeassistant.components.yamaha: critical
    custom_components.my_integration: critical

when I call the service , I can select the service.
and as service data, I put name: mister

When I do the call, I don’t see anything in the logging, not even errors…
Is there something else I can do?
update: found it in homeassistant log.

1 Like

I have the same behavior today?
What I am doing wrong?

The documentation is not very pure for that.

Logs are found in the home assistant logs. The hello world script example outputs to the logs. So browse to your configuration folder and look at the home-assistant.log file.

Thanks petro, in this logs file everything looks good