REST Error fetching data - HTTP hosted on ESP8266 not working in HASS

I’m having issues with HTTP REST calls to my Arduino/ESP8266 which works with CURL, Fiddler, and all browsers but not Home Assistant.

configuration.yaml

sensor:
  - platform: rest
    resource: http://192.168.0.69/json
    name: WeMos D1 UpTime
    value_template: '{{ value_json.UpTime }}'

Errors in home-assistant.log

2017-10-01 12:41:35 ERROR (Thread-10) [homeassistant.components.sensor.rest] Error fetching data: <PreparedRequest [GET]>
2017-10-01 12:41:35 ERROR (Thread-10) [homeassistant.components.sensor.rest] Unable to fetch REST data

Browsers work perfectly fine, so does Fiddler and the below curl attempts from the shell.

hass# curl -X GET http://192.168.0.69/json
{
“UpTime”: “14:33:21”,
“Free Mem”: “34KB of 80KB”
}

I also have a Raspberry Pi with PHP which spits out JSON and that works with HAss for some odd reason. I’ve taken ALL of the headers (including the HTTP 200 success, content-type, etc.) from that response and threw it into my Arduino code but it still did not work. I realize the above curl example shows return of no headers but, believe me I’ve tried every way possible with & w/o headers. Even with identical headers that the RPi succeeds with I’m still getting that annoying fetch REST error above. I can also clearly see good attempts via TCPDUMP when manually running the CURL attempts. The HAss attempt never show up in TCPDUMP.

Any way to debug this? Can I see the URL being called, headers, etc… The logged error entries above are not very actionable. I’ve also tried the LOGGER component in HAss and it showed nothing extra.

Thank you!

Just stating the obvious, but shouldn’t the IP addresses be the same?

Sorry, that’s my fault :slight_smile: definitely using the same URL. Not an ID 10 T problem, I swear :slight_smile: modified above to match. I also have multiple NodeMCU modules for testing.

The next thing that might be a problem, is spaces and upper case in names. I have learned the hard way to keep the name: field to lower case and _

Just tried it, changed to wemos_uptime and got same error. Went into HASS UI and badges were missing as usual. Below is a successful RPi with mixed letter case, seems to work well.

  - platform: rest
    resource: http://192.168.0.246/?UseJSON=
    name: Gate UpTime
    value_template: '{{ value_json.UpTime }}'

image

Not sure what happened but all three sensors now work showing the same info.

  - platform: command_line
    command: python3 -c "import requests; print(requests.get('http://192.168.0.11/json').json()['Temperature'].split(' ')[1].split('\'')[0])"
    name: Nice WeMos TempPY
    unit_of_measurement: "°F"
  - platform: rest
    resource: http://192.168.0.11/json
    name: Nice WeMos TempREST
    value_template: '{{ value_json.Temperature.split(" ")[1].split("''")[0] }}'
    unit_of_measurement: "°F"
  - platform: mqtt
    name: "Nice Wemos Temperature"
    state_topic: "smartthings/Nice Wemos/temperature"
    unit_of_measurement: "°F"

I’m no longer getting a single REST Error… so friggin strange… Anyway here’s the Arduino HTTP header that was used with success:

  jsonResponse.concat("HTTP/1.x 200 OK\n");
  jsonResponse.concat("Content-Type: application/json\n");
  jsonResponse.concat("\n"); //  do not forget this one
  jsonResponse.concat("{\n"); //  start of json
1 Like