Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from requests import get
- import json
- from datetime import datetime
- from datetime import timedelta
- today = datetime.today()
- x = 10 # liczba dni
- delta = timedelta(days=x)
- period = (today - delta).strftime("%Y-%m-%dT%H:%M:%S")
- HOST = "192.168.1.x" # HA IP adres
- SENSOR = "sensor.airly_temperature" # sensor
- DATE = period
- END_POINT = "history/period/{}?filter_entity_id={}".format(DATE, SENSOR)
- url = "http://{}:8123/api/{}".format(HOST, END_POINT)
- # HA LIVE TOKEN
- f = open("/config/HA_API_KEY.txt", "r") # "Bearer aaaBBBBcccDDDeeeFFF...." -
- HA_API_KEY = f.readline()
- f.close()
- headers={"Authorization": HA_API_KEY, "content-type": "application/json" }
- response = get(url, headers=headers)
- response_json = response.json()
- list_states = []
- for i in response_json[0]:
- if i['state'] == 'unavailable':
- list_states.append(float(list_states[-1]))
- else:
- list_states.append(float(i['state']))
- print(max(list_states))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement