NightMode

On your display
NightMode displays a dimmed ...ZZZ screen
- Works with
- AWTRIX NG
- Topic
- Miscellaneous
- Includes
- Script
Choose your display in the next step.
Flow description
NightMode displays a dimmed ...ZZZ screen during a configurable nighttime period. By default, it activates at 23:00, sets the display brightness to 1%, disables automatic brightness, and keeps the nighttime screen visible until 06:01.
The ZZZ characters use a compact custom 3 × 5 pixel font. The text colour and spacing between the characters can be adjusted in the app settings.
Before NightMode starts, the app saves the current brightness and automatic-brightness setting. When night mode ends, these settings are restored automatically.
NightMode then returns to the app positioned immediately before it in the AWTRIX app rotation. The daytime app can either remain fixed on the display or allow normal app rotation, depending on the “Keep daytime app on screen” setting.
Main features:
- Configurable start and end times
- Adjustable nighttime brightness
- Customisable text colour
- Adjustable spacing between the Z characters
- Automatic saving and restoration of brightness settings
- Optional fixed daytime display
- Automatic return to NightMode if another app is selected during the night
- Automatic positioning and centring of the
...ZZZgraphic
vfqF0nt3qsJk.ax
# @name NightMode
# @desc Shows ...ZZZ at night and restores the daytime display
# @author Bjørn Arve / OpenAI
# @version 2.0
# @config start_h number "Night mode starts – hour" default=23 min=0 max=23 unit=h
# @config start_m number "Night mode starts – minute" default=0 min=0 max=59 unit=min
# @config end_h number "Night mode ends – hour" default=6 min=0 max=23 unit=h
# @config end_m number "Night mode ends – minute" default=1 min=0 max=59 unit=min
# @config night_br slider "Night brightness" default=1 min=1 max=10 unit=%
# @config day_br slider "Day brightness fallback" default=80 min=1 max=100 unit=%
# @config text_color color "Colour of ...ZZZ" default=#3070FF
# @config z_gap number "Space between the Z characters" default=2 min=0 max=4 unit=px
# @config hold_day bool "Keep daytime app on screen" default=true
class NightMode
var start_h, start_m, end_h, end_m
var night_br, day_br, text_color, z_gap, hold_day
var night_active, visible
var saved_br, saved_auto
var draw_x, draw_y, z1_x, z2_x, z3_x
def init()
self.start_h = store.get("start_h")
self.start_m = store.get("start_m")
self.end_h = store.get("end_h")
self.end_m = store.get("end_m")
self.night_br = store.get("night_br")
self.day_br = store.get("day_br")
self.text_color = store.get("text_color")
self.z_gap = store.get("z_gap")
self.hold_day = store.get("hold_day")
self.night_active = store.get("night_active")
if self.night_active == nil
self.night_active = false
end
self.saved_br = store.get("saved_br")
self.saved_auto = store.get("saved_auto")
self.visible = false
# Calculate all drawing positions once
var total_width = 15 + self.z_gap * 2
self.draw_x = (width() - total_width) / 2
self.draw_y = (height() - 5) / 2
self.z1_x = self.draw_x + 6
self.z2_x = self.z1_x + 3 + self.z_gap
self.z3_x = self.z2_x + 3 + self.z_gap
end
def is_night()
var h = hour()
var m = minute()
if h < 0 || m < 0
return false
end
var current = h * 60 + m
var start_time = self.start_h * 60 + self.start_m
var end_time = self.end_h * 60 + self.end_m
if start_time > end_time
return current >= start_time || current < end_time
end
return current >= start_time && current < end_time
end
def loop()
var night = self.is_night()
if night
if !self.night_active
# Save the current daytime settings
var current_br = settings.get("brightness")
if current_br != nil && current_br > self.night_br
self.saved_br = current_br
store.set("saved_br", current_br)
end
var current_auto = settings.get("autoBrightness")
if current_auto != nil
self.saved_auto = current_auto
store.set("saved_auto", current_auto)
end
self.night_active = true
store.set("night_active", true)
end
# Correct the brightness only when necessary
var current_br = settings.get("brightness")
if current_br != self.night_br
settings.set("brightness", self.night_br)
end
var current_auto = settings.get("autoBrightness")
if current_auto != false
settings.set("autoBrightness", false)
end
# Return to NightMode if another app has been selected
if !self.visible
rotation.show()
end
rotation.pause()
else
if self.night_active
# Restore normal brightness when night mode ends
var restore_br = self.saved_br != nil ? self.saved_br : self.day_br
settings.set("brightness", restore_br)
if self.saved_auto != nil
settings.set("autoBrightness", self.saved_auto)
end
self.night_active = false
store.set("night_active", false)
# Return to the app placed before NightMode
rotation.resume()
rotation.previous()
if self.hold_day
rotation.pause()
end
else
# Remember manual daytime brightness changes
var current_br = settings.get("brightness")
if current_br != nil && current_br > self.night_br
if current_br != self.saved_br
self.saved_br = current_br
store.set("saved_br", current_br)
end
end
var current_auto = settings.get("autoBrightness")
if current_auto != nil && current_auto != self.saved_auto
self.saved_auto = current_auto
store.set("saved_auto", current_auto)
end
if self.hold_day
rotation.pause()
end
end
end
end
def should_show()
return self.is_night()
end
def on_show()
self.visible = true
end
def on_hide()
self.visible = false
end
# Draw one Z character at 3 × 5 pixels
def draw_z(x, y, color)
line(x, y, x + 2, y, color)
pixel(x + 2, y + 1, color)
pixel(x + 1, y + 2, color)
pixel(x, y + 3, color)
line(x, y + 4, x + 2, y + 4, color)
end
def draw()
clear()
# Three dots
pixel(self.draw_x, self.draw_y + 4, self.text_color)
pixel(self.draw_x + 2, self.draw_y + 4, self.text_color)
pixel(self.draw_x + 4, self.draw_y + 4, self.text_color)
# Three 3 × 5 pixel Z characters
self.draw_z(self.z1_x, self.draw_y, self.text_color)
self.draw_z(self.z2_x, self.draw_y, self.text_color)
self.draw_z(self.z3_x, self.draw_y, self.text_color)
end
end
return NightMode()
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
More flows for AWTRIX NG Scripts or Miscellaneous
Something wrong with this flow? Report it.
Have an idea?
Sign in to ask questions and join the conversation.