Block heater automation


#1

Hi folks,

don’t have a specific problem but rather I’m trying out webcore for the first time and wondering If I have the concept right. I’m having a little trouble grasping the ways we would know if a script will or won’t fire. I have one based on various times + temps and there may be a better or proper way to acomplish this. The main idea is that if I am home the block heater turns on in the morning based on the temp. Colder temp range = earlier start time, between certain times it shuts off if I have left the property.


#2

This piston will only execute when “Presence Sensor 1” changes…
(notice the lightning bolts in the left margin)

I would probably go about this the opposite way… with Time as a trigger, and presence as a condition. Maybe something like:

Every day at 6am
do
   IF Temp is inside of range -36 and -50
      and 
      Presence Sensor 1 is present
      and
      $dayOfWeek is between 1 and 5
   Then
      Turn on
   END IF
END EVERY

Every day at 7am
do
   IF Temp is inside of range -26 and -35
      and 
      Presence Sensor 1 is present
      and
      $dayOfWeek is between 1 and 5
   Then
      Turn on
   END IF
END EVERY

etc…

Notice all of these blocks are separate, meaning that one execution will not process any other block. (normally, pistons run top to bottom, but not so with EVERY blocks)


Another way would be to combine times in a single IF block… Something like this:

IF Time happens daily at 6am
   or
   Time happens daily at 7am
   or
   Time happens daily at 7:30am
Then
   IF Presence Sensor 1 is present
      and
      $dayOfWeek is between 1 and 5
   Then
      IF Temp is inside of range -36 and -50
         and 
         Time is between 5:59 and 6:01
      Then Turn on
      END IF
      IF Temp is inside of range -26 and -35
         and 
         Time is between 6:59 and 7:01
      Then Turn on
      END IF
      IF Temp is inside of range -19 and -25
         and 
         Time is between 7:29 and 7:31
      Then Turn on
      END IF
      etc
   END IF
END IF

This method runs top to bottom at each event, which is why the extra time conditions.


#3

thanks for the tip! going to remake like this, is there a way for me to copy out chunks of my existing setup or highlight the chunk I have after the second if to reuse it?


#4

I would check out my article in the Wiki.


Also note I added another example to my last post.


#6

Looks like it didnt fire, do i need the other smartapps setup the way the main webcore app is setup? I have them all published in the ide but only the man smartapp is fully setup in the way it shows


#7

Can you post your latest version with Full logs and Trace turned on?


#8

I have log turned on now, I think I have to wait for tomorrow morning for the log to fill with results though, current version for the time being:


#9

I haven’t examined the whole piston yet (walking out the door ATM)
… but lines 19, 21, 23, and 25 all need to say "OR.


I would also convert your “ONLY WHEN's” into conditional IF’s, as shown in my 2nd example above.


#10

I’ve converted the ANDs to ORs, any advice if its possible to change the Only whens into IFs without rebuilding the chain?

PS the log is showing actual activity now, subscribed to devices and first scheduled event at 6am tomorrow, going to keep an eye out and cross my fingers! if It’s working right I will post to the example pistons for anyone else wanting to setup a block heater :slight_smile:


#11

I am a huge fan of writing it once, and then dragging the block to make a copy.


#12

if it doesnt run this morning I’ll remake as IFs

Edit: it ran! Going to figure out why the shutoff didnt work tonight then edit times and do some final testing


#13

Current version, almost fully working, the start up worked but the shut down did not fire

