u/Chemical-Hurry-8194

Need advice on automating latch opening
▲ 11 r/RASPBERRY_PI_PROJECTS+1 crossposts

Need advice on automating latch opening

I mainly want help in making sure this setup is not needlessly complicated. I am designing a project to automate opening a wall safe through a flic button and a pi 02W. My vision is to have it embedded in a bust like the Adam west batcave button and have the pi execute a code that unlatches an electromagnetic solenoid holding the door shut. I am slightly foreign to this world but I am confident in my ability to follow directions and based on what I’ve found this should be relatively simple.

I had AI whip up a materials list, wiring diagram and python code (I’d love to learn on my own if I discover I enjoy this hobby it was just easier that way). Anything is appreciated, thank you all in advance.

Python script: from gpiozero import OutputDevice
from time import sleep

import fliclib

# -----------------------------
# GPIO SETUP
# -----------------------------

SOLENOID_PIN = 17

solenoid = OutputDevice(SOLENOID_PIN)

# -----------------------------
# SETTINGS
# -----------------------------

UNLOCK_PULSE_TIME = 0.2
RELOCK_DELAY = 5

# -----------------------------
# FUNCTIONS
# -----------------------------

def unlock():
print("UNLOCKING")

solenoid.on()
sleep(UNLOCK_PULSE_TIME)
solenoid.off()

def relock():
print("RELOCKING")

solenoid.on()
sleep(UNLOCK_PULSE_TIME)
solenoid.off()

# -----------------------------
# FLIC CALLBACK
# -----------------------------

class ButtonConnectionChannel(fliclib.ButtonConnectionChannel):

def on_button_single_or_double_click_or_hold(
self,
click_type,
was_queued,
time_diff
):

if click_type == fliclib.ClickType.ButtonSingleClick:

print("BUTTON PRESSED")

unlock()

sleep(RELOCK_DELAY)

relock()

# -----------------------------
# FLIC CLIENT
# -----------------------------

client = fliclib.FlicClient("localhost")

def got_button(bd_addr):
print("Button connected:", bd_addr)

cc = ButtonConnectionChannel(bd_addr)

client.add_connection_channel(cc)

client.get_info(got_button)

print("Waiting for Flic button...")

client.handle_events()

u/Chemical-Hurry-8194 — 5 days ago