Can someone please tell me if this is possible and how I can write it (contact sensor/ lights

For the contact sensor, you could write a rule that does this, but it might be easier to "translate" the contact sensor into a motion sensor so you can use it in standard motion-lighting-type apps instead. Here is a post from staff that allows you to do that: Motion Lighting conundrum.

For the dimming feature you asked, the "Set Level" command on almost any device lets you specify both a level and transition time, so if you use this instead of on (or off), you can control how fast it happens. This works in either direction. (A small note: enabling "prestaging" will make the bulb not turn on with a Set Level if it is off, since that is what the "staging" thing means. But this setting is off by default and not supported on all devices anyway.) So you can do something like "Set Level" to 100% with a transition time of 15 seconds and have it slowly fade to 100 over that time. Not all apps let you do this, and some call it something like "fade time" instead.

If you did want to do this with Rule Machine, something like this should work:

Trigger: Contact sensor opened

Actions:

Cancel Delayed Actions
Dim: Hue Light: 100% --> fade 15
Wait for events: Contact sensor closed
Delay: 0:00:20 (cancelable)
Off: Hue Lights

That being said, that rule might not do exactly what you want unless you want the lights to turn off every time you close the door (which I suppose you might if going to bed and wanting the lights to turn off is the only reason you'd close it; what I mean is just that, as you can observe, it ignores other things you might care about in the room like motion sensors).

7 Likes