Piston called via URL not behaving as expected


#1

1) Give a description of the problem
Piston executes when I don’t want it to.

2) What is the expected behaviour?
My piston is designed to be called by a Raspberry Pi app via its external URL. The piston has two things to do: 1) toggle a virtual switch, and 2) speak text as long as it’s not between midnight and 9:30am. I want the piston to only execute if called by my app.

3) What is happening/not happening?
It works when it’s called BUT it keeps also executing at 9:30am and midnight every day. I only want it to execute when called via url by my app. Apparently because I have an IF statement based on time, webcore wants to schedule it to run again at 9:30. How do I suppress this behavior?

Additional comments:

  • I know I could probably fix this by separating it into two separate pistons: one to toggle the virutal switch, and the second to be triggered by the virtual switch, but I have need several of these pistons for different cases, and I’d prefer to keep the logic all in one piston if I can.

  • Webcore seems to want to self schedule the piston for later because it sees an IF based on a time range. Is there some advanced config thing I can set to stop this? Or is there a different way I need to arrange the logic?

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

5) Attach logs after turning logging level to Full
7/4/2019, 9:29:59 AM +73ms
+0ms ╔Received event [The Austin’s Home].time = 1562250600000 with a delay of -927ms
+85ms ║RunTime Analysis CS > 17ms > PS > 39ms > PE > 29ms > CE
+88ms ║Runtime (37035 bytes) successfully initialized in 39ms (v0.3.10c.20190522) (87ms)
+89ms ║╔Execution stage started
+94ms ║║Cancelling statement #1’s schedules…
+131ms ║║Executed physical command [StreetCamSwitch].off() (31ms)
+132ms ║║Executed virtual command [StreetCamSwitch].toggle (35ms)
+145ms ║║Comparison (time) 34199208 is_not_between (time) 0 … (time) 34200000 = true (8ms)
+148ms ║║Time restriction check passed
+149ms ║║Cancelling condition #4’s schedules…
+150ms ║║Condition #4 evaluated true (15ms)
+151ms ║║Cancelling statement #4’s schedules…
+156ms ║║Requesting time schedule wake up at Fri, Jul 5 2019 @ 12:00:00 AM CDT
+159ms ║║Cancelling condition #3’s schedules…
+159ms ║║Condition group #3 evaluated true (state changed) (24ms)
+162ms ║║Cancelling statement #5’s schedules…
+530ms ║║Executed physical command [Watson Announcer].playText([There is motion at the street, 85]) (362ms)
+531ms ║║Executed [Watson Announcer].playText (364ms)
+534ms ║╚Execution stage complete. (445ms)
+535ms ║Setting up scheduled job for Fri, Jul 5 2019 @ 12:00:00 AM CDT (in 52200.393s)
+544ms ╚Event processed successfully (543ms)
7/4/2019, 8:01:06 AM +687ms
+1ms ╔Received event [The Austin’s Home].execute = 96.8.203.182 with a delay of 42ms
+66ms ║RunTime Analysis CS > 15ms > PS > 35ms > PE > 16ms > CE
+68ms ║Runtime (37035 bytes) successfully initialized in 35ms (v0.3.10c.20190522) (67ms)
+69ms ║╔Execution stage started
+73ms ║║Cancelling statement #1’s schedules…
+108ms ║║Executed physical command [StreetCamSwitch].on() (28ms)
+109ms ║║Executed virtual command [StreetCamSwitch].toggle (34ms)
+120ms ║║Comparison (time) 28866799 is_not_between (time) 0 … (time) 34200000 = false (7ms)
+122ms ║║Condition #4 evaluated false (11ms)
+123ms ║║Cancelling statement #4’s schedules…
+127ms ║║Requesting time schedule wake up at Thu, Jul 4 2019 @ 9:30:00 AM CDT
+130ms ║║Condition group #3 evaluated false (state did not change) (19ms)
+132ms ║╚Execution stage complete. (63ms)
+133ms ║Setting up scheduled job for Thu, Jul 4 2019 @ 9:30:00 AM CDT (in 5333.18s)
+145ms ╚Event processed successfully (145ms)


#2

First thing comes to my mind is, using a variable.
What if you have another piston that changes a global variable right after 9:30 AM
and your current piston can have another IF instead of “time between.”

piston #1 
Every day AT 9:30 
Set @annoucementglobalvariable = TRUE

now back to your current piston,

IF @annoucementglobalvariable = TRUE
Then 
With 
Watson announcer 
Speak text : motion in the driveway.

IF time is 11:59pm 
Set @@annoucementglobalvariable = FALSE

EDIT : You can even put everything in a single piston, I haven’t tested though.
EDIT 2 : Yeah I got excited and post my solution but i’m having second thoughts…it won’t work…
Since you need to execute only with URL, using an IF statement is messing it up.
I still see a solution is working but i have a strong feeling it will be two seperate pistons.

Any experts? pros? minions?


#3

Thank you for your quick response! It’s a good thought and wouldn’t be a bad way to go since I have multiple similar pistons I need. They all could key off the same global variable.

Open to other ideas as well…


#4

One other solution is,
pausing your piston.
But again you need one other piston (that can control several pistons at the same time)

Piston #1 
Every day at 9:30am 
Resume piston "Motion warning"

Every day at 11:59pm 
Pause piston "Motion warning"

And your motion warning piston is: (No IF BLOCK)

Execute
With streetcamswitch
do 
toggle
With
Watsonannouncer
do
Speak text "motion detected"

I BELIEVE just resuming this piston at 9.30am WON’T trigger it…

ps : Some Pros are not a big fan of pausing and resuming pistons FYI.


#5

I think the solution is actually quite simple. Notice the lightning bolt in the left margin? This means those events will execute the piston. Normally, if I only want a piston to run when called from an external source, I code it in a way so I have NO triggers in that piston. Once saved, you want to see this up top:

To achieve this, you can either unsubscribe on line 18, or re-word it so the lightning bolt goes away.

For example, the command:
IF $hour24 is greater than 9, Then speak text
will only speak from 10AM to midnight

(this method works because system variables are not treated as triggers)


#6

Thanks this looks like the best option so far. I recoded the IF to use the system variable. It still shows the lightening bolt next to that line, but it also shows the warning message you mentioned that I want. (May be a minor bug in the dashboard)

Thanks again to all responders :+1:t2::+1:t2:


#7

Nice conversion to get a more precise time! :+1:

I should probably mention that most math can turn a trigger into a condition…
(even non-system variables)


I suspect this is because:

  • The math cannot be calculated unless the piston runs
  • and the piston cannot run until the math is calculated

giphy