Cyclic timer-based execution of commands (e.g. cyclic presence simulation to prevent burglary)

Idea:
Cyclic switching lights on/off to simulate presence of people in the house to prevent burglary

Main Concept:
Define a reasonable sequence (cycle) of commands for your lights in the house that simulates presence of people. Run this cycle as often as needed during absence of people in the house. A switch switches the cycles on and off.

The following example is a .rules file. It uses a sample of a (for testing seconds-based) sequence for one lights-plug [item ShellyPlug1_Power]. Instead of plusSeconds you could use plusMinutes as well. For switching the cycles on and off, the switch item TimersTest is used.

This setup is running at my openHAB without any problems.

OpenHAB Version 2.5

Feedback welcome.

import java.util.List
import java.util.ArrayList
val List<Timer> TimerList = new ArrayList<Timer>()

// you need to have a Switch item e.g. as follows: Switch TimersTest "Timers Test"
// the Switch item is used to switch the timers sequence ON and OFF 

rule "Add Timers to List"
    when Item TimersTest received command ON 
    then 
        // Set timer events for whatever timeframes and items
        // use an ascending order of timers for more clarity
        TimerList.add(createTimer(now.plusSeconds(5), [|ShellyPlug1_Power.sendCommand(ON)]))
        TimerList.add(createTimer(now.plusSeconds(10), [|ShellyPlug1_Power.sendCommand(OFF)]))
        TimerList.add(createTimer(now.plusSeconds(15), [|ShellyPlug1_Power.sendCommand(ON)]))
        TimerList.add(createTimer(now.plusSeconds(20), [|ShellyPlug1_Power.sendCommand(OFF)]))
        TimerList.add(createTimer(now.plusSeconds(25), [|ShellyPlug1_Power.sendCommand(ON)]))
        TimerList.add(createTimer(now.plusSeconds(30), [|ShellyPlug1_Power.sendCommand(OFF)]))
        TimerList.add(createTimer(now.plusSeconds(35), [|ShellyPlug1_Power.sendCommand(ON)]))
        TimerList.add(createTimer(now.plusSeconds(40), [|ShellyPlug1_Power.sendCommand(OFF)]))
        TimerList.add(createTimer(now.plusSeconds(45), [|ShellyPlug1_Power.sendCommand(ON)]))
        TimerList.add(createTimer(now.plusSeconds(50), [|ShellyPlug1_Power.sendCommand(OFF)]))
        TimerList.add(createTimer(now.plusSeconds(55), [|ShellyPlug1_Power.sendCommand(ON)]))
        
        // the last (last by time) timer should do some cleanup and restart the whole sequence
        TimerList.add(createTimer(now.plusSeconds(60), [|
            // do cleanup of all timers by cancelling all of them
            TimerList.forEach[timer|timer?.cancel]
            // do some cleanup of the TimerList by removing all list-entries
            TimerList.removeAll()
            // do cleanup item states by switching all items to their default (e.g. OFF)
            ShellyPlug1_Power.sendCommand(OFF)
            // restart the whole sequence
            TimersTest.sendCommand(ON)
        ]))
    end
 
rule "Cancel Timers of List"
    when Item TimersTest received command OFF
    then 
        // do cleanup of all timers by cancelling all of them
        TimerList.forEach[timer|timer?.cancel]
        // do some cleanup of the TimerList by removing all list-entries
        TimerList.removeAll()
        // do cleanup item states by switching all items to their default (e.g. OFF)
        ShellyPlug1_Power.sendCommand(OFF)
    end

idea >>> Use random times between a limited time range instead of fixed times in the timers.

eg

1 Like

Another idea is to record the light states to persistence and play back whatever the lights were doing seven days ago when you are away. That way it’s not random, its actually turning on and off exactly how you normally would. Presence Simulation It’s a two line Rule to implement.

2 Likes

If you didn’t use the lights much 24 hrs ago it wouldn’t be so good. Or if your away longer than 24 hrs, the pattern would begin to repeat. You would need a 2 week history to replay.

I have mine set to start when it gets dark and the alarm is fully armed. Then starts a ‘typical’ evening sequence but with start, On. Off times randomised enough to hide sequence. Does the blinds too. No need to think when remotely checking what is on. It just works.

That’s why I said

emphasis added.

So use a two week period. The amount of time you go back is kind of irrelevant. I’d choose an increment of seven days so the different usage patterns for a given day matches the type of day (e.g. weekends will have a different usage than work days). You could go back a month if you want, or a year. If you’ve got the data going back that far you can go back as far as you want.

It seems to me replaying your actual usage at a given time of day would be superior to some random sequence. The fact that lights and blinds start moving differently or more frequently than normal will stand out just as much as their remaining off for anyone watching the house to determine when you are away.

If you used the lights less seven days ago when you were home, was that a problem when you were home? Does that mean you are more likely to be broken into while you are home than when you are away if you use the lights less? Shouldn’t you then randomize everything all the time?

The whole point is to make burglars think you are home. What’s better than to actually have the lights and blinds and stuff operate the way you actually operated them when you were home?