Perpetual dragscript for sharing

Hi all
I have shared this as it works most of the time but not all and I need some help to sense-check.
What happens is the session doesn’t close at the end of the night.
There is a central block loop ( lines 53 to 83) where it checks weather conditions and waits 5 minutes then goes again, doing a waitSafe in the process but when waitsafe ( line 83) releases the loop, wait until Nautical night (line 43) is catching it unexpectedly and causing Voyager to waith through out the day with the session connected and fully powered. Any thoughts ?
I have just updated the waitsafe and waitnight to the same long/lat and made sure the nautical night is shorter than the sequencer accepted night length.
It is largely based on Leo’s script with my own needs added in.

here we go :
1 - Start: Events At Start are ENABLE
2 - Script
3 - Remark: Script to manage Observatory and keep RoboTarget running for extended periods of time.
4 - Remark: Update the positions you want the telescope and dome first to move to to support blind solve at the start of the night
5 - Remark: Update the sky temperature and SQM values you consider a useful evening to open up for…
6 - Remark: OpenState - track shutter open state for resume purposes
7 - Counter: OpenState - Init Value = 0
8 - Counter: timeoutCounter - Init Value = 0
9 - Counter: errorCounter - Init Value = 0
10 - Decimal Number: skyTemperature - Init Value = 0
11 - Remark: Update BlindSolveCount > 0 to prevent BlindSolves on startup
12 - Counter: blindSolveCount - Init Value = 0
13 - Decimal Number: TimeToDusk - Init Value = 0
14 - Block: Wait for the evening to start. Nothing is connected so disable Light and suspend events.
15 - Wait Dusk: Manual Data [LAT:50° 59’ 00" N LON: 00° 26’ 00" W] - Offset (Before) 00:15:00 [hh:mm:ss] >> TimeToDusk
16 - Disable Weather Light Event
17 - Disable Suspend Event
18 - Connect Safety Monitor Control
19 - DO IF SETUP DISCONNECTED
20 - Block: Connect power and devices
21 - Block: Start session power
22 - External Script: C:\Users\obbo\Documents\Voyager\Script\startdomepower.bat espasw02
23 - External Script: C:\Users\mharrison\Documents\Voyager\Script\startPierpower.bat espasw01
24 - Wait Time: 00:00:10 [hh:mm:ss] Interval
25 - Connect Setup with Timeout: TimeOut : 60[s]
26 - If Error
27 - Send Email: - Failed to connect session at start of ev … - Time ##NOW##
Typical causes- wrong prof …
28 - GoTo Block: Close down open session
29 - DO IF SETUP CONNECTED
30 - Block: Setup connected session
31 - Remark: Go to a known place for blind solving
32 - Cooling Down: -15[°C] - Async Cooling - Use CCD Firmware Cooling down-15[°C]
33 - Unparking
34 - Goto ALT/AZ: ALT 45 - AZ 175 - FC: False
35 - Stop Tracking
36 - Dome Goto Azimuth: Azimuth=185°
37 - Block: Check for sky clear by temperature and do dusk flats if we are still near Dusk!
38 - Update Decimal From Observing Conditions: skyTemperature - SkyTemperature
39 - DO IF DECIMAL VALUE: skyTemperature is Lower than -10
40 - DO IF DECIMAL VALUE: TimeToDusk is Between [15 : -30]
41 - Enable Suspend Event
42 - Block: Sky flats at start of Dusk
43 - Remark: Auto sky flats moves the scope - so we need the dome slaved and open and suspened events enablled
44 - Dome Slave ON
45 - Update Counter: OpenState - Set to 1
46 - Open Shutter
47 - Open Flat Device Cover: ID #1
48 - Open Flat Device Cover: ID #2
49 - Flat: C:\Users\mharrison\Documents\Voyager\ConfigSequence\ATIK11 Flats.s2f
50 - Send Email: - Weather valid - flats completed - Time ##NOW##

