Porch light automation - some design help required


#1

1) Give a description of the problem
I’m looking for some guidance on how to best configure this piston.

It is not working as I expected when I put it together
example: - I have had to manually subscribe to events as the door (contact) sensor trigger was not working. i have also had to set the contact sensor to be ‘opened for at least 1 second’ on a basic trigger when the door was closed, the piston stopped.

I’d really appreciate if someone could give me some pointers to ensure it will be reliable.

Also, I have a routine to power on at sunset, power off at 10pm (bed) and also to switch on at 7:30am and off again at sunrise. Is this best to be kept separate or in the same piston?

2) What is the expected behavior?
I want the light to come on at sunset (handled as a Smarthings routine currently)
When either the motion sensor or door sensor is triggered, I want the light to go full brightness then fade after 1 minute of inactivity - either to 5% if before 10pm or 0% / off if after 10pm
At 7:30am I want the light to come on (handled as a Smarthings routine currently) until Sunrise (handled as a Smarthings routine currently)

3) What is happening/not happening?
I’ve had to manually subscribe to events on the door trigger as it wasn’t firing
This morning I opened the door and the light was only at 5%

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach any logs (From ST IDE and by turning logging level to Full)
I’ll gather logs and submit tomorrow morning as they have rolled over

Thanks

Aidan


#2

I am by no means an expert here, but I think you need another if statement down in your Else section to say If time is after 10PM. So on line 33 insert an If statement like line 23 but the condition is time is after 10PM.


#3

I’ve always had trouble with the “was open for…” statements. They don’t really get subscriptions even though they are triggers. And there is no clear timeframe. Does it mean “was the contact open for the last 1 second” or “was the contact ever open for 1 second”.

For my situation, I did something like

if motion 1 changes to active
then
    if contact 1 changed in the past x seconds
    then if...

1 second is also way to short. The event might take 1-2 seconds to actually reach ST/WebCore. You should pick something longer (10? 30?) and see if it is more stable.

Also, you have “time is before 10pm” but then “only fade while night”. If night is different from 10pm then you may have different results from “night” until 10pm.

Seeing the light at 5% in the morning makes perfect sense. If you come in at, say 8pm, then your if statement will dim the light (line 30) to 5% and leave it there. It would never turn off thereafter.