Hello,is there anyway to make a momentary switch on a RaspberryPi?
do you want the momentary switch on dashboard? what you are using it for? i do not see any use of an momentary switch. you can send OFF command back once it is pressed after X seconds.
Ok, I wanted to use it to pulse a relay connected to an older garage door opener to open and close it. It’s and older opener that just needs a few seconds close on the control wire to open and close it.
you can do this in your python code if you are using a MQTT cayenne python library.
Ok, do you have and example of what that code would look like? I was thinking the momentary switch would also be useful to build a fireworks launcher with a relay hatt. Although it’s a little to late this year.
first you need add a device to cayenne using this https://github.com/myDevicesIoT/Cayenne-MQTT-Python.
once done you can write your own code to turn ON relay and turn OFF after X seconds while sending back OFF command to button.
Ok, something like this code I found on the internet?
import cayenne.client #Cayenne MQTT Client<br> from gpiozero import LED led=LED(17) #Declaring button pin 17</p><p> # Cayenne authentication info. This should be obtained from the Cayenne Dashboard. MQTT_USERNAME = "YOUR MQTT USERNAME" MQTT_PASSWORD = "YOUR MQTT PASSWORD " MQTT_CLIENT_ID = "YOUR CLIENT ID"</p><p> # The callback for when a message is received from Cayenne. def on_message(message): print("message received: " + str(message)) if message.channel==1: #Dashboard Led widget channel. They must be same. if message.value=="1": #If led command "1", turn led on(message.value must be string) led.on() elif message.value=="0": #If led command "0", turn led off(message.value must be string) led.off()</p><p> client = cayenne.client.CayenneMQTTClient() client.on_message = on_message #When message recieved from Cayenne run on_message function client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)</p><p> while True: client.loop()
yup that should wok and then send OFF value back to cayenne.
Hey, I wanted to do the same thing and since I don’t really know enough about Python to make that work, I accomplished the same thing with a time delay relay. I originally just used the Trigger function and let the network lag turn the switch off if it’s on. The problem with that was how long it latched the output on before refreshing. It was so long that I would open the garage, walk into the house and still have to wait for a while before I could close the garage. Since the output was latched, I couldn’t close it with the button on the wall. I fixed this with a Drok timer relay from Amazon for $10 and used it to send a one second pulse when the Cayenne App switch was turned on. I used the same Trigger to reset it with the lag but didn’t care because once in the garage, I always use the wall button anyways. If I had to, I can just manually turn the switch off-then-on again to close it faster. I know this is an old post but thought some one else may be able to use this simple solution. Regards.
Hello, do you happen to have the model number of the device by chance?