Replies: 4 comments 1 reply
-
Could you do something like this: @time_trigger("startup")
def pyscript_startup():
pyscript.started = 1 Could you then qualify your automation on pyscript.started == '1' (although it won't be defined until it's set)? |
Beta Was this translation helpful? Give feedback.
-
This is very interesting! It might be pushing the bubble around a bit if it
fails on the undefined variable, but maybe this can fail more gracefully.
I'll experiment with this and report back.
Thanks for the idea!
…On Mon, Jul 10, 2023, 1:15 PM Craig Barratt ***@***.***> wrote:
pyscript initializes itself, loads all the user scripts, and runs all
@startup triggers when the EVENT_HOMEASSISTANT_STARTED occurs. That's to
make sure all other components are already loaded.
Could you do something like this:
@startup
def pyscript_startup():
pyscript.started = 1
Could you then qualify your automation on pyscript.started == '1'
(although it won't be defined until it's set)?
—
Reply to this email directly, view it on GitHub
<#485 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZLG5F56MKFJUH4KGLCJDPLXPQ2BTANCNFSM6AAAAAA2EWKRIU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Sadly, this doesn't work. HA preserves the state of the "started" variable,
so the second time you boot up, it already exists and is set to 1 when the
automatons are loaded, but before pyscript is ready.
Is there a way to keep HA from making the variable persistent?
For future posterity, this is what I did.
@time_trigger("startup")
def pyscript_started():
pyscript.started = 1
This goes anywhere in the python script.
Then in the automation that calls the script, add this condition.
condition: numeric_state
entity_id: pyscript.started
above: 0
It seems like the condition fails gracefully if the state doesn't exist,
and prevents the action from happening and failing.
|
Beta Was this translation helpful? Give feedback.
-
Yes, that would work for a clean shutdown or reboot, but not for a power
cycle. Odds are, this will work for 99.99% of the cases that I care
about...I'll give it a try.
…On Tue, Jul 11, 2023, 8:02 PM Craig Barratt ***@***.***> wrote:
Could you try this to reset the variable at shutdown?
@time_trigger("shutdown")def pyscript_shutdown():
pyscript.started = 0
—
Reply to this email directly, view it on GitHub
<#485 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZLG5F3KS7T25CCU5IBX2DLXPXSPXANCNFSM6AAAAAA2EWKRIU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Hi all,
I have pyscript running on my HA system with a python script that is meant to be called by an automation under certain conditions.
During HA startup, the conditions for the automation are true pretty much as soon as the helper state and automations are loaded, and this allows the automation to call the python script before pyscript has finished initializing - the name of my service isn't found.
Is there some sort of state available from the pyscript object that I can use as a condition in my automation to keep it from trying to call the python script until after pyscript is done initializing?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions