Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106113

RESTful Sensor: unexpected value in value_json

$
0
0

Hello everyone,

I want to set my son’s alarm clock (Alexa) via Home Assistant. To do this, I want to get the substitute schedule from Stundenplan24, find my son’s class there, filter out irrelevant lessons (e.g. sports girls) and missed lessons and then get the lesson number of the first remaining lesson. The whole thing should happen via a RESTfull sensor.

I get the data as XML. The documentation says that XML from the RESTfull sensor is automatically converted to JSON and can/must be filtered using JSONPath.

As a test, I got the XML for one day, converted it at Best XML to JSON Converter Online and wrote a JSONPath (with try & error :slight_smile: ). I can’t post the XML or JSON here. This is too long and contains sensitive data but when I test the JSONPath with JSONPath Online Evaluator, I get the following string array:

[
  "2",
  "3",
  "4",
  "5",
  "6"
]

Now I have configured my REST sensor as follows (I changed the school number in the URL):

sensor:
- platform: rest
  resource_template: "https://www.stundenplan24.de/10000000/mobil/mobdaten/PlanKl{{ (now() + timedelta(days=1)).strftime('%Y%m%d') }}.xml"
  name: "indiware_first_lesson"
  username: !secret indiware_username
  password: !secret indiware_password
  authentication: basic
  json_attributes_path: "$.VpMobil.Klassen.Kl[?(@.Kurz == '7a')].Pl.Std[?(@.Fa != '---' && @.Fa.__text != '---' && @.Fa != 'SPOw' && @.Fa.__text != 'SPOw')].St"
  value_template: "{{ value_json[0] }}"

My expectation would be that the value 2 (as a string) from the upper string array comes back as a sensor value. But the sensor doesn’t work like that. In the log I get the warning:

Template variable warning: dict object has no element 0 when rendering '{{ value_json[0] }}'

It seems as if the JSONPath is not being evaluated at all and the sensor is trying to write the entire json object to value_json. What am I doing wrong here?

Thank you for your support!
fion

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>