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:

  1. data = response.text
  2. parsed = json.loads(data)
  3. vr = float(parsed["state"])
  4. print vr

response is 14.3, this is what i need, temperature of my sensor....

How add this to prtg?

Thankyou...


Article Comments

Hi there,

Thanks for the KB post.

Our Python sensor expects an output follow as stated in the manual:

https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

Thanks.


With kind regards,
Chan Siau Hen
Technical Support Team, Paessler AG.


Aug, 2021 - Permalink