Hi… made a api witch spits out a JSON (parsed and checked on various parsers online)
This is my JSON:
{"icao24":"040102","registration":"ET-ASH","manufacturericao":"BOEING","manufacturername":"Boeing","model":"Boeing 787-8","typecode":"B788","serialnumber":"38754","linenumber":"283","icaoaircrafttype":"L2J","operator":"Ethiopian Airlines","operatorcallsign":"ETHIOPIAN","operatoricao":"ETH","operatoriata":"ET","owner":"Ethiopian Airlines","testreg":"","registered":"2015-04-01","reguntil":"","status":"","built":"2015-01-01","firstflightdate":"","engines":"","modes":"false","adsb":"false","acars":"false","notes":"","categoryDescription":"Heavy (> 300000 lbs)"}
My rest sensor is configured like this:
sensor:
- platform: rest
### REST Sensor for AIRPLAN INFO..
resource: "http://192.168.1.10/minglarn/php/find_aircraft.php?air=040102"
timeout: 40
name: aircraft_info
method: GET
json_attributes:
- manufacturericao
- manufacturername
- model
- operator
- owner
- registered
- built
When checking the logs i see:
2022-04-25 01:33:16 WARNING (MainThread) [homeassistant.components.rest.sensor] Empty reply found when expecting JSON data
But when I do a CURL -X GET i do get the json…
What is wrong here?!
tom_l
April 25, 2022, 1:33am
2
You have no value_template for the sensor state.
tom_l
April 25, 2022, 5:55am
4
Every sensor must have a state. Attributes are optional. All you are defining is the attributes of the sensor. Not the state. So it is attempting to use the entire json reply, which is over 255 characters, which is not allowed for states (attributes can be over 255 characters).
So set a state with a value template.
For example:
value_template: "OK"
or if you want something more meaningful
value_template: "{{ value_json.icao24 }}"
Aha… ok… I see…
But, did add that, still getting errors…
2022-04-25 08:47:58 WARNING (MainThread) [homeassistant.components.rest.sensor] Empty reply found when expecting JSON data
2022-04-25 08:47:58 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.manufacturername }}'
Does the PHP script set the correct Content-Type
header?
<?php
header('Content-Type: application/json; charset=utf-8');
...
?>
Should be enough?
Think I found the cause…
My REST sensor is using a input_text …
sensor:
- platform: rest
### REST Sensor for AIRPLANE INFO..
resource: "http://192.168.1.10/minglarn/php/find_aircraft.php?air={{states('input_text.opensky_icao')}}"
When using a real value it works… but not with a input.text value… Damn…
So next time, put your actual code in your question
Instead of resource
, use resource_template
. See the fine manual .
Damn, feeling stupid… “resource_template” made the REST work…
BIG thanks to all of you…
tom_l
April 25, 2022, 8:33am
11
In future when you post an issue, please post your actual config.