How to handle many devices the same


#1

1) Give a description of the problem
I have several GE/Jasco Dimmers all running the NuttyTree DTH to allow for double tap. I didn’t want to write a Piston for each one, so I was trying to have them all behave the same with a single Piston.

2) What is the expected behaviour?
For each of these six dimmers, I would like them to be set to 100% if they were double tapped up (button #1). This worked when I first set it up with one specified device.

3) What is happening/not happening?
I tried to convert the Piston to use a ‘for each’ to handle all of my devices, and now it isn’t picking up on the event. It is even telling me that is does not subscribe to any events now. I’m guessing I can’t use ‘for each’ this way. Is there another/better way?

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

5) Attach logs after turning logging level to Full
None


#2

Why did you need to use FOR EACH for this piston…?

if you did that to make sure EACH device will be set level to 100, you don’t need that i believe


#3

have you checked out the mirroring option in Smart Lighting? :slight_smile:


#5

Haha, yes, I use that elsewhere. In this case, I don’t want them all to turn on. I want if their switch is double tapped up, then that one light is set to 100% and the rest are left alone.


#6

So if I just take out the ‘for each’ then the {$device} variable will only act on the one device that triggers it? How do I specify it from my array of devices?


#7

I just got it functioning by adding an additional if condition that subscribes to the events. If dimmer ‘White Bulb 1’ is double tapped up (button #1) it sets only that dimmer to 100% and if it is double tapped down (button #2) it sets only that dimmer to 25%. The rest of the dimmers are not affected. This seems messy to me, though. Is this a proper way to do this?


#8

@RobertB I don’t want to misguide you FYI but here is a variable works.

device dimmers = bulb 1, bulb2, bulb3, bulb4,

now from this point on what ever you do with the variable DIMMERS, all of the devices under that variable will be equally effected.

Turn ON dimmers
will turn on all of the switches in that variable


#10

Hi Ike,

Okay, that was what I thought. Thank you for the clarification. This was why I introduced the ‘for each’ to isolate the device that the action is taken on to the device that triggered the event. I definitely don’t want to turn on all of them each time one is double tapped.

Is there a cleaner way to do this isolation for a given array of devices than what I posted in post 7 two above?


#11

Just for the clarification,

  • you have a single button or multiple? (zwave or zigbee etc)
  • You want to push that button and then what do you want to achieve with lights?

#12

I have six in wall GE z-wave dimmers (assigned to dimmer variable). They each are in different rooms and are controlling different lights. The DTH that I’m using recognizes double tapping up on the dimmer toggle switch as button #1 pressed. I would like when I double tap up on the wall dimmer (which is pressing button #1 logically), then its associated light(s) turn on at 100%.


#13

ok i got it…
If there is a neat way of doing this in a single piston it’s above my paygrade:)
there is “save matching devices” to a variable feature that I use a lot but in my humble and still learning opinion, that would a very messy piston for your needs…

I’d recommend creating different pistons for each dimmer.

Actually creating different piston for each rooms need… (most people here deal with 100s of pistons)


#14

haha okay, thanks for the help. The way I have it in my second webcore screenshot (post 6 or 7?) is actually working as I would like it from the single piston. My button #2 (double tap down) is also working in that one and setting the proper lights to 25%. I just didn’t know if there was a cleaner way to achieve the same thing. I have only done a handful of Pistons so far so I’m definitely in learning mode.


#15

When I hear someone seeking “clean code”… (which is always a good goal) … One of the main priorities is to have the least amount of code processing at any given event.


In a nutshell, by you insisting on a FOR EACH loop… this means that it loops 6 times when anything changes… yet only controls one device. Essentially, 17% of your code processing is actually useful, and the remaining 83% is a waste of resources.

At the risk of repeating the above, I would make one trigger per piston, without any looping.


I guess another way to say all of this:

  • Are you trying to make “pretty” code that is appealing to the eye?
  • Or are you trying to make code that runs smoothly and efficiently in your SmartHome environment?

#16

To see this in action, turn Logging Level to Full and press a button.

Your log will likely be near 80 lines (at each and every button press), instead of about a dozen lines if I wrote the piston.


On an unrelated note, placing a trigger inside another trigger is also asking for trouble…
(lightning bolts should always be top level, or far left un-indented)


#17

this is deffinetly with in the range of @WCmore paygrade:))


#18

Hello WCmore! Thank you very much. That was super helpful. I see why you justify your paygrade :slight_smile: I guess I’m coming from a higher level programming world where “don’t repeat yourself” (DRY) is the mantra. I can see how that could make it “prettier” for humans, but more work for the system. I ran my code in Full logging level as you suggested and it took 38 lines.

For arguments sake, I just refactored it to this, taking in your suggestions about removing the ‘for each’ and un-nesting my triggers. It now runs with 13 lines of logs, but still accomplishes my goal of doing it with one Piston and not repeating myself. What do you think? I still should have one piston per device?


#19

This last version is much better!!

No looping, and only runs top to bottom once per button press. :+1:
(currently, each execution is about 50/50 instead of 17/83)


#20

Great to hear! Thanks for the lesson! Learning a lot and having fun :slight_smile:


#21

That’s a great attitude!

It really is fun & challenging… One day, SmartHomes will be as common as SmartPhones…
(although right now, most folks still look at me funny when I try to explain what I do for a living, LOL)