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.