Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(How) can I trigger a HA automation on pyscript reload? #531

Open
bjornbak opened this issue Oct 7, 2023 · 3 comments
Open

(How) can I trigger a HA automation on pyscript reload? #531

bjornbak opened this issue Oct 7, 2023 · 3 comments

Comments

@bjornbak
Copy link

bjornbak commented Oct 7, 2023

When a pyscript is updated the reload is logged as

2023-10-07 12:20:33.937 INFO (MainThread) [custom_components.pyscript.global_ctx] Reloaded /config/pyscript/sonnen_time_of_use_plan.py

in the log.

I would like to trigger a HA automation when I update a pyscript.
How can I listen to/trigger based on the reloaded event?

@ALERTua
Copy link
Contributor

ALERTua commented Oct 7, 2023

https://hacs-pyscript.readthedocs.io/en/stable/reference.html#time-trigger
image
I hope this helps.
But please use the Discussions tab instead of Issues for questions <3

@bjornbak
Copy link
Author

bjornbak commented Oct 7, 2023

Thank you, @ALERTua but I need the trigger a HA built-in automation on reload.

I want to create python scripts with no or minimum HA or pyscript specific code so I can unit test them outside HA.
So I am creating HA automations that collects states and attributes and call the pyscript as a service.
The pysript is returning it's output using the new response_variable feature.
And the HA automation is then updating relevant entities..

As a workaround I use the folder_watcher sensor but it triggers too fast so I have to add an artificial delay to wait for the reload.

@craigbarratt
Copy link
Member

Per @ALERTua 's suggestion - can't the pyscript call-on-reload function do something than can then trigger an HA built-in automation? Eg, it could set an entity or call a service?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants