Holiday code not evaluating date


#1

1) Give a description of the problem
Using the attached piston for years. It never seems to evaluate the date correctly. Every year at christmas I just enable the piston and then after I disable it. Kind of defeats the purpose of the automation.

2) What is the expected behaviour?
I expected the code to process the date correctly and alternate the lights only on holidays. Instead it is stuck on christmas all the time.

3) What is happening/not happening?
Not evaluating the date. Prob something wrong with the logic.

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

5) Attach logs after turning logging level to Full
1/12/2022, 6:08:21 PM +503ms +1ms ╔Received event [Outside Lights].switch = off with a delay of 63ms +7870ms ║RunTime Analysis CS > 15ms > PS > 7765ms > PE > 90ms > CE +7871ms ║Piston waited at a semaphore for 7761ms +7875ms ║Runtime (74998 bytes) successfully initialized in 7765ms (v0.3.110.20191009) (7873ms) +7876ms ║╔Execution stage started +7883ms ║║Comparison (enum) off changes_to (string) on = false (0ms) +7884ms ║║Cancelling condition #22's schedules... +7885ms ║║Condition #22 evaluated false (5ms) +7886ms ║║Cancelling condition #5's schedules... +7887ms ║║Condition group #5 evaluated false (state changed) (7ms) +7890ms ║║Cancelling statement #46's schedules... +7893ms ║║Executed virtual command setState (0ms) +7899ms ║║Calculating (integer) 15 / (integer) 3 >> (integer) 5 +7904ms ║║Executed virtual command setVariable (3ms) +7912ms ║║Calculating (integer) 100 - (integer) 98 >> (integer) 2 +7918ms ║║Calculating (integer) 5 - (integer) 1 >> (integer) 4 +7920ms ║║Calculating (integer) 2 / (integer) 4 >> (integer) 0.5 +7925ms ║║Executed virtual command setVariable (3ms) +7930ms ║║Executed virtual command setVariable (3ms) +7935ms ║║Executed virtual command setVariable (3ms) +7940ms ║║Executed virtual command setVariable (2ms) +7944ms ║║Executed virtual command setVariable (2ms) +7954ms ║║Comparison (boolean) false is (boolean) false = true (1ms) +7955ms ║║Cancelling condition #38's schedules... +7956ms ║║Condition #38 evaluated true (9ms) +7957ms ║║Cancelling condition #48's schedules... +7958ms ║║Condition group #48 evaluated true (state changed) (10ms) +7960ms ║║Cancelling statement #36's schedules... +7964ms ║║Calculating (integer) 0 + (integer) 1 >> (integer) 1 +7969ms ║║Executed virtual command setVariable (3ms) +7977ms ║║Comparison (boolean) false is (boolean) false = true (2ms) +7978ms ║║Condition #38 evaluated true (8ms) +7979ms ║║Condition group #48 evaluated true (state did not change) (9ms) +7981ms ║║Cancelling statement #36's schedules... +7986ms ║║Calculating (integer) 1 + (integer) 1 >> (integer) 2 +7990ms ║║Executed virtual command setVariable (3ms) +7998ms ║║Comparison (boolean) true is (boolean) false = false (2ms) +8000ms ║║Cancelling condition #38's schedules... +8001ms ║║Condition #38 evaluated false (9ms) +8002ms ║║Cancelling condition #48's schedules... +8003ms ║║Condition group #48 evaluated false (state changed) (11ms) +8008ms ║║Comparison (boolean) true is (boolean) true = true (2ms) +8009ms ║║Condition #45 evaluated true (4ms) +8014ms ║║Comparison (enum) off is (string) on = false (1ms) +8016ms ║║Condition #229 evaluated false (5ms) +8017ms ║║Condition group #228 evaluated false (state did not change) (6ms) +8018ms ║║Condition group #51 evaluated false (state did not change) (13ms) +8019ms ║╚Execution stage complete. (143ms) +8020ms ╚Event processed successfully (8020ms)


#2

I do my logic different than the way you do:

start date --> addDays(date(“03/21/” + $year), 1)
end date --> addDays(date(“11/01/” + $year), 1)

whereas you do:
start date --> addDays(date(“12/25/” + $year), -26)
end date --> addDays(date(“12/25/” + $year), 5)

so two difference… I use the exact dates and 1 at the end

my piston does work year after year between March 21st and November 1st.

i am sure others have better solutions though.


#3

pic

For unchanging dates, I am a fan of using “day of year” … Something like this:

define
   integer {doy} = (no value set)
end define

execute
   IF Switch 2 changes to on          <-- Trigger
   Then
      Set variable {doy} = formatDateTime($now, 'D')
      IF {doy} is between 38 and 53   <-- Condition   (Feb 7 - Feb 22)
      Then 
         do Valentine stuff
      END IF
      IF {doy} is greater than 337    <-- Condition   (Dec 4)
         or
         {doy} is less than 7         <-- Condition   (Jan 6)
      Then 
         do Xmas stuff
      END IF
   END IF
END EXECUTE

Normally I use “is between”, but your Christmas time spans the new year, so that one event is handled a bit differently. (greater/less than)

Also note how I used nested “IFs” instead of “Only Whens”…