Thanks Nick, Josh. That works very well now. I also replaced the magnet with one I bought off Amazon that seems to work better than the magnet that came with cases even through its feels much weaker.
Here is the new code I'm using based on your suggestion. Let me know if it can be improved upon.
Class Type1Sensor
Shared sensorMessage As String
Shared sensorType As Integer
Shared sensorInterval As Integer
Shared TempF As Float
Shared TempC As Float
Shared BattVolt As Integer
Shared strBattVolt As String
Shared Event Boot()
sensorType = 1
sensorInterval = 5 //minutes
sensorMessage = "closed"
End Event
Shared Event keepalive() RaiseEvent Every 10 Seconds
BattVolt = Device.BatteryVoltage// Get battery voltage
TempC = TempSensor.GetTemp
TempF = TempSensor.ToFarenheit(TempC)
MQTT.BeaconPublish(dataType.TEMPERATURE, TempF, BattVolt)
End Event
Shared Event inSync() RaiseEvent Every 60 Seconds //keep the status inSync with dashboard in case of fast transistations
BattVolt = Device.BatteryVoltage// Get battery voltage
TempC = TempSensor.GetTemp
TempF = TempSensor.ToFarenheit(TempC)
If ReedSwitch = True Then
sensorMessage = "open"
Else
sensorMessage = "closed"
End If
MQTT.Publish(sensorType, sensorInterval, sensorMessage, TempF, BattVolt)
Thread.Sleep(10000)
Thread.ClearHardwareEvent()
End Event
Shared Event ReedSwitchChanged()
//initialize system variables
If ReedSwitch = True Then
sensorMessage = "open"
LedRed = True
Else
sensorMessage = "closed"
LedRed = False
End If
BattVolt = Device.BatteryVoltage// Get battery voltage
TempC = TempSensor.GetTemp
TempF = TempSensor.ToFarenheit(TempC)
MQTT.Publish(sensorType, sensorInterval, sensorMessage, TempF, BattVolt)
Thread.Sleep(10000)
Thread.ClearHardwareEvent()
End Event
End Class