Please note that there are so far 3 follow up edits down the page, with more information.
For some time i have been using this code underneath, as a way to setup webhooks.
I use the read_smokedetector scope and i am getting the "sound_test" information in etc. But for some reason which i can not figure out, when i test the smoke alarm with "smokecheck no-25s", the alarm goes off, it is shown in the app, that smoke has been detected(with all the regular warnings etc) But the "smoke" webhook is never recieved on our server.
Webhooks does work, since the sound_test functionality, activated from the app still triggers the webhook which is recived, but nothing comes in when smoke is detected.
We have been using this approach for a while and its been working fine, so i am a bit baffeled.
[edit1]
I tried setting up a new app and pointing the hoop to https://webhook.site/
I get the "push_type": "webhook_activation" and the "push_type": "NSD-sound_test" but i dont get the smoke type when i test the alarm
[/edit1]
[edit2]
I have now tried with a few of the devices here and the behavior is the same, i am getting a various amount of webhooks, but the webhook indicating smoke detection is never sent from the netatmo backend it seems, who do i need to contact regarding this? [/edit2]
[edit3]
Looking at the issue further, it seems like the only webhook which is related to the alarm it self, arrving at the endpoint is only the sound_test, I get tons of webhooks related to the registration process today when i registered around 15 alarms, but none of the following detection_chamber_status,battery_status,smoke,tampered,wifi_status,hush
Only sound_test, is arriving
I have checked the API endpoint /gethomedata to see if the data exists, which is does, when i request it in that way.
curl -X GET "https://api.netatmo.com/api/gethomedata ... XX&size=10" -H "accept: application/json" -H "Authorization: Bearer XXXXXXXXXXXXX|XXXXXXXXXX"
[/edit3]
Code: Select all
# coding=utf-8
from flask import Flask, request, render_template
import requests, json, os
app = Flask(__name__)
# ENVIRONMENT VARIABLE
APP_URL = 'http://x.x.x.x' #url/ip of server where this script is running on.
CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxx' #app page on netatmodev site
CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #app page on netatmodev site
webhook_url = 'http://x.x.x.x' #url needs to be supplied without the endpoint name, endpoint will be added on line 55
# GLOBAL VARIABLE
SCOPE = 'read_smokedetector'
@app.route('/', methods=['GET', 'POST'])
def home():
request_url = 'https://api.netatmo.com/oauth2/authorize?client_id=' + CLIENT_ID + '&redirect_uri=' + APP_URL + '/netatmoOAuth&scope=' + SCOPE + '&state=abcd'
return render_template('index.html', url = request_url)
@app.route('/netatmoOAuth', methods=['GET'])
def netatmoOAuth():
# GET USER CODE
code_user = request.args.get('code')
# CALL NETATMO TO RETRIEVE TOKEN
host_url = 'https://api.netatmo.com/oauth2/token'
request_datas = {
'grant_type' : 'authorization_code',
'client_id' : CLIENT_ID,
'client_secret' : CLIENT_SECRET,
'code' : code_user,
'redirect_uri' : APP_URL + '/netatmoOAuth',
'scope' : SCOPE
}
# GET ACCESS TOKEN
json_return = requests.post(host_url, data = request_datas)
access_token = json_return.json()['access_token']
# ADD WEB HOOK
#add_web_hook_url = 'https://api.netatmo.com/api/addwebhook?url=' + webhook_url # + '/webhook'
add_web_hook_url = 'https://api.netatmo.com/api/addwebhook?url=' + webhook_url + '/netatmo'
json_return = requests.get(add_web_hook_url, headers = {'Authorization' : 'Bearer ' + access_token})
web_hook_status = json_return.json()['status']
# VERIFY WEB HOOK
if web_hook_status == "ok":
return render_template('success.html')
return render_template('error.html')
@app.route('/netatmo', methods=['GET', 'POST'])
def webhook():
# VERIFY JSON
json_file = request.json
if json_file == None:
Message("JSON is null.")
return "JSON is null."
# SHOW JSON IN LOG
app.logger.info('request json : %s', request.json)
print(request.json)
return '', 200
def Message(text):
print(text)