I have a memory tag ieg, Shift which can A/B/C. Whenever the shift changes, i am triggering below script.
if currentValue.value !=previousValue.value:
system.tag.writeBlocking("[.]ShiftChange", [1])
And i am switching off the shift change script after few mins of shift starts via gateway event.
But whenever the gateway restarts, tags getting restarted and hence ShiftChange is changing as true unless it is changed manually.
Is there way to handle the issue in restarting event anywhere?
This whole approach seems fraught with race conditions. How are you using the ShiftChange boolean? Are you simply using a tag change on that to run shift-end scripts? If so, don't use a boolean at all. Consider using just two tags and one event script:
A memory tag ShiftStartTS of type datetime.
An expression tag CurrentHour with expression getHour(now(5000))
A tag change event (either kind) attached to CurrentHour that:
Uses system.date.now() to acquire the current time, then uses that to compute what the ShiftStartTSshould be at that moment.
Uses system.tag.readBlocking() to get the stored value of ShiftStartTS.
Compares them. If different, writes the new value back, and also executes your shift change code.
The above approach does not need to check initialChange or compare any other values. It will run your shift change code once and only once even if you had many start/stops/edits around shift change, or the gateway was completely down for a few hours at the normal shift change time.