- Joined
- Aug 11, 2018
- Messages
- 677
- Reaction score
- 1,123
The python script seems to configure the IO with pull down instead of pull up. This makes it seem like the switch should be wired to 3v3 and GPIO.The circuit is in heatshrink but if I remember correctly it's a just a 10k resistor splitting the ground wire.
Here's the main bit of the python script...
Code:def my_callback(channel): if GPIO.input(8) == GPIO.HIGH: print('\n FLOAT at ' + str(datetime.datetime.now())) log = open("current_water_level.txt", "w") print (('OK | Last flipped at ' + str(datetime.datetime.now())), file = log) else: print('\n SINK at ' + str(datetime.datetime.now())) log = open("current_water_level.txt", "w") print (('Low | Last flipped at ' + str(datetime.datetime.now())), file = log) GPIO.setmode(GPIO.BCM) GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(8, GPIO.BOTH, callback=my_callback)
It's run every few minutes via cron and the status is broadcast via mqtt to my home assistant server which can send out alerts & trigger the top off. I'd prefer getting it into reef-pi so I can trigger the top off directly.