51 - Block: Check for clear sky by temperature and sky brightness and (re)start
52 - Wait Nautical Night: Data from connected Setup - Offset (Before) 00:30:00 [hh:mm:ss]
53 - Update Decimal From Observing Conditions: skyTemperature - SkyTemperature
54 - DO IF DECIMAL VALUE: skyTemperature is Lower than -10
55 - DO IF SQM: >= 18.25 [mag/arcsec^2]
56 - Enable Suspend Event
57 - Dome Slave ON
58 - Open Shutter
59 - Update Counter: OpenState - Set to 1
60 - Open Flat Device Cover: ID #1
61 - Open Flat Device Cover: ID #2
62 - Block: Initial Blind position solving for night
63 - Remark
64 - DO IF COUNTER VALUE: blindSolveCount is Lower or Equal to 0
65 - Goto ALT/AZ: ALT 45 - AZ 175 - FC: False
66 - Blind Solving with Mount Sync
67 - Update Counter: blindSolveCount - Offset by 1
68 - Block: observing session using RoboTarget to manage targets.
69 - Remark: Dome slaving on sequence is specified in Dome Driver. Check for response update set to after 10 secs.
70 - Scheduler DEFAULT - Nautical Night - Night Start Offset=0 - Night End Offset=60
71 - If Error
72 - Remark: Errors occur because scheduler retried internally and failed hard.
73 - Send Email: - Error termination of Scheduled session - Time ##NOW##

74 - If OK
75 - Remark: Scheduled session completed OK due to end of night or other reasons.
76 - Update Counter: errorCounter - Set to 0
77 - Update Counter: timeoutCounter - Set to 0
78 - Remark: Reset error and timeout counters
79 - GoTo Block: Wait on sequence error or timeout before retrying
80 - Block: Wait on sequence error or timeout before retrying
81 - Remark: Waiting potentially with the dome open - require suspend to protect.
82 - Wait Time: 00:05:00 [hh:mm:ss] Interval
83 - Remark: This enables us to detect end of night condition properly
84 - Wait Safe: Wait SAFE until FINISH NIGHT Nautical - Manual Data [ LAT:51° 00’ 00" N LON: 00° 26’ 00" W] - Offset (After) 00:50:00 [hh:mm:ss] - Exit with ERROR if the Night has ended less than 0 [hh] - Check Exit - Check Suspend
85 - If Error
86 - GoTo Block: Close down open session
87 - GoTo Block: Check for clear sky by temperature and sky brightness and (re)start
88 - Block: Close down open session
89 - Disable Suspend Event
90 - Close Shutter
91 - If TIMEOUT
92 - Update Counter: timeoutCounter - Set to 1
93 - DO IF COUNTER VALUE: timeoutCounter is Lower or Equal to 3
94 - GoTo Block: Close down open session
95 - Send Email: - End of session error closing dome - Time ##NOW##

96 - Update Counter: OpenState - Set to 0
97 - Close Flat Device Cover: ID #1
98 - Close Flat Device Cover: ID #2
99 - Disable Suspend Event
100 - Warmup: Async
101 - Dome Slave OFF
102 - Stop Tracking
103 - Parking
104 - Dome Park
105 - Wait Time: 00:02:00 [hh:mm:ss] Interval
106 - Disconnect Setup
107 - Forced Disconnect Setup
108 - Block: Stop session power
109 - Send Email: - End of session power down - Time ##NOW##

110 - Wait Time: 00:00:10 [hh:mm:ss] Interval
111 - External Script: C:\Users\mharrison\Documents\Voyager\Script\stopPierpower.bat espasw01
112 - External Script: C:\Users\obbo\Documents\Voyager\Script\stopdomepower.bat espasw02
113 - GoTo Block: Wait for the evening to start. Nothing is connected so disable Light and suspend events.
114 - End
115 - Events
116 - Emergency Suspend: Wait Resume until end of Nautical Night (to allow calculation mount must be connected to Voyager) - On Resume Timeout Restart DragScript
117 - Close Shutter
118 - If TIMEOUT
119 - Send Email: - Shutter close failure! -
120 - Stop Tracking
121 - Emergency Resume
122 - Remark: If we were previously neither open or tracking, this leads to the wrong state - handle using OpenState
123 - DO IF COUNTER VALUE: OpenState is Greater or Equal to 1
124 - Start Tracking
125 - Open Shutter
126 - Emergency Exit
127 - Close Shutter
128 - Close Flat Device Cover: ID #1
129 - Close Flat Device Cover: ID #2
130 - Send Email: - Emergency Exit - Time ##NOW##
Mount
131 - Warmup: Async
132 - Dome Slave OFF
133 - Parking
134 - Dome Park
135 - External Script: C:\Users\mharrison\Documents\Voyager\Script\stopPierpower.bat espasw01
136 - Wait Time: 00:02:00 [hh:mm:ss] Interval
137 - External Script: C:\Users\obbo\Documents\Voyager\Script\stopdomepower.bat espasw02
138 - External Script: C:\Users\mharrison\Documents\Voyager\Script\stopPierpower.bat espasw01