Need an idea for better "trigger only if unchanged for X minutes" script

I’m trying to think how to make a rule that will trigger only if an item status didn’t change for 5 minutes.
what I have so far is this (I want it to turn off if b836405c was ‘false’ for 5 minutes):

rule "PC light auto on or off"
when
    Item mqtt_topic_b836405c_occupancy received update
then
    if (mqtt_topic_b836405c_occupancy.state == 'true'){
        tradfri_0220_0004c4ab_65537_brightness.sendCommand(100)
        tradfri_0220_0004c4ab_65537_color_temperature.sendCommand(35)
    }
    if (mqtt_topic_b836405c_occupancy.state == 'false'){
         if (mqtt_topic_b836405c_occupancy.historicState(now.minusMinutes(5))=='false' && mqtt_topic_b836405c_occupancy.historicState(now.minusMinutes(4))=='false' && mqtt_topic_b836405c_occupancy.historicState(now.minusMinutes(3))=='false' && mqtt_topic_b836405c_occupancy.historicState(now.minusMinutes(2))=='false' && mqtt_topic_b836405c_occupancy.historicState(now.minusMinutes(1))=='false'){
         tradfri_0220_0004c4ab_65537_brightness.sendCommand(OFF)
         }
     }
end

There’s got to be a better way to do this.
Any help and ideas will be appreciated.

Are you sure you want “trigger if unchanged for X mins”?
I ask because usually with occupancy you want to trigger if unupdated, as you might get continuing “occupied” updates.

As general advice, using persistence records is unsatisfactory for this use. You get a snapshot of 5 minutes ago, anything could have happened in the meantime.

Better to use a timer. Start a timer when your “unoccupied” update comes in. If the timer is running when an “occupied” update comes, cancel it. If the timer runs to completion, do whatever, you know no “occupieds” came.

Look at Design Patterns: Generic Is Alive and Design Pattern: Motion Sensor Timer.

I phrased the question in general terms, specifically in this case I want “trigger if occupancy is false (unoccupied) for 5 minutes” .

As far as using a timer I’ll try it.

Also my Sensor updates its status every minute.