Sorry, but I've looked at several threads and no one talks about my idea.
I'm currently working with a switch, that will manage the Christmas-tree lights, to turn it on at 18:00 and off at 01:00 (e.g.)
I don't know which option is the best.
I can set a script that switches on at 18:00, wait 5 hours, and then switches it off
I would like to look for its state and change it, but for some reason, I've changed the switch once and no more changes are possible.
This is my current code, very simple.
#!/usr/bin/python3
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
#GPIO.setwarnings(False)
GPIO_ENCHUFE = 27
try:
GPIO.setup(GPIO_ENCHUFE,GPIO.OUT) # Here it breaks
current_state = GPIO.gpio_function(GPIO_ENCHUFE)
# Cambio de estado
opposite_state = (current_state+1)%2
GPIO.output(GPIO_ENCHUFE,opposite_state)
#sleep(5)
except Exception as e:
# Cambiar a version email
print("Algo ha ocurrido\n"+str(e))
GPIO.cleanup()
Does anyone know any option to keep the switch status after the program ends?