Advertisement
jarekmor

max_value

Dec 16th, 2022 (edited)
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | Source Code | 0 0
  1. #!/usr/bin/python3
  2.  
  3. from requests import get
  4. import json
  5. from datetime import datetime
  6. from datetime import timedelta
  7.  
  8. today = datetime.today()
  9. x = 10                                                          # liczba dni
  10. delta = timedelta(days=x)
  11. period = (today - delta).strftime("%Y-%m-%dT%H:%M:%S")
  12.  
  13. HOST = "192.168.1.x"                                            # HA IP adres
  14. SENSOR = "sensor.airly_temperature"                         # sensor
  15. DATE = period
  16.  
  17. END_POINT = "history/period/{}?filter_entity_id={}".format(DATE, SENSOR)
  18. url = "http://{}:8123/api/{}".format(HOST, END_POINT)
  19.  
  20. # HA LIVE TOKEN
  21. f = open("/config/HA_API_KEY.txt", "r")                     # "Bearer aaaBBBBcccDDDeeeFFF...."  -
  22. HA_API_KEY = f.readline()
  23. f.close()
  24.  
  25. headers={"Authorization": HA_API_KEY, "content-type": "application/json" }
  26. response = get(url, headers=headers)
  27. response_json = response.json()
  28.  
  29. list_states = []
  30. for i in response_json[0]:
  31.     if i['state'] == 'unavailable':
  32.          list_states.append(float(list_states[-1]))
  33.     else:
  34.         list_states.append(float(i['state']))
  35.    
  36. print(max(list_states))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement