custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

Custom Logbook entry #497

Closed LDprg closed 1 year ago

LDprg commented 1 year ago

As I am using pyscript without jupyternotebooks (I am using docker and those didn't worked), I want to get a simpler method for printing logs that direct into the HA ones. Is there a way to create Logbook entries?

sdaoudi commented 1 year ago

You can use the logger component as mentioned in documentation: https://hacs-pyscript.readthedocs.io/en/latest/reference.html?highlight=log#logging

Try to change the log level in your configuration.yaml:

logger:
  logs:
    custom_components.pyscript: info

Reload your home assistant configuration. After this you can add logs statement to your pyscripts:

log.info("my first log")
oskretc commented 1 year ago

To log info directly into HA logbook use this service

logbook.log(name="Hello World", message="Hello from pyscript")

LDprg commented 1 year ago

Oh, thx. Didn't know that I can achieve this with a service.

ALERTua commented 1 year ago

@LDprg could you please update or close the issue? Thank you

LDprg commented 1 year ago

Sorry, I will now close.