Full Proof Lights off No Motion optimization


#1

1) Give a description of the problem
I have borrowed ideas from many people to create a simple but functional light off no motion in all my rooms and its been working flawlessly until today.

if switch is on
and motion is inactive
then
  wait 10 min
  turn switch off
end if

This morning I noticed a light still on so I investigated and the light status was reported on and motion was inactive so everything was working. I am assuming this does not work because there is not trigger so I changed it to.

if switch is on
and motion changes to inactive
then
  wait 10 min
  turn switch off
end if

The problem with this is if the motion sensor isn’t working or if was turned on via alexa or some other remote means it wouldn’t turn off.

So I added another section

if switch changes to on
and motion is not active
then
  wait 15 min
  turn switch off
end if

2) What is the expected behaviour?
The piston seems to work just fine but I feel like there has to be a better way. I have 10 of these pistons so I want them to be optimized I am pretty certain this is way too many lines for something so simple. Not sure how that affects webcore but I would like a smooth running machine.

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


#2

If you have been here very long, you will know that I am a fan of small, task specific pistons, if possible. You have lots going on in this piston. There are MANY ways to accomplish your tasks. However, generally, I try not to trigger my piston from within the piston as you are doing with line 46 and the trigger at line 50 and the condition at line 26. Personally, I would separate the “ON” and “OFF” operations into separate pistons.


#3

I couldn’t agree more. I have lots of pistons all with simple straightforward tasks which is why I am trying to simplify this one.

What I am doing on 38-48 is turning the light back on if motion is detected within 30 seconds. My kids would complain that the lights would turn off when they were lying in bed reading so should the lights be shut off due to lack of motion they would turn back on if they waved their arms within 30 seconds. I stole that idea from someone on here and the kids really like it.


#4

Two things jump out at me:

  1. Device variables may be your friend down the road. You mention having 10 such pistons. If the logic stays the same and only sensors and lights change, then it is nice to just reassign the devices at the top. Less chance for tired eyes to miss something.

  2. My personal preference is to eliminate “Wait” statements, and instead trigger based on the sensor being in the particular state for the desired time.


#5

Based on what I think you are trying to do …


#6

That’s awesome thank you for taking the time to make the example., I really like the idea of tying them all together. I am stuck on one part. How in your example do you tie a specific motion sensor to a specific switch?

The Loft for example has a “Loft Motion Sensor” and a “Loft Light” The Office has an “Office Motion Sensor” and an “Office Light” etc…


#7

You just need to edit the device variables in the “define” block. For example, click on “Switch 24” and select “Loft Light” from your drop-down list.

I only did one quick test, so try out one room to make sure that it does what you expect. Once you have a confirmed good piston, you can make duplicates that only need the two device variables changed.

image


#8

Oh I see what you are saying. I misunderstood. I thought you were saying to put all rooms into one piston. I will test it out. Thank you!


#9

Of course, I am going to throw this out there. If you are a SmartThings user,… You may want to start exploring Automations or the Rules API as a replacement for webcore pistons. Notice I said exploring … as the end of groovy and webcore could hit everyone by the end of the year. Better to start preparing now :slight_smile:


#10

Good caveat. I have not kept up on the ST drama.


#11

An X Samsung user.


#12

Sad but true. I moved all of my webcore to Hubitat because of this reason. I hope that webcore will continue to be maintained there.


#13

I’m considering moving to Hubitat for this reason. Are there any good guides on how to migrate?


#14

There are a few threads on migrating. I did not follow a particular “guide.” Lots of info in discussions (just search in the HE threads). But I started here : https://community.hubitat.com/t/smartthings-migration-new-to-hubitat
I thought that I could move everything over in one day (40+ devices, 12 echos, 5 pads, a whole home audio system, security system, Ring doorbell…you get the picture) but it really should take several days. If you will allow the mesh to adjust and settle and not force things, your device inclusion process will be much less painful. I don’t remember having much difficulty moving my 200+ webcore pistons over. There are some nuisances in the HE webcore that required minor adjustments to a few of my pistons. Overall, I am very happy with HE. I’m still running my ST hub. I have a few devices remaining there. I am hopeful that the ST environment will improve.


#15

Thanks for the info, I’ll have a look. I suspect I should probably just bite the bullet and go for it!

I’m put off mainly by moving all devices to a new hub, some are behind light fittings/switches etc and as you mentioned getting everything to mesh properly again.