Create a gist now

Instantly share code, notes, and snippets.

@fvdbosch /onion-ifttt.py Secret
Last active Feb 14, 2017

What would you like to do?
Onion Omega2 - IFTTT Triggers
#!/usr/bin/env python
import onionGpio
from time import sleep
from os import system
ifttt_key = ""
system("omega2-ctrl gpiomux set i2c gpio")
btn1 = onionGpio.OnionGpio(18)
btn2 = onionGpio.OnionGpio(19)
btn3 = onionGpio.OnionGpio(11)
btn4 = onionGpio.OnionGpio(5)
btn1.setInputDirection()
btn2.setInputDirection()
btn3.setInputDirection()
btn4.setInputDirection()
led1 = onionGpio.OnionGpio(0)
led2 = onionGpio.OnionGpio(1)
led3 = onionGpio.OnionGpio(2)
led4 = onionGpio.OnionGpio(3)
led1.setOutputDirection(0)
led2.setOutputDirection(0)
led3.setOutputDirection(0)
led4.setOutputDirection(0)
btn1_current_value = ""
btn1_previous_value = ""
btn2_current_value = ""
btn2_previous_value = ""
btn3_current_value = ""
btn3_previous_value = ""
btn4_current_value = ""
btn4_previous_value = ""
def trigger_event(event):
system("wget -qO- /dev/null https://maker.ifttt.com/trigger/" + event + "/with/key/" + ifttt_key + " > /dev/null")
while True:
btn1_current_value = btn1.getValue().rstrip()
btn2_current_value = btn2.getValue().rstrip()
btn3_current_value = btn3.getValue().rstrip()
btn4_current_value = btn4.getValue().rstrip()
if(btn1_current_value == "0" and btn1_current_value != btn1_previous_value):
led1.setValue(1)
led2.setValue(0)
led3.setValue(0)
led4.setValue(0)
trigger_event("onion_1")
elif(btn2_current_value == "0" and btn2_current_value != btn2_previous_value):
led1.setValue(0)
led2.setValue(1)
led3.setValue(0)
led4.setValue(0)
trigger_event("onion_2")
elif(btn3_current_value == "0" and btn3_current_value != btn3_previous_value):
led1.setValue(0)
led2.setValue(0)
led3.setValue(1)
led4.setValue(0)
trigger_event("onion_3")
elif(btn4_current_value == "0" and btn4_current_value != btn4_previous_value):
led1.setValue(0)
led2.setValue(0)
led3.setValue(0)
led4.setValue(1)
trigger_event("onion_4")
btn1_previous_value = btn1_current_value
btn2_previous_value = btn2_current_value
btn3_previous_value = btn3_current_value
btn4_previous_value = btn4_current_value
sleep(.05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment