Check if device is still connected withing luup code

I have a problem with the luup code execution because one of my motion sensors randomly disconnects. When this happens the following code causing issues in scenes execution:

local state = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",27) local lastTripTime = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","LastTrip",27)

How can i check if the device is connected (knowing device ID) before i execute the code so there is no errors?