
Basically what I want to calculate is the time between the activation of a PIR sensor and the last update. So what I did:
- When the PIR activates (and triggers the lights) I store the datetime in a global var like this:
Code: Select all
local Time = require('Time')
local currentTime = Time().raw
domoticz.globalData.eye01Activation.add(currentTime)
- Next I have a script which triggers every minute and checks the lastUpdate of the PIR sensor:
Code: Select all
local lastUpdate = eye01.lastUpdate
local Time = require('Time')
local lastActivationRaw = domoticz.globalData.eye01Activation.getLatest().data
domoticz.log('LAST ACTIVATION RAW: ' .. lastActivationRaw)
if (lastActivationRaw ~= nil) then
local lastActivationTime = Time(lastActivationRaw)
local currentTime = Time()
local minutesActivated = lastUpdate.compare(lastActivationTime)
domoticz.log('MINUTES ACTIVATED: ' .. tostring(minutesActivated.minutes))
end
Disclaimer: I removed some lines which were not relevant to reproduce the issue. It might not compile like this, did not check, the idea is clear I hope
