I have a nice Working PiGlow Script for my retropie but a little stuck

I have a nice script butchered up, with smaller scripts none of which I wrote myself I’m a total hack but with retropie it go through a LED cycles then it loops the last part of the script once emulationstation loads (lucky timing?)

#!/usr/bin/env python
##################################################
## Switch each colour on in sequence on and off ##
##                                              ##
## Example by Jason - @Boeeerb                  ##
## hacked together by co4                       ##
##################################################

import time
import piglow

piglow.auto_update = True

for x in range(6):
    piglow.all(0)
    piglow.ring(x,80)
    time.sleep(0.25)

import piglow
import time

for x in range(18):
    piglow.led(x+1, 180)
    piglow.show()
    time.sleep(0.4)
    piglow.led(x+1, 0)
    piglow.show()
    time.sleep(0.4)

import piglow
import time

for x in range(18):
    piglow.led(x+1, 180)
    piglow.show()
    time.sleep(0.1)
    piglow.led(x+1, 0)
    piglow.show()
    time.sleep(0.1)

import piglow
import time

for x in range(18):
    piglow.led(x+1, 180)
    piglow.show()
    time.sleep(0.040)
    piglow.led(x+1, 0)
    piglow.show()
    time.sleep(0.040)

import piglow
from time import sleep

piglow.auto_update = True


val = 40
colour = 1

while True:
    if colour == 19:
        colour = 1
        if val == 40:
            val = 0
        else:
            val = 40

    piglow.led(colour, val)
    sleep(0.060)

    colour = colour + 1

it’s brilliant BUT I have 2 minor issues… when I reboot or shutdown my piglow remains on and lighten up, is there anyway to get the looping part of the script to reverse back up (red to white, then white to red) even if it’s not writing the script a general pointer where I can find out how to do it would be amazing Thanks :)

Please help…

Had a piglow running as a nightlight for 2 days on a zero w. Then it stopped.

I updated upgraded, rebooted and get this message…

File “nightlight.py”, line 32, in
piglow.all(0)
File “/usr/lib/python3/dist-packages/piglow.py”, line 295, in all
show()
File “/usr/lib/python3/dist-packages/piglow.py”, line 126, in show
setup()
File “/usr/lib/python3/dist-packages/piglow.py”, line 323, in setup
import sn3218
File “/usr/lib/python3/dist-packages/sn3218.py”, line 114, in
enable_leds(0b111111111111111111)
File “/usr/lib/python3/dist-packages/sn3218.py”, line 62, in enable_leds
[enable_mask & 0x3F, (enable_mask >> 6) & 0x3F, (enable_mask >> 12) & 0X3F])
OSError: [Errno 121] Remote I/O error

Anyone any ideas???