Restore Previous Dimmer Level Does Not Execute

Using the following PLEG, the goal is to have the dimmer level restored after no motion is detected. However, the LastDimLevel variable has not changed from 10 for weeks. So the restored dimmer level is always 10 and not the actual previous level.

Triggers
BathMotion Bath_Motion Sensor is tripped
NoBathMotion Bath_Motion Sensor is not tripped

Device Properties
LightLevel Bath Lights LoadLevelStatus

Conditions
LastDimLevel BathMotion ? LastDimLevel : LightLevel
Lighten BathMotion AND (LightLevel > 0) AND (LightLevel < 9)
Brighten BathMotion AND (LightLevel > 9) AND (LightLevel < 15)
RestoreDimLevel (LightLevel > 8 AND LightLevel != 10) AND (NoBathMotion; NOW > 1:01)

Actions
Actions for Condition: Brighten
Bath Lights SetLoadLevelTarget newLoadlevelTarget=61

Actions for Condition: RestoreDimLevel
Delay 10 – Prevents fighting manual operation of the switch.
Bath Lights SetLoadLevelTarget newLoadlevelTarget={(LastDimLevel)}

Actions for Condition: Lighten
Bath Lights SetLoadLevelTarget newLoadlevelTarget=9

Yep … you found a bug in cascading dependencies through the conditional statement.

To work around:
LastDimLevel ((LightLevel != LightLevel) OR BathMotion) ? LastDimLevel : LightLevel

This propagates the dependency while inserting (F OR BathMotion) which is equivalent to BathMotion.

I will of course fix this.

Hooray! I found it. Do I get a cookie?

Thank you for the workaround.

Edit: Still not getting the results I desire. With the workaround, LastDimLevel is now immediately changed to present LightLevel, so the lights ramp up, LastDimLevel immediately gets set to the new ramped up level, and the later RestoreDimLevel action sets target at LastDimLevel which is now equal to LightLevel not the previous and desired LightLevel.

I suppose that what I really need to do is have the LastLightLevel variable set at the beginning of the Lighten or Brighten action rather than being set by a condition. But, I’m unsure if that’s possible.

Here is the patch …

Sorry my browser has all of my cookies :slight_smile:

Richard, thanks for the patch! After installing the patch I went back to condition:
LastDimLevel BathMotion ? LastDimLevel : LightLevel

LastDimLevel is now always equal to LightLevel. Naturally this does not return to a previous dim level as desired.

It should track … as long is it was not set because of motion.
This assumes that motion stays active during the duration it takes to send the Dimmer level.

The trip points for Lighten and Brighten seem strange.

I would assume LightLevel is in the range 0 to 100

[quote=“RichardTSchaefer, post:6, topic:177248”]It should track … as long is it was not set because of motion.
This assumes that motion stays active during the duration it takes to send the Dimmer level.[/quote]
My problem is that I am trying to set the LastDimLevel when motion starts so that I can return there after the motion has ended. I’ll look at this some more and try to figure out a way to make it work.

[quote=“RichardTSchaefer, post:7, topic:177248”]The trip points for Lighten and Brighten seem strange.

I would assume LightLevel is in the range 0 to 100[/quote]
Yes LightLevel 0 to100.

The trip points are intentionally strange. The light is set at certain “resting levels” by scheduled scenes. Detected motion, when the light is already on at one of these resting levels is supposed to ramp the light up, but the amount of increase is different depending on the current resting level. I don’t want the brightening logic to interfere with levels set manually at the switch and also don’t want one resting level to be stair stepped to the next resting level, hence the strange trip levels and strange scheduled resting levels of 1% and 10%.

The goal is for the schedule to set the light at 10% in the evening and if there is motion, temporarily ramp up to 61%. After the motion stops, if the light is at 61% return to the previous level(10%). If someone operates the switch manually, so that it is no longer set between 10 and 14 or at 61, then don’t change the dim level.

