HI! I try to make Python Script advance script, but get error (Invalid JSON.). (code: PE231). My python script work on rassberry py and on my windows installed python 3.9 Here is my python script:; ------------------------------------------------------------ from requests import get import json import threading
url = "http://homeassistant.local:88/api/states/sensor.a4c138a3bba8_temperature" headers = { "Authorization": "Bearer xy", "content-type": "application/json", }
response = get(url, headers=headers) print(response.text) ---------------------------------------------------------- and response is :
{"entity_id": "sensor.a4c138a3bba8_temperature", "state": "20.1", "attributes": {"unit_of_measurement": "\u00b0C", "friendly_name": "Balkon Temperature", "device_class": "temperature"}, "last_changed": "2021-08-20T07:20:44.263451+00:00", "last_updated": "2021-08-20T07:20:44.263451+00:00", "context": {"id": "de2rdd0aefee81c6882ee0", "parent_id": null, "user_id": null}}
I can also parse this value to add in python code:
- data = response.text
- parsed = json.loads(data)
- vr = float(parsed["state"])
- print vr
response is 14.3, this is what i need, temperature of my sensor....
How add this to prtg?
Thankyou...
Add comment