TimeOfDay does not trigger,

I have a small project on a raspberry pi 4 which controls a relay over 3 states on, off and timedependent

Thanks!

from gpiozero import Button, OutputDevice,TimeOfDay
from datetime import datetime,time as t
from signal import pause
import time
import os
import tkinter as tk

'''
This script takes the input from a push button and controls
the relais which is controls the power for the screen its normally closed
if the relais gets the signal -> the screen shuts off, this way its secured
that the screen is on by default
'''

# GPIO PINS
button = Button("BOARD36")
relay = OutputDevice("BOARD7")

# default relaystate
relay.off()

# default state
state = 0
pressed_time = None

# Timer in state 2
ontime_morning=t(hour=7, minute=0, second=0, microsecond=0)
offtime_evening=t(hour=10, minute=33, second=0, microsecond=0)


def display_message(message,milliseconds=3000):
    root = tk.Tk()
    root.attributes('-topmost', True)  # Make the window stay on top
    root.overrideredirect(True)  # Remove the title bar
    root.geometry("800x100")  # Set the window size to create a square shape
    label = tk.Label(root, text=message,font=("Helvetica", 18))
    label.pack()
    def close_window():
        root.destroy()
    root.after(milliseconds, close_window)
    root.mainloop()

def change_state():
    global state
    state = (state + 1) % 3  # Cycling between 0, 1, and 2
    update_output()

def message_while_pressed():
    global pressed_time
    pressed_time = time.time()

def message_when_released():
    global pressed_time
    if time.time() - pressed_time >= 0.2:
        change_state()

def update_output():
    _=os.system('clear')
    global state
    now = datetime.now().time()
   
    if state == 0:
         relay.off()
         print("screen on")
         display_message("nModus: Ein",5000)
               
    elif state == 1:
        if ontime_morning < now < offtime_evening:
            relay.off()
            print("screen on in timeslot")
            display_message("nModus: Zeitschaltuhr ")
           
        else:  
            for count in range(3, 0, -1):
                display_message(f'nModus: Zeitschaltuhrn AUS in {count}')
                time.sleep(1)  # Wait for 1 second

            relay.on()
            print("screen off out timeslot")
                     
    elif state == 2:
        for count in range(3, 0, -1):
            display_message(f'nModus: AUS in {count}',1000)          
        relay.on()
        print("screen off")
       

def relay_day():
    global state
    if state == 1:
        relay.off()
        update_output()
       
def relay_night():
    global state
    if state == 1:
        relay.on()
        update_output()

   
# signal for daytime
daytime=TimeOfDay(ontime_morning,offtime_evening)

#  signaling
daytime.when_activated=relay_day
daytime.when_deactivated=relay_night

button.when_pressed = message_while_pressed
button.when_released = message_when_released

update_output()  # Initial output update based on the initial state

pause()

the button to switch the state works , as well as the displaying of the window,

The problem Im facing is with TimeOfDay form gpiozero , the functions get not automatically triggered by the timechange.

Ive already checked that everything is in UTC and also if I press the button to switch to the state 1 , if its inside the relay stays on and outside the timeframe it shuts of..

What am I missing here?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật