Save and reset to original bulb level


#1

1) Give a description of the problem
When doorbell is pressed, it should switch the light for 90 seconds to 100%. After that it should reset to the original level, which was before ringing the bell.

2) What is the expected behaviour?
It should save the state just at the beginning

3) What is happening/not happening?
It updates the state while running the Piston

4) Post a pic

5) Attach logs after turning logging level to Full

`25.12.2021, 18:35:35 +84ms
+0ms ╔Received event [Mein Zuhause].time = 1640453736837 with a delay of -1754ms
+110ms ║100
+256ms ║Fullified
+264ms ╚Event processed successfully (264ms)

25.12.2021, 18:34:06 +656ms
+1ms ╔Received event [VButton].switch = on with a delay of 38ms
+185ms ║Setting up scheduled job for Sat, Dec 25 2021 @ 6:35:36 PM CET (in 89s)
+192ms ╚Event processed successfully (192ms)`


#2

A few observations…

When we hard code variables up top (in the “define” section), then that data is forced each time the piston runs.

Usually, I “Set variable” somewhere down in the code, and leave the top blank (no value set) so it remains flexible, and only changes when I want it to.


Also, I would encourage you to change your commands from “Adjust level by” to “Set level to”. The later is specific, while “Adjusting” is based on whatever is currently seen…

Here is the basic structure:

define
    integer firstState = (no value set)
end define

execute
    IF Doorbell is pressed
        Set variable firstState = Device's level
        Set Device's level to 100
        Wait 90 seconds
        Set Device's level to {firstState}
    END IF
END EXECUTE

#3

Worked, thank you!