Last active 1725702434

gistfile1.txt Raw
1#!/bin/bash
2set -e
3
4# https://dev.netatmo.com/apidocumentation/weather#Available-data og velg værstasjon
5# Filter på denne url i inspectoren for å få module ID og device ID
6# https://app.netatmo.net/api/simplifiedfuturemeasure
7
8# ELLER
9# Gå til https://weathermap.netatmo.com/ og finn et punkt, hent URL fra "share"
10# https://weathermap.netatmo.com//?zoom=16.1802283695561&type=temp&param=Filter&stationid=70%3Aee%3A50%3A2c%3A91%3A60&maplayer=Map&lang=undefined
11# stationid=70%3Aee%3A50%3A2c%3A91%3A60 blir da device_id, renskrevet til 70:ee:50:2c:91:60 (replace %3A med :)
12
13device_id="70:ee:50:2c:91:60"
14module_id="02:00:00:2c:b2:30"
15
16random_agent=$(shuf -n 1 <(curl -fsSL https://gist.githubusercontent.com/jakebathman/e57bad07fae95f4776f2588c919777d7/raw/cb998ab2c5e08501722544923c3f6b41e373d88b/user-agents.txt | grep -v '^$'))
17access_token=$(curl --silent -A "$random_agent" https://weathermap.netatmo.com | grep 'accessToken' | sed -E 's/.*accessToken: "(.*)",/\1/')
18
19# Time and 6 hours ago in Unix time
20date_end=$(date +%s)
21date_begin=$(($date_end - 3600))
22# 6 hours in unix time is 21600
23# 3 hours in unix time is 10800
24# 1 hour in unix time is 3600
25
26
27temp_humidity=$(curl --silent 'https://app.netatmo.net/api/getmeasure' --compressed -X POST \
28-H "User-Agent: $random_agent" \
29-H 'Accept: application/json, text/plain, */*' \
30-H 'Accept-Language: nb,en-US;q=0.7,en;q=0.3' \
31-H 'Accept-Encoding: gzip, deflate, br, zstd' \
32-H "Authorization: Bearer $access_token" \
33-H 'Content-Type: application/json;charset=utf-8' \
34-H 'Origin: https://weathermap.netatmo.com' \
35-H 'DNT: 1' \
36-H 'Connection: keep-alive' \
37-H 'Sec-Fetch-Dest: empty' \
38-H 'Sec-Fetch-Mode: cors' \
39-H 'Sec-Fetch-Site: cross-site' \
40-H 'Sec-GPC: 1' \
41-H 'Pragma: no-cache' \
42-H 'Cache-Control: no-cache' \
43--data-raw '{"date_begin":"'"$date_begin"'","date_end":"'"$date_end"'","scale":"max","device_id":"'"$device_id"'","module_id":"'"$module_id"'","type":"Temperature,Humidity"}' | jq '.body | last | .value[0][0]')
44
45pressure=$(curl --silent 'https://app.netatmo.net/api/getmeasure' --compressed -X POST \
46-H "User-Agent: $random_agent" \
47-H 'Accept: application/json, text/plain, */*' \
48-H 'Accept-Language: nb,en-US;q=0.7,en;q=0.3' \
49-H 'Accept-Encoding: gzip, deflate, br, zstd' \
50-H "Authorization: Bearer $access_token" \
51-H 'Content-Type: application/json;charset=utf-8' \
52-H 'Origin: https://weathermap.netatmo.com' \
53-H 'DNT: 1' \
54-H 'Connection: keep-alive' \
55-H 'Sec-Fetch-Dest: empty' \
56-H 'Sec-Fetch-Mode: cors' \
57-H 'Sec-Fetch-Site: cross-site' \
58-H 'Sec-GPC: 1' \
59-H 'Pragma: no-cache' \
60-H 'Cache-Control: no-cache' \
61--data-raw '{"date_begin":"'"$date_begin"'","date_end":"'"$date_end"'","scale":"max","device_id":"70:ee:50:2c:91:60","module_id":"70:ee:50:2c:91:60","type":"Pressure"}' | jq '.body | last | .value[0][0]')
62
63# echo "Tid:"
64echo "Temperatur: $temp_humidity"
65echo "Pressure: $pressure"
66