Variables (string) are not updating as expected; review my beginner code and offer changes


#1

1) Give a description of the problem
Piston to control a switch that turns on/off a hot water circulator. Overall this switch should get turned on in the AM, off when household is at work/school, on in evening, off when asleep. I have tried to insert comments to demonstrate. With each “action”, I have tried to get update a variable with what/when the action occurred. This does not seem to be updating with events. It updates when I switch on/off the “guest mode” switch and when I run a piston test.

2) What is the expected behavior?
Described above. Two variables should be updated when piston directs switch to be turned on/off.

3) What is happening/not happening?
Variables (LastEvent and LastEventTime) not updated as expected. They do update appropriately with guest mode switch (is a virtual ST on/off switch) being turned on/off, but not the other events that are time-based or lack of motion based.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
Let me know if logs will help but I think I am just missing something with the way the code is written.


#2

Line 31, 34 & 37 cannot all be true at the same moment…
Perhaps you meant to say OR instead of AND??

Also, the only other triggers you have are “Switch 1”. (lines 73 & 86)
This means that lines 49-71 will only run if something else triggers the piston.
(such as pressing TEST)


Sometimes, I code similar projects this way:

Every day at X am             <-- Trigger
    IF Location is whatever   <-- Condition
        Then turn on
    END IF
END EVERY

Every day at Y pm             <-- Trigger
    IF Location is whatever   <-- Condition
        Then turn off
    END IF
END EVERY