Motion activated light and TCPs


#1

1) Give a description of the problem
Trying to do something that I think is super standard, and yet I have been battling with the task cancellation policies (TCP) for a few days now.

2) What is the expected behaviour?
I would like a light to turn on upon a motion trigger, and stay on for X minutes regardless of when the motion stops (I am assuming here that the motion will stop earlier than the X minutes). I would also like the light to stay on in case conditions change, e.g. if I switch off and on the light, or if I change the dimmer level.

3) What is happening/not happening?
If I leave the TCP as standard, then the light will never switch off. Indeed, after the “wait”, the task will not continue because the motion condition is no longer true.
If I set the TCP to “never”, then the light will switch off, but it will do so regardless of whether I acted on the light as explained above (e.g. having physically changed the light level) or not.

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

5) Attach logs after turning logging level to Full

+1ms	╔Starting piston... (v0.3.113.20210203)
+657ms	║╔Subscribing to devices...
+687ms	║║Subscribing to Entrance motion sensor.motion...
+755ms	║║Subscribing to Downlight entrance SW...
+756ms	║╚Finished subscribing (111ms)
+797ms	╚Piston successfully started (797ms)

#3

I have had several attempts at this and got nowhere.

There is a ‘super standard’ scenario that has been handled at nauseating length on this forum many times. That one is where lights are turned on with motion and off when motion stops (often with a delay) and there is a wish for manual override. The basic solution there is that if you turn on the light with motion you set a flag to say things are handled automatically. When it comes to turning the light off you only do anything if the flag is still set.

In your case you just want a fixed time from when motion starts so everything happens in response to the motion going active. That makes it awkward as you have to somehow stop the wait being cancelled if the piston gets an inactive event, and also know whether a light on event is you fiddling with it or the light turning on automatically.

I think you can start with:

If motion changes to active
   And
   Light is off
Then
   Set automatic=true
   Turn light on
End if

I also think you can end with:

If automatic = true
Then
    Wait X minutes
    Turn light off
    Set automatic = false
End if

That would mean the off timer would only start if the light was turned in with motion, and would be cancelled if the piston runs again and the flag is off. So we need a middle bit to detect fiddling.

If light switch changes to off
    Or
   Light level changes
Then
    Set automatic = false
End if

Hmm. Why didn’t I see that several attempts ago? Perhaps it is still wrong.


#4

I’m not sure it answers your question, but you may want to read:

  • specifically the motion examples and commentary (which some comes from this forum)