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
#7
OK, I feel stupid, I added the line to print the time readout, the function is running, however I am not seeing the print of LightsActivated, but the code proceeds to action the post requests.

from pushbullet import Pushbullet
import RPi.GPIO as GPIO
import requests
from time import sleep
from gpiozero import Button
from datetime import datetime

def lights():
	now = datetime.now()
	if (2, 0, 0) <= (now.hour, now.minute, now.second) < (6, 0, 0):
		print("LightsActivated", now.hour, now.minute, now.second, now)
		requests.post('http://10.0.0.36/light/0?turn=on&brightness=100')
		requests.post('https://maker.ifttt.com/trigger/lights/json/with/key/key')
		sleep(3)
		requests.post('https://maker.ifttt.com/trigger/lights2/json/with/key/key')
		sleep(2)
		requests.post('https://maker.ifttt.com/trigger/lights3/json/with/key/key')
		sleep(3)

button = Button(2)
pb = Pushbullet("key")
pbv = Pushbullet("key")
print(pb.devices)
print(pbv.devices)

while True:
    if button.is_pressed:
        print("Trigger")
        push = pb.push_note("IR Detect", "Beams Detect")
        push = pbv.push_note("IR Detect", "Beams Detect")
        lights()
        
        sleep(21)

else:
    print("NoTrigger")
I also never get to the else when there isn't an activation. Appreciate the help for this noob!!

[Image: 2023-03-15-23-49-48-Termius-Pi.png]
Reply


Messages In This Thread
RE: Running an action only between certain times - by alexbca - Mar-15-2023, 12:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pixel color and action Sartre 4 2,247 Apr-13-2023, 03:26 AM
Last Post: Sartre
  Checkbox itens with a button to run action Woogmoog 3 1,017 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
Question Running an action only if time condition is met alexbca 5 1,417 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Code running many times nad not just one? korenron 4 1,445 Jul-24-2022, 08:12 AM
Last Post: korenron
  rtmidi problem after running the code x times philipbergwerf 1 2,496 Apr-04-2021, 07:07 PM
Last Post: philipbergwerf
  Running Ajax multiple times on button click? CaptainCsaba 1 2,180 Mar-11-2020, 02:17 PM
Last Post: CaptainCsaba
  Have an amount of time to perform and action CookieGamez2018 1 3,010 Dec-21-2018, 07:12 AM
Last Post: Gribouillis
  action on MQTT while long loop is running runboy 4 6,197 Oct-05-2018, 11:57 PM
Last Post: runboy
  Hourly action resetter with threading? alex36540 3 3,406 Jan-10-2018, 07:13 AM
Last Post: Gribouillis
  recursive action elhetch 6 5,424 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