Python script: Hello World (Logfile)

I would like to start with my first python script “hello world” from this documentation: Python Scripts - Home Assistant

In my config.yaml i changed the logger to:

logger:
  default: warning
  logs:
    homeassistant.components.python_script: info

But I don’t get any output in the logfile, what’s going wrong?

Developer Tools

python script

name = data.get("name", "world")
logger.info("Hello %s", name)
hass.bus.fire(name, {"wow": "from a Python script!"})

You will not see info logs if you set the logger default to warnings.
Either set the logger to info

  default: info

or your script to send warnings

logger.warning("Hello %s", name)

It should if it outputs to [homeassistant.components.python_script], his configuration for the python_script section is set to info.

However, that will show logger info from the [homeassistant.components.python_script] log output. It’s been awhile since I’ve ran a python script, but logger may not output to [homeassistant.components.python_script] for python scripts.

1 Like

If I change the code to

logger:
  default: info
  logs:
    homeassistant.components.python_script: info

there is also no output into the Log (Configurations>Logs)

Look at your log file, not the UI. Also, when you change log levels, you need to restart or reload the logger integration.

Sorry, replied to fast. :relaxed:

Nothing to be sorry about, it’s confusing if you’ve never used it. I try to supply the most amount of information to the information suppliers

Thank you…and sorry, I am a beginner with python.
I always have done the restart after changes in config.yaml

In the logfile (config/home-assistant.log) I can find only this line:

2022-01-14 13:58:26 INFO (SyncWorker_11) [homeassistant.components.python_script.hello_world.py] Hello world

That’s showing that it’s working. And if you want to setup your logger properly…

logger:
  default: warning
  logs:
    homeassistant.components.python_script.hello_world.py: info
1 Like