From e9a2d2bea83688a0b7ad3516d5c119b7e5a5cec1 Mon Sep 17 00:00:00 2001 From: D Delmar Davis Date: Sat, 18 Apr 2026 20:50:23 -0700 Subject: Display temps on rainbowhat --- bin/timetemp.py | 66 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/bin/timetemp.py b/bin/timetemp.py index 7b8de40..03f147b 100755 --- a/bin/timetemp.py +++ b/bin/timetemp.py @@ -22,26 +22,48 @@ except FileNotFoundError: print("'Rainbow HAT'?" + str(hat_is_a_rainbow_hat) ) -from adafruit_ht16k33 import segments # type: ignore - -# Create the I2C interface. -i2c = busio.I2C(board.SCL, board.SDA) - -# Create the LED segment class. -# This creates a 7 segment 4 character display: -display = segments.Seg7x4(i2c) - -# Clear the display. -display.fill(0) -while True: - display.print(time.strftime("%H:%M")) - time.sleep(5) - file=open('/var/lib/prometheus/node-exporter/temp.prom') - display.colon = False - for line in file.readlines(): - values=line.split()[0:2] - if values[0]=='home_temperature_farenheit': - display.print(str(values[1])[0:4]+'f') - file.close() - time.sleep(5) +if hat_is_a_rainbow_hat: + import rainbowhat as rh + + while True: + rh.display.print_str(time.strftime("%H%M")) + rh.display.show() + # display.print(time.strftime("%H:%M")) + time.sleep(5) + file=open('/var/lib/prometheus/node-exporter/temp.prom') + # display.colon = False + for line in file.readlines(): + values=line.split()[0:2] + if values[0]=='home_temperature_farenheit': + rh.display.print_str(str(values[1])[0:3]+'f') + rh.display.show() + # display.print(str(values[1])[0:3]+'f') + file.close() + time.sleep(5) + + +else: + from adafruit_ht16k33 import segments # type: ignore + + # Create the I2C interface. + i2c = busio.I2C(board.SCL, board.SDA) + + # Create the LED segment class. + # This creates a 7 segment 4 character display: + display = segments.Seg7x4(i2c) + + # Clear the display. + display.fill(0) + while True: + display.print(time.strftime("%H:%M")) + time.sleep(5) + file=open('/var/lib/prometheus/node-exporter/temp.prom') + display.colon = False + for line in file.readlines(): + values=line.split()[0:2] + if values[0]=='home_temperature_farenheit': + display.print(str(values[1])[0:4]+'f') + file.close() + time.sleep(5) + -- cgit v1.2.3