Pyscript, how to trigger and access data

I installed pyscript on Home Assistant and followed the tutorial for hello_world:
https://hacs-pyscript.readthedocs.io/en/stable/tutorial.html#writing-your-first-script

The script hello_world.py seems to be callable from Service tab in Developer Tools, but I dont see logs anywhere.
I did add the log config to configuration.yaml and restarted HA, as well reload the configuration.yaml file.

pyscript:
  allow_all_imports: true
  hass_is_global: true
logger:
  default: info
  logs:
    custom_components.pyscript: info

The documentation suggest the logs can be seen in Configuration → System → Logs

There are logs, but no hello world: got action ... as I would expect.

  • Where can I find the script output?

Next I created some python code to login to an external service and set a configuration.
The goal of this script is to configure the active power limit of my solax invertor, to turn down the solar production when the energy prices are negative.
If the prices are a bit negative, I want to produce only enough for myself. When the prices are too negative i want to shut off the solar production completely.
The script works and configures the solax inverter correctly. The script however requires input from HA.

sensor.electricity_price
sensor.p1_meter_power
sensor.solax_power_now

The electricity_price is the current energy price (€/kWh). The p1_meter_power is the current inflow/outflow of energy in my home (value in Watt). The solax_power_now is the energy produced by the solar panels (in Watt).

The method I created is called def config_solax( energy_price, current_use, current_production ):

  • How do I access the 3 sensor values in the python script?
  • The python script makes use of import requests. Do i need to install that via pip? or will that be done automatically?
  • The script calculates a percentage which is sent to the solax inverter. E.g. produce 50% means for a 3kW inverter, that it will produce a maximum of 0.5 * 3000 = 1500Watt. This value 50 I would like to log in HA. How do I send this value back to HA?

Once I’ve got it all working, I shall put the script on github so others can make use of it as well. Any help with the above questions would be much appreciated!

If you don’t see you log entries in ‘Log Viewer’, try looking directly in the log file ‘config/home-assistant.log’. The Studio Code Server works well for this, or use Samba and your favorite IDE.