Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Script not working with trigger activated #572

Unanswered
bbnoc asked this question in General
Discussion options

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
You must be logged in to vote

Replies: 2 comments

Comment options

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

You must be logged in to vote
0 replies
Comment options

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
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /