News:

  • February 01, 2023, 08:05:30 AM

Login with username, password and session length

Author Topic: Automagic DST Adjustment  (Read 2885 times)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3478
  • Darth Ladder
Automagic DST Adjustment
« on: March 22, 2021, 07:59:39 PM »
Energizes ST768 (DST/SummerTime) on or after 2am the second Sunday in March and de-energizes on or after the first Sunday in November (US Standard).     Logic is state-based rather than looking for the exact transition time so should work even if the PLC is off at the exact transition moment.

Code: [Select]
STRE SDT0.DayOfWeek 0
ANDGE SDT0.Hour 2
ANDPDPF
OR ST0

MATH ST768

"((SDT0.Month > 3) && (SDT0.Month < 11)) ||
((SDT0.Month == 3) && (SDT0.Day >= (SDT0.DayOfWeek + 8))) ||
((SDT0.Month == 11) && (SDT0.Day < (SDT0.DayOfWeek + 1)))"

I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Bolt

  • Hero Member
  • *****
  • Posts: 492
Re: Automagic DST Adjustment
« Reply #1 on: March 22, 2021, 08:09:39 PM »
I've been using this logic for years, worked well so far, I think this is similar to what you posted (and deleted) last week.

Bolt

  • Hero Member
  • *****
  • Posts: 492
Re: Automagic DST Adjustment
« Reply #2 on: March 23, 2021, 10:32:51 AM »
Oh, and your code wouldn't import, I had to change it to
Code: [Select]
STRE SDT0.DayOfWeek 0
ANDGE SDT0.Hour 2
ANDPDPF
OR ST0

MATH ST768 "((SDT0.Month > 3) && (SDT0.Month < 11)) || ((SDT0.Month == 3) && (SDT0.Day >= (SDT0.DayOfWeek + 8))) || ((SDT0.Month == 11) && (SDT0.Day < (SDT0.DayOfWeek + 1)))"

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3478
  • Darth Ladder
Re: Automagic DST Adjustment
« Reply #3 on: March 23, 2021, 11:44:39 AM »
I've been using this logic for years, worked well so far, I think this is similar to what you posted (and deleted) last week.

Yeah, very similar.   My issue is that some of my customers don't have the equipment powered up 24/7, so I wanted something that would determine the correct state for ST768 no matter when it was executed.   So that's why the inequalities in the MATH vs. equality tests, and the reason for the $ST0 on the permissive, so it gets run once on power up.   I do the same thing for stuff intended to run once a day, say at midnight.   I record the last date on which it ran, and part of the enable is $Now.Day != LastRunDate.    Then if the PLC is off at midnight or whatever the designated run time is, the stuff still gets done, pending any other permissives.

Today's is identical to last week's except the the last OR expression was actually true AFTER the first Sunday in November, rather than before.   So I knew it was wrong, but didn't have the time to think through the exact fix.   Change the >= to <?   <=?   Adjust +/- the offset that corrects for MIN(Day) == 1, but MIN(DoW) == 0?   So I took it down till I could think it through.   Turns out I just needed to change the >= to <.

I'm a MATH box monkey.   Like the old saying goes, When the only tool you have is a MATH box, every problem is a math problem!   ;D
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3478
  • Darth Ladder
Re: Automagic DST Adjustment
« Reply #4 on: March 23, 2021, 11:46:09 AM »
Oh, and your code wouldn't import, I had to change it to
Code: [Select]
STRE SDT0.DayOfWeek 0
ANDGE SDT0.Hour 2
ANDPDPF
OR ST0

MATH ST768 "((SDT0.Month > 3) && (SDT0.Month < 11)) || ((SDT0.Month == 3) && (SDT0.Day >= (SDT0.DayOfWeek + 8))) || ((SDT0.Month == 11) && (SDT0.Day < (SDT0.DayOfWeek + 1)))"

I'm actually slightly surprised.   I did format it to make the logic easy to follow, but I thought if it were cut and pasted directly into a MATH box, DMD would strip out the carriage returns and accept it.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

belias

  • Full Member
  • ***
  • Posts: 28
Re: Automagic DST Adjustment
« Reply #5 on: January 31, 2022, 04:53:42 PM »
Just wanted to say thanks for this...this has been really helpful.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3478
  • Darth Ladder
Re: Automagic DST Adjustment
« Reply #6 on: January 31, 2022, 08:14:52 PM »
Glad it was useful!
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.