While loop doesn't stop


1) Give a description of the problem
While loop at line 55 doesn’t stop and keeps dimming until the light (Dimmer2) is completely off although halfway through the button (Keypad3) isn’t held anymore.

2) What is the expected behaviour?
I thought the loop would terminate as soon as the button wasn’t held anymore.

3) What is happening/not happening?
Refer to 1

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


5) Attach logs after turning logging level to Full


The problem is that a button being ‘held’ doesn’t mean you have your finger on it. It means you held it down for long enough for the button to decide you had ‘held’ it rather than ‘pushed’ it. So the piston is running in response to an event. The ‘gets held’ will remain true until something else causes the piston to fire, or it exits. Currently, buttons in SmartThings don’t seem to have the idea of ‘pressed/released’ even if the hardware does (and I don’t know if it does). They just say they’ve been pushed / held / double pushed etc.

I’ve never worked with dimmers, but I’m guessing that dimming to 0% will also set the switch to off? Otherwise the only reason your piston stops looping is because after about ten seconds one of the ‘waits’ will cause the piston to exit and start up again rather than just do a busy wait.


On top of everything @orangebucket said,

in general, 1 second waits are not going to fly with webcore.
In my experience min wait (for WAIT to work) 4-5 seconds and up…
30 seconds or more is the better.

For HELD to work as a dimmer (what you are trying to do)
you can use it in an IF block BUT after each held you need to wait (not a command, your actual finger) 4-5 seconds minimum.


Good advice, thank you. I’ll get on editing.


I’ve tried longer wait times but it was too long a pause. I’ve decided that dimming in real time like using hardware isn’t a realistic goal for using a WebCoRE script. Here is the updated script I’ve come up with. Every held action dims up or down and you need to register a new held state for every step. It’s not very practical but it works. Variables are mainly there just because I wanted to practice using them being new to WebCoRE.


Yes you’ll find some amazing things about Webcore and some not practical things as well (of course, devices also play a huge role in this)

My biggest dissapointment was, not being able to create a “lux sensor that changes the lights according to outside day light.”
But not a chance:))))


You’re right, it depends on the device. I was trying to use an Ikea up/down button as a dimmer. That’s what it’s supposed to do with an all Ikea setup but difficult if not impossible to achieve with ST/Webcore.
I’m intrigued by your lux sensor idea. Can you elaborate what you want to achieve with it?


instead of a regular ON/OFF action, i wanted my lights acting according to outside brightness.
Lets say, (I’m making up all the lux numbers right now)
it’s 5pm and outside lux is 5000, so the lights are dimmed 40%
it’s 5.02 pm and it gets darker now, outside is down to 4000 so lights are up to 60%
it’s 2pm BUT a it’s 4000 outside (maybe a cloudy day) lights are 50% maybe… cloud is gone, ok lights are out…

So far it’s doable BUT i wanted lights change to be incremental instead of sudden (40%, 41%, 42%, 43% ohh getting lighter outside, 42%, 41% ) so that you never realize what’s happening outside, your inside lights are insync (but reversed) with outside…

What happened was,
The sensor is reading 5000 and the lights are 50% great but a minute later it gets darker BUT my sensor is still reading 5000, maybe a couple of minute later, now sensor finally caught up but all of a sudden down to 3000 etc… and all the % increments skipped…I tested this with the office and it felt like a night club LOL

Does that make sense?


It makes complete sense. Haha, I’ve turned my living room into a night club a few times too trying to figure out how to use my light sensor.

I think it’s a great idea, kind of similar to but much more advanced compared to what I do with my living room indoor readings. From what I understand, you’ve already figured out a script that can do what you want but the light sensor is letting you down because the reading increments are too far apart to be smooth.

I have a Fibaro motion sensor that also reads ambient light in lux. Because it’s a Z-wave device you can change its settings. It has two different ways that it reports lux data to the hub. You can set a time interval for the reports and also or you can tell it to report if there’s an X lux amount of change. So in your example, you could make it send readings even every 5 seconds for detailed adjustments but that would keep the traffic and the device busy and it would also kill the battery very soon. But it should still provide the detailed lux data you need. What light sensor do you use?

I’ve set my sensor to take indoor readings and to switch on or off my living room lights. Because it is measuring the very place it is adjusting, it causes a self referential paradox in a way. When it turns on the lights, there’s a jump in light amount and if the threshold settings are too close, then I get the night club action. When the threshold is far apart enough to prevent constant switching on and off, the living room becomes too bright for example in the morning before it turns off the lights. I’m thinking of a buffer action script for it now.


I believe it was a Samsung motion (multiple) sensor

Yes I had that problem too:))))
After that I placed the sensor outdoors and put it in a box:)