turn of HVAC if windows/doors are open

I’d like to create some sort of script that will turn my Nest off if any doors or windows are left open. I currently have both the Nest and DSC plugins. My DSC has 2 partitions (upstairs/downstairs) and one of the partitions includes a PIR.

My initial thought was to do the following:

[code]pseudo-code

var nottriggered = true

function stillopen(num)
nottriggered = true
if ((partition still open) and (partition last triggered >= 5m)) then
Nest off
send notification
end
end

trigger → partition1 or partition2 open
if ((was not motion detector) and nottriggered) then
nottiggered = false
luup.delay(stillopen(partition#), 5 minutes)
end[/code]

However, on further thinking I realized that if a partition is triggered and then another element in the partition is opened within the 5m time-frame, nothing will happen as the partition last triggered >= 5m condition will fail.

Has anyone else done anything like this? Any pointers/suggestions?

Many thanks,
J.

Many people have done this in PLEG … it is well suited to solve this type of problem.