HABApp: Dynamically create countdown timers?

Hi @Spaceman_Spiff!

Not 100% sure how to describe this request, but I’ll try.

I’m trying to use parameters to handle all my motion/door devices that trigger lights on timers.

It is largely working great, creating the listen_events by iterating through the keys in the parameters file.

But I am not sure if I can create the timers, which ideally call a common function with the name of the motion/door device that triggered them, programmatically like I did the listen_events.

is this possible?

If you create one rule per device and pass the parameters into the rule you only have one timer.
You can the set the device name on the rule and just call the function accordingly.

Another possibility is to save the return value from the scheduler e.g. in a dict.

Thanks - I’ve come back to your reply a few times this week, and clearly don’t know enough to make it work…

I’m trying to have one rule that pulls in all the motion/timer/door items from a parameter file and sets up listen events for each entry. When the listen event is triggered, it reads the JSON and decides how long, how bright, etc, etc, from the device definition.

That works great, except I seem to have to manually create timers.

Oh, maybe you are saying that I could dynamically create rules (each with one listen event) from the parameter files, and have one generically-named timer in that rule? I’ll have to think about that as well, but how to achieve doesn’t immediately come to mind…

If you have any rough examples as a starting point, that would be helpful!

If the item belongs logically together that’s the way I would do it. I don’t have enough information but what you are describing sure looks like it.
I would create the rules dynamically

I read this section about a year ago and had no idea what was happening in the code, but feel like I could give it a try now. Thanks for the tip, stay tuned!

:exploding_head: :exploding_head: :exploding_head: :exploding_head: :exploding_head:

I think I got it…super cool!

1 Like