[Help Needed] Hue online / offline rule

I have a number of Hue bulbs around the house. All of my light switches are the dumb on/off type, which means that when I use the switch to turn the bulb off OH still reports the bulbs as being online when it isn’t

Searching the forum I found this rule, that updates the status of specific bulbs.

rule "Master Bedroom Ceiling Light"
when
    Thing "hue:0100:1:10" changed
then
var lightsStatusInfo = getThingStatusInfo("hue:0100:1:10")

if ((lightsStatusInfo !== null) && (lightsStatusInfo.getStatus().toString() == "ONLINE")) {
    Master_Bedroom_Ceiling_Light_Switch.sendCommand(ON)
} else {
    Master_Bedroom_Ceiling_Light_Switch.sendCommand(OFF)
}
end

Although the rule works, it some times causes a bulb to switch off if there happens to be a communication issues between it and the bridge. The bulb does come back on, however when this happens I often hear “Your bloody system!!! The lights gone out in the Bath room again!” resulting in the WAF level being reduced.

Having thought about this I believe a solution to help would be to add in a delay between state changes, for example if the bridge and the bulb lose their connection the rule waits for 120 seconds before the bulb is marked as offline after an additional status check to confirm.

My coding skills aren’t that great, so most of the time I search the forum in the hope that I find a good example that I can follow. I’ve not found anything this time and therefore I’m hoping it’s because I’ve come up with an idea that no one has thought about, not likely though. :smiley:

Thanks in advance for any pointers provided.

Regards,

Garry

Thanks for the pointers, I’ll take a look and see what I can pull together.