-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
58 lines (43 loc) · 1.17 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import sys
import time
import datetime
import requests
import os
def run():
date = datetime.datetime.now()
print("Start at:", date)
url = 'http://hassio/homeassistant/api/states/' + config["entity"]
headers = {'content-type': 'application/json', 'Authorization': token}
r = requests.get(url, headers=headers)
json_resp = json.loads(r.text)
try:
value = json_resp["state"]
except:
print("Could not get temperature")
return
print("Temperature:", value)
print("Reporting...")
url = 'http://www.temperatur.nu/rapportera.php?hash=' + config["hash"] + '&t=' + value
r = requests.get(url)
print(r.text)
print("Starting Addon")
with open('/data/options.json', 'r') as f:
config = json.load(f)
if config["interval"] < 30:
print("Interval is to small.")
print("Exit..")
sys.exit(0)
if config["entity"] == "":
print("No entity")
print("Exit..")
sys.exit(0)
if config["hash"] == "":
print("No hash")
sys.exit(0)
token = os.environ['HASSIO_TOKEN']
while True:
run()
print("Sleeping",config["interval"],"seconds")
time.sleep(config["interval"])
print('\n')