Created
March 4, 2025 21:36
-
-
Save bandrel/15d3266b2e48070b7f6af2b3a4ff6c49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/env python3 | |
# /// script | |
# dependencies = [ | |
# "flask", | |
# "requests", | |
# ] | |
# /// | |
#Signup for https://trigger.esp8266-server.de/ to enable webhooks within Alexa using the webhooks skill. | |
#https://www.amazon.com/Michael-Dworkin-Webhook-Routine-Trigger/dp/B09RGPYHLL | |
#Create Alexa routine using the webhooks to change the scene | |
#Replace the id and hash with the ones generated in the applicaion process | |
from flask import Flask, request, jsonify | |
import requests | |
app = Flask(__name__) | |
# Replace this with the URL you want to GET | |
baseurl = 'https://trigger.esp8266-server.de/api/' | |
DND_on = f'{base_url}?id={id1}&hash={hash}' | |
DND_off = f'{base_url}?id={id2}&hash={hash}' | |
@app.route('/') | |
def index(): | |
return "Webhook listener is running!" | |
@app.route('/webhook', methods=['GET','POST']) | |
def webhook(): | |
global enabled_state | |
data = request.get_json() | |
if data["call"] == 'active': | |
# Trigger a GET request to an external service | |
get_response = requests.get(DND_on) | |
enabled_state = True | |
else: | |
get_response = requests.get(DND_off) | |
enabled_state = False | |
return f"Current State is {enabled_state}" | |
if __name__ == "__main__": | |
# Run the Flask app on port 5001(or any port you prefer) | |
app.run(host="0.0.0.0", port=5001, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment