Lights return to origin on/off state and dim level after movement or contact trigger

I want some lights to dim up when a door is opened or a motion is detected, but I don't want it to shut off into darkness after a while. I want it to remember it's original dim level.

From the beginning I thought this was a simple task. Just remember the original dim level in a local variable before dimming up, then just reset dim level to original level after 5 sec when door i closed.

This works sometimes but very often the variables seams to get the values overwritten with the value I set when lighting up so the dim level does not go back to original.

I also have problems with combinations of bulb switch is on/off and the dim level. For example if dim level is 20 but switch is off. I should be able to test if on/off but that seams also confusing. Says switch on but actually are off and dim is > 0.

Seams like some kind of timing or threading issues between variables and actual values, or by bad coding :slight_smile:
Best would be if there already are som good apps this. I cant believe Iam the first that don't need this feature.

Example of my last code before gave up:

Trigger:
Altandörren changed

Action:
IF (Altandörren open(F) [FALSE]) THEN
Set OriginalLevel to Skarven Dimmer
Dim: Skarven: 20
Cancel Delayed Actions
ELSE
Dim: Skarven: OriginalLevel(20) --> delayed: 0:00:05 (cancelable)
END-IF

Just opening and closing door two times gives this log. As you can see it works the first time, then it remember wrong OriginalValue the second time.

app:10772021-02-16 22:01:37.937 infoDelay Over: Dim: Skarven: OriginalLevel(20) --> delayed: 0:00:05 (cancelable)
app:10772021-02-16 22:01:32.840 infoAction: END-IF
app:10772021-02-16 22:01:32.818 infoAction: Dim: Skarven: OriginalLevel(20) --> delayed: 0:00:05 (cancelable)
app:10772021-02-16 22:01:32.807 infoAction: ELSE (do actions)
app:10772021-02-16 22:01:32.804 infoAction: Cancel Delayed Actions (skipped)
app:10772021-02-16 22:01:32.800 infoAction: Dim: Skarven: 20 (skipped)
app:10772021-02-16 22:01:32.796 infoAction: Set OriginalLevel to Skarven Dimmer (skipped)
app:10772021-02-16 22:01:32.791 infoAction: IF (Altandörren open(F) [FALSE]) THEN (skipping)
app:10772021-02-16 22:01:32.749 infoAltandörr öppnas belysning Triggered
app:10772021-02-16 22:01:32.732 infoAltandörr öppnas belysning: Altandörren contact closed
app:10772021-02-16 22:01:27.001 infoAction: END-IF
app:10772021-02-16 22:01:26.998 infoAction: Dim: Skarven: OriginalLevel(20) --> delayed: 0:00:05 (cancelable) (skipped)
app:10772021-02-16 22:01:26.985 infoAction: ELSE (skipping)
app:10772021-02-16 22:01:26.971 infoAction: Cancel Delayed Actions
app:10772021-02-16 22:01:26.917 infoAction: Dim: Skarven: 20
app:10772021-02-16 22:01:26.905 infoAction: Set OriginalLevel to Skarven Dimmer
app:10772021-02-16 22:01:26.890 infoAction: IF (Altandörren open(T) [TRUE]) THEN
app:10772021-02-16 22:01:26.816 infoAltandörr öppnas belysning Triggered
app:10772021-02-16 22:01:26.804 infoAltandörr öppnas belysning: Altandörren contact open
app:10772021-02-16 22:00:56.814 infoDelay Over: Dim: Skarven: OriginalLevel(1) --> delayed: 0:00:05 (cancelable)
app:10772021-02-16 22:00:51.714 infoAction: END-IF
app:10772021-02-16 22:00:51.694 infoAction: Dim: Skarven: OriginalLevel(1) --> delayed: 0:00:05 (cancelable)
app:10772021-02-16 22:00:51.690 infoAction: ELSE (do actions)
app:10772021-02-16 22:00:51.685 infoAction: Cancel Delayed Actions (skipped)
app:10772021-02-16 22:00:51.682 infoAction: Dim: Skarven: 20 (skipped)
app:10772021-02-16 22:00:51.675 infoAction: Set OriginalLevel to Skarven Dimmer (skipped)
app:10772021-02-16 22:00:51.671 infoAction: IF (Altandörren open(F) [FALSE]) THEN (skipping)
app:10772021-02-16 22:00:51.608 infoAltandörr öppnas belysning Triggered
app:10772021-02-16 22:00:51.599 infoAltandörr öppnas belysning: Altandörren contact closed

app:10772021-02-16 22:00:45.960 infoAction: END-IF
app:10772021-02-16 22:00:45.956 infoAction: Dim: Skarven: OriginalLevel(1) --> delayed: 0:00:05 (cancelable) (skipped)
app:10772021-02-16 22:00:45.942 infoAction: ELSE (skipping)
app:10772021-02-16 22:00:45.924 infoAction: Cancel Delayed Actions
app:10772021-02-16 22:00:45.864 infoAction: Dim: Skarven: 20
app:10772021-02-16 22:00:45.811 infoAction: Set OriginalLevel to Skarven Dimmer
app:10772021-02-16 22:00:45.806 infoAction: IF (Altandörren open(T) [TRUE]) THEN
app:10772021-02-16 22:00:45.693 infoAltandörr öppnas belysning Triggered
app:10772021-02-16 22:00:45.674 infoAltandörr öppnas belysning: Altandörren contact open

Can you not use a capture to do this?

yes. as a screen capture?
I think Iam on to something. The bulb I tried to use are on a hur bridge so there seams to be a new layer of problems. Works better with bulb direct on hubitat.

The feature I should really want to see though as some kind of built in app. Also for outdoor to lightup where there are movement but only go back to original level after a while.

No. I meant use a capture command to save the state (level) of the dimmer or switch. Then you can restore it to that state (level).

1 Like

Thanks! That did som things easier and I found my problem.
Two lights. One direct to Hubitat and an other using hue bridge.
Hue bridge light fails to restore the second time I open the door.

IF (Altandörren open(F) [FALSE]) THEN
Capture: Ljuskronan i biblioteket, Skarven
Dim: Ljuskronan i biblioteket, Skarven: 25
Cancel Delayed Actions
ELSE
Restore: Ljuskronan i biblioteket, Skarven --> delayed: 0:00:05 (cancelable)
END-IF

(probably fails to capture latest values the second time)

With Hue Bridge bulbs, this is possible: the states are not "pushed" to Hubitat immediately. Hubitat has to poll for them. By default, this happens every minute, but you can adjust the time in the Hue Bridge integration app. If you change the device from Hubitat, the Hue device should update immediately in Hubitat, so this is mostly a concern for changes made outside of Hubitat--e.g., by the Hue app, Alexa (if using Hue's native integration), or whatnot. You can check "Current States" on the device page for the Hue device in Hubitat to be sure. If that's wrong, Rule Machine will also capture the "wrong" values.

The other consideration--and I didn't look closely enough above to see if this applies to your case--is that Hubitat will not capture all states for a bulb that is off, just the fact that it is off. So, if your rule changes the color, level, or anything else, a "restore" will just restore the fact that the bulb was off. It will not "pre-stage" the old color/level/etc. back to the bulb. There are workarounds if you need one for this, one of which is to always turn the bulb on first (and capture and restore the on/off state "manually" in a variable).

1 Like

You could do a scene capture and restore, but scene display on the apps page is a bit buggy.