InfluxDB as an alternative to mytimer.reschedule?

Hello to everyone,

I was testing my recursive rules with timers but I have 3 lights to control with PIR sensors now, is there any possibility to use InfluxDB to check if there is any motion so the rule could shut down the lights?

This is one of the 3 rules to shut down the light, I have another rule to turn on.

rule "Llums Soterrani OFF intel·ligent"
    Item ST_Soterrani_Pir received update 1  
    if (temporitzador6 === null)   
        temporitzador6 = createTimer(now.plusSeconds(10), [ |
            temporitzador6 = null

What specifically are you trying to fix, make better or whatever in your hope to use InfluxDB? It’s not clear what your problem with the timers are.

In short, I seriously doubt it. openHAB does stuff based on events. InfluxDB doesn’t generate any events. So there would be nothing to trigger something to happen.

Hi Rich,

The trigger would be the same, the part I wanna change is the “then”.
For example, create a variable to check the sum of the PIR sensor (1 min) and while the sum is positive it means that there is motion so we need to keep the lights on. When the sum is 0 we could turn the light off.

check1 = PB_Salo_Pir.sumSince(now.minusMinutes(1), "influxdb") as Number

I don’t know if that is possible, do you think it can be done?


So, the idea is to run a timer that after a while checks to see if “something” happened? Why would you not just use the “something” directly to reschedule the timer, or whatever?


The idea is to remove all timers and only use influxdb data to check if there is any motion periodically. If there is motion we keep the lights on, if not we shit them down. I don’t know if this could actually be possible.

It’s possible, it’s pointless, it’s inefficient.

Here’s your problem. There still has to be a time based element.

Using your original example with a ten-second timer, you could construct a rule that runs every second and examines the database, and doesn’t turn the light off unless the newest event is more than ten seconds old.
It’ll work, but your system will be performing thousands of database accesses. By the time you have a few of these rules, it will be quite busy doing that and won’t be able to do much else.
Internally, the mechanism clanking away to make your rule run every second is the same mechanism that would run just once for a ten-second timer, so that’s working harder too.

Really, you need to address the timer phobia. What difficulty is using timers causing you?

1 Like

I understand now, thanks. My only problem with the timers is that I have already more than 5 rules with them and I am not sure if they will perform well at the same time.

You helped me a lot, thank you very much.

Rule Timers work like an alarm clock. You set them for some future time, and forget them, They do nothing extra while waiting.

1 Like

There is a famous quote in computer science credited to Donald Knuth (). " Premature optimization is the root of all evil." Put another way, don’t solve a problem until you know you have a problem. In home automation in general, and in OH 3 in particular, performance almost never matters. You simply are not doing enough to actually experience a performance problem. So don’t try to preemptively fix a performance problem you may never have if for no other reason than you won’t know if you’ve actually fixed it because you’ve no way to test it.

In this case, as rossko57 points out, your attempt to fix a perceived performance problem with Timers (a problem that in fact doesn’t exist) would actually have been far worse from a performance perspective than making no change at all.

That’s why we usually ask for the root problem you are trying to solve and I’m glad you told us.

Now, if you have a bunch of these motion sensor and light combos, you can handle them all using just one rule using the Design Pattern: Associated Items design pattern.

It would be something like

import java.util.Map

val Map<String,Timer> timers = newHashMap

rule "Motion sensor lights"
    Member of MotionSensors received update 1
    if(timers.get( === null) {
        timers.put(, createTimer(now.plusSeconds(10), [ |
            sendCommand("Pir", "Llums"), "OFF")
            timers.put(, null)
    else {
1 Like

Thanks, it worked for me. I didn’t knew this way of doing it. I am new on this world of home automation with OpenHAB, glad you helped me a lot.