Get Sensors Status

From Domoticz
Jump to: navigation, search

Purpose

This script will get status of all sensors

Dependencies - hardware / software / operating system

This script will work on all type of hardware / software / operating system.

It could be use to trigger any bash script such :

Domoticz Setup - switches, variables, version

  • N/A

Installation instructions

Copy this script in your domoticz\scripts\lua\ folder.

Script with comments

--get status of all sensors
--if the sensor is dead for more than 1 day output the name of that sensors

function timedifference(s)
 year = string.sub(s, 1, 4)
 month = string.sub(s, 6, 7)
 day = string.sub(s, 9, 10)
 hour = string.sub(s, 12, 13)
 minutes = string.sub(s, 15, 16)
 seconds = string.sub(s, 18, 19)
 t1 = os.time()
 t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
 difference = os.difftime (t1, t2)
 return difference
end
 
commandArray = {}
 
for i, v in pairs(otherdevices) do
  timeon = 86400
  tc = tostring(i)

--print("Alive: " .. tc .. " ");

     difference = timedifference(otherdevices_lastupdate[tc])
     if (difference > timeon) then
        tempdiff = tostring(difference)
        
        --remove garbage from the output, only report nodes that has not update for more than 1 day.
        v = i:sub(1,2)
        v2 = i:sub(1,4)
        v3 = i:sub(1,6)
        v4 = i:sub(1,17)
        if ( (v ~= 'IP') and (v2 ~= 'Talk') and (v3 ~= 'Tunein') and (v4 ~= 'Living Room - Hub') ) then
        --print("Dead: " .. tc .. " : " .. difference);
        end
        
     end

end 

return commandArray 

Example of use (if relevant) i.e. output files / screen displays

N/A