-
Notifications
You must be signed in to change notification settings - Fork 58
-
Hi,
I have a script with a time trigger - and i have defined two functions.
Is there something important i do not understand? When it triggers, or file is changed, function two acts as function 1 does not exist.
I come from openhab, and there one specify a trigger of some sort at the top, then whole script executes from top to bottom.
It also seems that variables defined above the trigger, only gets filled at script load time, and do not change every time script is run.
Example code will not work with trigger. It will work with no trigger and manual start of script. The logic thing would be to just do whatever is below the trigger, when triggered? Or am i missing something essential?
@time_trigger("startup", "cron(*/1 * * * *)")
def function1():
code
def function2():
value = function1()
if value == something:
do something else
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
Got a great idea - just write the script with only a @service decorator, and just call it from a HA automation every minute. Still, same behaviour.
Then i wrapped both functions in a "main" function - and the last line was a call to the function2 (in the example above) - that worked.
Is this normal? Because it does not feel normal to have functions, inside functions :P
Thanks
Beta Was this translation helpful? Give feedback.
All reactions
-
Did you try to remove the empty line between your @time_trigger decorator and your function body? I am not sure if that is the cause, but I never have empty lines after my decorators. cron is working fine for me.
@time_trigger("startup", "cron(*/1 * * * *)")
def function1():
code
Beta Was this translation helpful? Give feedback.