Python Forum
Running an action only between certain times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running an action only between certain times
#3
Time is essentially a number, but you treat it as a string. 2am is '02:00:00' and 7am is '07:00:00'. Both of these are less than '2:00:00', so your test will never be True. Treat time like a datetime object, as Griboulilis recommends, and this should work. Kind of.

If you want to turn lights on at 2am and off at 7am, why not schedule an event to turn the lights on at 2am and off at 7am? Have you looked at the sched library?

https://docs.python.org/3/library/sched.html
ndc85430 likes this post
Reply


Messages In This Thread
RE: Running an action only between certain times - by deanhystad - Mar-02-2023, 12:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pixel color and action Sartre 4 2,268 Apr-13-2023, 03:26 AM
Last Post: Sartre
  Checkbox itens with a button to run action Woogmoog 3 1,023 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
Question Running an action only if time condition is met alexbca 5 1,423 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Code running many times nad not just one? korenron 4 1,451 Jul-24-2022, 08:12 AM
Last Post: korenron
  rtmidi problem after running the code x times philipbergwerf 1 2,500 Apr-04-2021, 07:07 PM
Last Post: philipbergwerf
  Running Ajax multiple times on button click? CaptainCsaba 1 2,189 Mar-11-2020, 02:17 PM
Last Post: CaptainCsaba
  Have an amount of time to perform and action CookieGamez2018 1 3,016 Dec-21-2018, 07:12 AM
Last Post: Gribouillis
  action on MQTT while long loop is running runboy 4 6,207 Oct-05-2018, 11:57 PM
Last Post: runboy
  Hourly action resetter with threading? alex36540 3 3,432 Jan-10-2018, 07:13 AM
Last Post: Gribouillis
  recursive action elhetch 6 5,432 Jun-06-2017, 04:23 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020