It would be much much simpler to just use the Expire binding (Design Pattern: Expire Binding Based Timers).
Switch Heartbeat { expire="24h,command=OFF" }
rule "Heartbeat received"
when
Item HeartBeatSource received update
then
HeartBeat.sendCommand(ON)
end
rule "Heartbeat timer expired"
when
Item Heartbeat received command OFF
then
// code to alert that the device has been offline for too long
end
Depending on how you receive the heartbeat, you could potentially avoid needing to add the new Heartbeat Item and just add the expire to your existing heartbeat.
I use this approach for many of my sensors, though they are mostly MQTT so I don’t need a separate timer Item for the Expire binding.