Presence Simulation

Came here as the previous method I used (google calendar scheduler) is no longer supported in OH3.

Tried the great method in this thread but had a little difficulty at first but quickly found the answer here

In short, change this (from above code):
createTimer(now.plusMillis(i*presence_delay))

To this:
createTimer(now.toInstant().plusMillis(i*presence_delay).atZone(now.zone))

For completeness and for anyone else who is interested in this method here is what I have now which I can confirm works with OH3.

Make sure influxDB is setup, ether manually or via openhabian

Add following:

.items

Switch Swi_PreSim  // used in sitemap to turn simulation on/off

Group  gSim        // add this group to items you wish to be included

example light to be included:

Dimmer Dim_Lounge_Rear "Lounge Rear" <light> (gSim) { channel="xyz" }

.persist

Items {
gSim* : strategy = everyChange
}

.rules

// **************************
// Global variables
// ***************************
var int presence_days = 1
var int presence_delay = 1000
var String persistence = "influxdb"
// ***************************
// Presence Simulation
// ***************************
rule "Presence Simulation"

when

    //Time cron "0 0/1 * 1/1 * ? *" //every 60 sec
    Time cron "0/30 0/1 * 1/1 * ? *" //every 30 sec

then

    if (Swi_PreSim.state == ON) {
        gSim.members.forEach(light,i |
            if(light.historicState(now.minusDays(presence_days), persistence).state != light.state) {
                //createTimer(now.plusMillis(i*presence_delay)) [|  OH2
                createTimer(now.toInstant().plusMillis(i*presence_delay).atZone(now.zone)) [| //OH3
                    logInfo("Pres_Sim",light.name + " state " + light.historicState(now.minusDays(presence_days), persistence).state)
                    light.sendCommand(light.historicState(now.minusDays(presence_days), persistence).state.toString)
                ]
            }
        )
    }
end

Pleased I found this as it is so much simpler than the Google method, no messing about with their API and all done locally, wish I discovered this a while ago!

2 Likes