What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Sensor Python code (Invalid JSON.). (code: PE231)

Votes:

0

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...

json python requests

Created on Aug 20, 2021 7:33:43 AM



1 Reply

Votes:

0

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.

Created on Aug 25, 2021 6:36:11 AM by  Chan Siau Hen [Paessler Technical Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.