Are dynamic @state_trigger's possible? #273
Replies: 1 comment
-
If I understand your question, I think what you are (probably) looking for is done here; Basically, write the function you want you want to apply to each door/window and wrap that in another function which takes a single door/window as an argument and dynamically generates the function with appropriate decorators. That should work as long as your function doesn't need to coordinate between the different entities. Another option is using string formatting along these lines: I would lean toward the first, but take all of this with a grain of salt as I'm very new to pyscript and just trying to sort a lot of this out for myself. Hope it helps! |
Beta Was this translation helpful? Give feedback.
-
I'm trying to write a script that will upon startup find all door/window sensors, (and notice when new ones are added, both these functions I have written already), and then set up a @state_trigger for each. Is there a way to define these dynamically? Poking around I've found that I can do an event trigger on state_change, but there are so many of those happening all the time I feel like thats inefficient. Or, is that what a @state_trigger does internally anyway? If so I'll just go that route.
Beta Was this translation helpful? Give feedback.
All reactions