"Define" help needed


#1

1) Give a description of the problem
Are you tired of me asking for help yet? :slight_smile: I really do research before I ask, but I have trouble understanding if I read something that’s not directly applicable to my situation.

I am not sure how to use “define” in the actual piston. I JUST figured out how to define!

2) What is the expected behaviour?
When any one of five gates opens (door contact), I want my strobe light to strobe. I want it to stop strobing when that gate (or, if more than one, all gates) are closed. Basically, I want to know all my gates are closed before I let my dogs out! The strobe light is inside my front door - if it’s flashing, I know to go close a gate or gates! If it flashes and stops flashing, I know that someone closed the gate after opening it.

3) What is happening/not happening?
As you see I figured out how to Define, and how to do IF: Gates changes to" But I can’t figure out how to tell it "changes to OPEN. And then later, how to turn the strobe light off when they’re shut!
I have a test simulated switch. I figured that “Changes to ON” makes the strobe light strobe, but if that’s all I have, when I turn the switch off, the strobe light will not turn off. I need to tell it that as well, huh.

4) Post a Green Snapshot of the pistonimage

Applicable piston code! :slight_smile:


#2

Before tackling any code, I have to ask:

Does your strobe light automatically strobe when turned on? or does webCoRE have to keep sending (on/off) commands to keep it strobing?


#3

It keeps strobing when turned on. In the app, if I click “on” it will strobe until I click “off”. With a test piston and sim switch it turned on when in the app I clicked “on” for sim switch (changes to ‘on’). It did not turn off until I went to the strobe and clicked off.


#4

I apologize… I do not fully understand your flow or setup…
Which app are you referring to? SmartThings?
What is the purpose of the SimSwitch?


Can you ignore the SimSwitch for a moment, and create a test piston that sends a command directly to the strobe light? IE::

Turn on Strobe
Wait 4 seconds
Turn off Strobe

Once this piston is created, just press Test to see the results.


#5

Heh, it does not stop strobing. Here’s the piston:

and the log:
8/21/2020, 4:46:11 PM +895ms
+3ms ╔Received event [Home].test = 1598042771893 with a delay of 1ms
+131ms ║RunTime Analysis CS > 33ms > PS > 61ms > PE > 37ms > CE
+138ms ║Runtime (35882 bytes) successfully initialized in 61ms (v0.3.110.20191009) (132ms)
+140ms ║╔Execution stage started
+147ms ║║Cancelling statement #1’s schedules…
+678ms ║║Executed physical command [Gate Alarm].on() (519ms)
+679ms ║║Executed [Gate Alarm].on (521ms)
+685ms ║║Executed virtual command [Gate Alarm].wait (1ms)
+686ms ║║Waiting for 4000ms
+4698ms ║║Skipped execution of physical command [Gate Alarm].off([]) because it would make no change to the device. (6ms)
+4699ms ║║Executed [Gate Alarm].off (9ms)
+4707ms ║╚Execution stage complete. (4568ms)
+4708ms ╚Event processed successfully (4709ms)
8/21/2020, 4:46:03 PM +557ms
+1ms ╔Starting piston… (v0.3.110.20191009)
+1355ms ║╔Subscribing to devices…
+1497ms ║║Subscribing to Gate Alarm…
+1498ms ║╚Finished subscribing (155ms)
+1529ms ╚Piston successfully started (1528ms)

Sorry I wasn’t clear. I did mean the SmartThings app. I was using a sim switch I created for testing, I didn’t realize I could just click test.


#6

I had to load your first piston to see what trouble you were having. Even though you have defined a variable to contain your list of contact sensors, in your if statement, you have to treat it as a device. So instead of selecting, ‘variable’, select ‘device’, then scroll past all your devices and you will find your device variable. When you select that, then you can chose the sub-option ‘contact’ and changes to ‘open’. Hope this helps.


#7

I am confused as to why a strobe light appears as a Music Player…
(which is not normally “turned off”)

… but your log looks to me like the “Gate Alarm” is acting like a momentary trigger
(meaning the instant it is turned on, it turns itself off, and will continue to make noise until you jump thru some hoop)

This is common with home alarms, since we do not want the criminals to have easy access to turn off the noise.


If you are unable to find a way to programmatically turn it off, another option is to plug it into a SmartOutlet… This way, you can simply kill the power to shut it up.


#8

So it’s a GoControl Siren/strobe. I have the siren turned off in the hardware settings. I’m going to be stubborn and keep trying - my “home automation” budget is at an end, so I can’t get a smart outlet!

I don’t understand why it would have that momentary trigger. I may post to the thread of the writer of the Device Handler and ask.


#9

SONOFA… LOL thanks, got me further!!!


#10

Most devices designed to alert intruders, will intentionally keep their control options well hidden.
(this is smart)


#11

Ok, ok, ignoring the fact that the strobe isn’t turning off with the command, I still want to learn the proper way. Here’s the Piston turning it on if any gate opens (I hope):

I’m not sure where to insert the "turn off when (device gates) is closed, meaning that when all the gates are closed, the (alarm, whatever) shuts off.


#12

LOL I suppose, but I want to bend it to my will!


#13

It is ok to be stubborn, :grin: but I would focus on the OFF command in a test piston, as before.
(it’s pointless to create logic for a command that does not work)


#14

Gotcha. I’m posting in the device handler author’s thread now.


#15

That is smart… He/she is likely the person most familiar with the DH code…


#16

I’m not HUGELY confident, as the last post in that thread was in May. But, who knows…

If NOT - I suppose I can just use my Hallway light, as I rarely leave that one on, and all of my houses’ switches are zwave. I’ll give him a few days and then come back!


#17

Let’s use a normal bulb for this exercise…

IF any of Sensor 1 or Sensor 2's contact CHANGES      <-- Trigger
Then
    IF any of Sensor 1 or Sensor 2's contact IS open  <-- Condition
    Then
        Turn on Bulb (maybe Set color to red, for an alert?)
    Else
        Turn off Bulb 
    END IF
END IF

In this example, the piston runs when any contact changes (in either direction)

At that point:

  • If ANY of them are open, execute the THEN block.
  • If ALL of them are closed, execute the ELSE block.

#18

So in this instance, “Else” would be used.

I swear some experience Webcore person once posted that they rarely use “Else”… I read it quite a while ago and don’t remember why they said that…

But - that does makes sense to me. The trigger (in my case) would be ANY gate changing EITHER from open to closed, or closed to opened. It would be the state of ONE of them changing. Or more than one, I suppose… Cool!!!


#19

That was probably me. :man_facepalming:

Although that advice is actually very good…
99% of pistons can be created without using ELSE blocks.
(and they tend to confuse newbies)


When I break that “rule”, I typically only use them in very specific situations.

(1) I want to reduce triggers (like the example above)
(2) I want to reduce code (like the example above)
(3) When there is only a single condition attached (like the example above)

(I may occasionally break #3, but rarely)


#20

Heh, how long have you been doing this??