@time_trigger and additional params #326
Replies: 1 comment 2 replies
-
There are a couple of choices. Most easily, you can simply use config['entities'] in the trigger function. There's no need to pass it as an argument since it's already in scope (ie, exists) when the trigger closure is defined. The documentation is referring to how you can pass extra arguments to the trigger function. That's helpful if you have several different triggers applied to the same function and you'd like to tell them apart. Here's how that should work. Inside the @time_trigger("once(sunrise)", kwargs={"var1": 10, "var2": "hello"})
@time_trigger("once(sunset)", kwargs={"var1": 25, "var2": "goodbye"})
def func_sunrise_or_sunset(**kargs):
.... (note: untested) |
Beta Was this translation helpful? Give feedback.
-
I'm writing a trigger closure, that creates a @time_trigger
def create_triggers(config):
start_time=config['periode']['start']
@time_trigger(f"once({start_time})")
def start_tuinlichten(**kwargs):
.... turn_on light1, turn_on light2....
but, I also have config['entities'] that contains ... entities :)
I wanted to add that variable config['entities'] to the @time_trigger(.... as param, so I can use the contens in the function... But HOW?
In de docs, under time trigger , I read:
"Additional keyword parameters can be passed to the trigger function by setting the optional kwargs parameter to a dict with the keywords and values."
But, I don't know how to do this?
Can someone help?
thanks!
Beta Was this translation helpful? Give feedback.
All reactions