Wait timeout per mode, or variable per mode?

I know RM doesn't currently support either of these, but both could be useful.

In the meantime, are there any ideas on how this rule could be better written without the mode conditionals to set the variable value for the timeout?

Stop dimmer fade
IF (Illuminance of Bedroom Motion Sensor is >= 60) Exit Rule
Color temperature per mode: Bedroom Lights
	Day: 4000
	Evening: 3000
	Night: 2700
Dimmers per mode: Bedroom Lights --> fade: 2
	Day: 100
	Evening: 70
	Night: 20
IF (Mode is Day) THEN
	Set delaySecs to 300
ELSE-IF (Mode is Evening) THEN
	Set delaySecs to 180
ELSE
	Set delaySecs to 120
END-IF
Wait for events: Illuminance of Bedroom Motion Sensor is >= 60 	OR Bedroom Lights turns off
 --> timeout: delaySecs
IF (Illuminance of Bedroom Motion Sensor is >= 60) Dim: Bedroom Lights: 0 --> fade: 2
IF (Bedroom Lights is on) Fade Bedroom Lights down to 0 over 1 minute with 3.0 seconds interval

My trigger is Bedroom Motion Sensor = Active. What I want is to turn the lights on when motion is detected, unless the ambient light is already bright enough. The lights should come on to the color temperature and level desired for the current mode, and then stay on while motion remains active or has been inactive for a certain duration, depending on mode. After the duration for motion inactivity has passed, slowly dim the lights to off. If motion becomes active again, cancel the fade and raise the lights back to the desired level. If at any time the ambient light level is sufficient, stop fading and turn off, or if the lights were turned off by any other means, stop fading.

I cannot use the ML app for this because it doesn't support fading off over time, or variable timeout duration, etc. And I cannot think of a way to do this with Delay actions per mode and Cancel delayed actions. I also am not concerned with the light level in the off state, because any other app or the physical switch already accounts for that.

This is the best I can come up with, but I still have a variable and 3 conditionals.

Triggers:

Bedroom Motion Sensor active

Actions:

Cancel Timed Actions: **This Rule**
Dimmers per mode: Bedroom Lights
	Day: 100
	Evening: 70
	Night: 20
Color temperature per mode: Bedroom Lights
	Day: 4000
	Evening: 3000
	Night: 2700
Wait for events: Bedroom Motion Sensor inactive 
	OR Illuminance of Bedroom Motion Sensor is >= lux 
	OR Bedroom Lights turns off
IF (Bedroom Lights is off) Exit Rule
IF (Illuminance of Bedroom Motion Sensor is >= lux) THEN
	Dim: Bedroom Lights: 0 --> fade: 2
	Exit Rule
END-IF
IF (Mode is Day) THEN
	Set delaySecs to 300
ELSE-IF (Mode is Evening) THEN
	Set delaySecs to 180
ELSE
	Set delaySecs to 120
END-IF
Set waitSecs to (delaySecs + 60.0)
Fade Bedroom Lights down to 0 over 1 minute with 3.0 seconds interval --> delayed: delaySecs(cancelable)
Wait for events: Illuminance of Bedroom Motion Sensor is >= lux 	OR Bedroom Lights turns off
 --> timeout: waitSecs
Cancel Timed Actions: **This Rule**
IF (Bedroom Lights is on) Dim: Bedroom Lights: 0 --> fade: 2
1 Like