Piston waiting too long to execute action or pending/cancelling


#1

1) Give a description of the problem
Most of the time recently my pistons are getting stuck on wait commands way past when they should be taking an action. They just sit either pending in red or the timer counts up.

2) What is the expected behaviour?
Motion changes to inactive > Lights wait 2 minutes > Lights Dim > Lights wait 10 seconds > Lights turn off.

3) What is happening/not happening?
Actions not actioning consistently or cancelling.

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full
Don’t have full logs yet but will try to get some when it plays up again.

Here is a screenshot of what is happening:


#2

The “WITH” on lines 51 & 60 should have Task Cancellation Policy set to Never.

Just keep in mind with this in play, if you leave the room for a minute (changes to inactive) and then return to the room, the lights will still turn off at the 130 second mark


I usually code around this with the following:

IF Sensor's motion stays inactive for 2 minutes
Then
    Set level to 15%
    Wait 10 seconds
    Turn off
END IF

This method will not need TCP settings or the long wait.
(The timer resets each time there is motion)


#3

Thanks for replying.

I want the lights to stay on if motion is triggered during the countdown so TCP set to never won’t work for me unfortunately.

Can I and if so how would it be best to use the motion stays inactive option with the 2 timers I have (2 minutes if lights were off and 30 minutes if they were turned on before motion was triggered)? Is there a better way than I’ve done above?


#4

I would base it on my previous post. Maybe something like this:

IF Sensor's motion stays inactive for 2 minutes
and
Any of Bulb 3 or 4 switch is on
and
{WasItOff} is true
    Then
        Set level to 15%
        Wait 10 seconds
        Turn off
END IF

IF Sensor's motion stays inactive for 20 minutes
and
Any of Bulb 3 or 4 switch is on
and
{WasItOff} is false
    Then
        Set level to 15%
        Wait 10 seconds
        Turn off
END IF

One small warning though. In certain circumstances, line 31 might conflict with line 55 and/or line 64.
I recommend not overlapping numbers here.
(IE: use “less than” 15% on line 31, or change line 55 & 64 to 16%)


The other thing to keep an eye on is this branching logic:

  • On line 29, you set variable to true, if either bulb is OFF
  • On line 71, you set variable to false, if either bulb changes to OFF

I usually try to avoid conflicting statements, but to be honest, your boolean logic looks like it might flow as planned. Just keep in mind those two contradictory IFs, where the tiniest change in the structure can totally break the logic. (Remember that you have six triggers in this piston, and each event runs the code top to bottom)