> 10/20/2020, 10:30:36 AM +116ms
+1ms ╔Received event [Home].time = 1603207800000 with a delay of 36116ms
+186ms ║RunTime Analysis CS > 138ms > PS > 8ms > PE > 39ms > CE
+189ms ║Runtime (49001 bytes) successfully initialized in 8ms (v0.3.110.20191009) (186ms)
+191ms ║╔Execution stage started
+195ms ║╚Execution stage complete. (5ms)
+199ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 6:00:00 AM CDT (in 70163.686s), with 4 more jobs pending
+212ms ╚Event processed successfully (212ms)
10/20/2020, 10:30:34 AM +160ms
+0ms ╔Received event [Home].execute = recovery with a delay of 57ms
+61ms ║RunTime Analysis CS > 19ms > PS > 6ms > PE > 37ms > CE
+63ms ║Runtime (48989 bytes) successfully initialized in 6ms (v0.3.110.20191009) (62ms)
+64ms ║╔Execution stage started
+70ms ║║Comparison (time) 37834229 happens_daily_at (time) 21600000 = false (0ms)
+72ms ║║Condition #68 evaluated false (4ms)
+73ms ║║Cancelling statement #68's schedules...
+75ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 6:00:00 AM CDT
+79ms ║║Comparison (time) 37834238 happens_daily_at (time) 25200000 = false (0ms)
+81ms ║║Condition #69 evaluated false (3ms)
+82ms ║║Cancelling statement #69's schedules...
+84ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 7:00:00 AM CDT
+88ms ║║Comparison (time) 37834247 happens_daily_at (time) 28800000 = false (0ms)
+90ms ║║Condition #70 evaluated false (3ms)
+91ms ║║Cancelling statement #70's schedules...
+93ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 8:00:00 AM CDT
+97ms ║║Comparison (time) 37834255 happens_daily_at (time) 32400000 = false (0ms)
+99ms ║║Condition #71 evaluated false (3ms)
+100ms ║║Cancelling statement #71's schedules...
+102ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 9:00:00 AM CDT
+106ms ║║Comparison (time) 37834264 happens_daily_at (time) 37800000 = false (0ms)
+108ms ║║Cancelling condition #72's schedules...
+108ms ║║Condition #72 evaluated false (4ms)
+110ms ║║Cancelling statement #72's schedules...
+112ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 10:30:00 AM CDT
+114ms ║║Cancelling condition #37's schedules...
+115ms ║║Condition group #37 evaluated false (state changed) (47ms)
+119ms ║╚Execution stage complete. (55ms)
+121ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 6:00:00 AM CDT (in 70165.719s), with 4 more jobs pending
+130ms ╚Event processed successfully (130ms)
10/20/2020, 10:30:33 AM +733ms
+0ms ╔Received event [Home].time = 1603207800000 with a delay of 33733ms
+58ms ║RunTime Analysis CS > 21ms > PS > 5ms > PE > 32ms > CE
+61ms ║Runtime (48991 bytes) successfully initialized in 5ms (v0.3.110.20191009) (60ms)
+62ms ║╔Execution stage started
+69ms ║║Comparison (time) 37833800 happens_daily_at (time) 21600000 = false (0ms)
+71ms ║║Condition #68 evaluated false (4ms)
+72ms ║║Cancelling statement #68's schedules...
+75ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 6:00:00 AM CDT
+79ms ║║Comparison (time) 37833810 happens_daily_at (time) 25200000 = false (1ms)
+80ms ║║Condition #69 evaluated false (3ms)
+100ms ║║Cancelling statement #69's schedules...
+103ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 7:00:00 AM CDT
+107ms ║║Comparison (time) 37833838 happens_daily_at (time) 28800000 = false (1ms)
+108ms ║║Condition #70 evaluated false (3ms)
+109ms ║║Cancelling statement #70's schedules...
+112ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 8:00:00 AM CDT
+116ms ║║Comparison (time) 37833847 happens_daily_at (time) 32400000 = false (0ms)
+118ms ║║Cancelling condition #71's schedules...
+119ms ║║Condition #71 evaluated false (4ms)
+120ms ║║Cancelling statement #71's schedules...
+123ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 9:00:00 AM CDT
+127ms ║║Comparison (time) 37833858 happens_daily_at (time) 37800000 = true (1ms)
+128ms ║║Time restriction check passed
+129ms ║║Cancelling condition #72's schedules...
+130ms ║║Condition #72 evaluated true (5ms)
+131ms ║║Cancelling statement #72's schedules...
+134ms ║║Requesting time schedule wake up at Wed, Oct 21 2020 @ 10:30:00 AM CDT
+136ms ║║Condition group #37 evaluated true (state did not change) (69ms)
+148ms ║║Comparison (time) 37833872 is_between (time) 21540000 .. (time) 21720000 = false (7ms)
+150ms ║║Condition #35 evaluated false (10ms)
+151ms ║║Condition group #33 evaluated false (state did not change) (12ms)
+162ms ║║Comparison (time) 37833886 is_between (time) 25140000 .. (time) 25320000 = false (7ms)
+164ms ║║Condition #46 evaluated false (11ms)
+165ms ║║Condition group #44 evaluated false (state did not change) (12ms)
+176ms ║║Comparison (time) 37833900 is_between (time) 28740000 .. (time) 28920000 = false (7ms)
+178ms ║║Condition #51 evaluated false (11ms)
+179ms ║║Condition group #49 evaluated false (state did not change) (12ms)
+190ms ║║Comparison (time) 37833914 is_between (time) 32340000 .. (time) 32520000 = false (7ms)
+192ms ║║Cancelling condition #56's schedules...
+193ms ║║Condition #56 evaluated false (12ms)
+194ms ║║Cancelling condition #54's schedules...
+195ms ║║Condition group #54 evaluated false (state changed) (14ms)
+208ms ║║Comparison (time) 37833931 is_between (time) 37500000 .. (time) 38100000 = true (7ms)
+209ms ║║Time restriction check passed
+210ms ║║Cancelling condition #61's schedules...
+211ms ║║Condition #61 evaluated true (13ms)
+227ms ║║Comparison (enum) not present is (string) not present = true (1ms)
+228ms ║║Cancelling condition #62's schedules...
+229ms ║║Condition #62 evaluated true (17ms)
+230ms ║║Cancelling condition #59's schedules...
+231ms ║║Condition group #59 evaluated true (state changed) (33ms)
+232ms ║║Cancelling statement #59's schedules...
+300ms ║║Executed physical command [Block Heater].off() (65ms)
+301ms ║║Executed [Block Heater].off (67ms)
+304ms ║║Skipping task 67 because of mode restrictions
+309ms ║╚Execution stage complete. (247ms)
+311ms ║Setting up scheduled job for Wed, Oct 21 2020 @ 6:00:00 AM CDT (in 70165.956s), with 4 more jobs pending
+338ms ╚Event processed successfully (338ms)

#14

If you stick with “ONLY WHEN”, I would not expect 100% reliability,
(notice that nothing was checked at 10:30:36 AM)

Using a conditional IF (indented) will force that data to be checked at that time.
(same with all the other blocks above, although you got lucky with your first test)


Edit:

It did not turn off this time because it’s difficult to be “not present” (line 79) and “home” (line 84) at the same moment.


#15

Its all working now! going to add and test some final tweaks before submitting to the samples form, thanks for your help!