Later in the evening, another scene changes the light night light mode and the dim level is set to 1%. If it sees motion it should ramp up, but if it reaches 10% or more, then the logic would cause it to again ramp up to the even brighter level. To avoid this, I ramp it to 9% and when the motion stops, it should return to the previous 1%. But again, if someone operates the switch manually and its load level is now outside the strange and narrow range, then don’t reset the newLoadLevelTarget.

Except, it doesn’t work properly. At present, with the patch, the light ramps up and stays there.

What kind of motion detector do you have …
When it trips … how long does it stay tripped ?
Your logic should work unless the motion is only tripped for a second … and it takes a second or more for the light to ramp up.

In this case it is a Schlage motion sensor. By default the return to untrip is 4 minutes. But, I changed it for testing purposes. The only other time delay is “Test mode” which untrips after 5 seconds. SO my sensor switches form tripped to untripped after ~5 seconds.

I think 4 minutes might mask the issue, but I don’t see it fixing the problem. I will re-test at the default 4 minutes, tomorrow. I’ll let you know if this resolves my issues.

Nope, it still doesn’t behave correctly when using the LastDimLevel BathMotion ? LastDimLevel : LightLevel condition. I have resorted to hard coding values and now (mostly) have the desired behavior. It’s not perfect or as elegant as I would like, but the following PLEG with a 5 second reset of the motion sensor comes closest to providing the behavior that I desire.

Triggers
BathMotion Bath_Motion Sensor is tripped
NoBathMotion Bath_Motion Sensor is not tripped

Device Properties
LightLevel Bath Lights LoadLevelStatus

Conditions
Lighten BathMotion AND LightLevel == 2
Brighten BathMotion AND LightLevel == 10
RestoreLightenLevel LightLevel == 9 AND (NoBathMotion; NOW > 1:00)
RestoreBrightenLevel LightLevel == 61 AND (NoBathMotion; NOW > 1:00)

Actions
Actions for Condition: Brighten
Bath Lights SetLoadLevelTarget newLoadlevelTarget=61

Actions for Condition: Lighten
Bath Lights SetLoadLevelTarget newLoadlevelTarget=9

Actions for Condition: RestoreLightenLevel
Delay 10
Bath Lights SetLoadLevelTarget newLoadlevelTarget=2

Actions for Condition: RestoreBrightenLevel
Delay 10
Bath Lights SetLoadLevelTarget newLoadlevelTarget=10

It’s still not perfect. There are still a few of issues, beyond the amateurish hard coded values.

PLEG - Sometimes, though infrequently, the Restore??ightenLevel will activate within several seconds of NoBathMotion, immediately bounce back up to the previous higher level and then 10 to ~100 seconds later Restore??ightenLevel. Visually it looks like the action trips, realizes it is in error, corrects itself and then functions normally.

Vera & PLEG - Due to Vera’s 1 minute resolution, the dim levels will be reset anywhere from 10 seconds to ~100 seconds. Not a big problem, but there is a level of unpredictability that I don’t like.

Vera? - You may also notice that I have changed my lowest “resting level” to 2%. For some reason, Vera has for some reason started to show/interpret the switch as 0%(Off) after polling it. This despite it actually being set at 1% and the light is indeed still On. Though it did not behave this way, even at 1%, before I started experimenting with this PLEG, using 2% seems to avoid the problem. I just hate inexplicable results.

You might try:

LastDimLevel (BathMotion; LightLevel < 20) ? LastDimLevel : LightLevel

[quote=“RichardTSchaefer, post:12, topic:177248”]You might try:

LastDimLevel (BathMotion; LightLevel < 20) ? LastDimLevel : LightLevel[/quote]
This works better than the earlier attempts and the workaround, but its behavior is still inferior to the latter hard coded PLEG method. This new condition works well for the higher dim level, but the 2-9% Lighten range doesn’t behave as desired when there are double trips.

I’ll likely use your recommended method in the future with setups that only use a single range of dim levels.