I have an esp32 running a simple rest server. It returns this
{"temperature":73.95800018,"pressure":30.02012825,"humidity":33.10644531,"battery":4152}
My configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
rest:
- resource: "http://192.168.1.247/data.xml"
scan_interval: 300
sensor:
- name: "Temperature"
value_template: "{{ value_json[0].temperature }}"
device_class: temperature
state_class: measurement
- name: "Pressure"
value_template: "{{ value_json[0].pressure }}"
device_class: pressure
state_class: measurement
- name: "Humidity"
value_template: "{{ value_json[0].humidity }}"
device_class: humidity
state_class: measurement
- name: "Battery"
value_template: "{{ value_json[0].battery }}"
device_class: battery
state_class: measurement
Been trying for days to get the data into HA so this is a fresh bare HA install
I have tried changing the value_template(and everything else) a hundred different ways,
this is as simple and paired down as I can make it yet it is still somehow beyond me
tom_l
February 24, 2024, 11:39pm
2
There is no list in your data so no need for [0]
in your templates.
Thank You!
Tried
value_template: "{{ value_json['temperature'] }}"
still no data
value_template: "{{ value_json.temperature }}"
gives template error
I’ve tried setting this up as a RESTful sensor also with the same result. I even reconfigured the REST server to provide this simple format. The entities show up but “unknown” for all values
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
rest:
- resource: "http://192.168.1.247/data.xml"
scan_interval: 300
sensor:
- name: "Temperature"
value_template: "{{ value_json['temperature'] }}"
device_class: temperature
unit_of_measurement: "°F"
- name: "Pressure"
value_template: "{{ value_json['pressure'] }}"
device_class: pressure
unit_of_measurement: "inHg"
- name: "Humidity"
value_template: "{{ value_json['humidity'] }}"
device_class: humidity
unit_of_measurement: "%"
- name: "Battery"
value_template: "{{ value_json['battery'] }}"
device_class: battery
unit_of_measurement: "mV"
This looks as close to the example here “RESTful - Home Assistant ” and “RESTful Sensor - Home Assistant ” as I can do.
This one(s)
* Template variable error: 'value_json' is undefined when rendering '{{ value_json.temperature }}'
* Template variable error: 'value_json' is undefined when rendering '{{ value_json.pressure }}'
* Template variable error: 'value_json' is undefined when rendering '{{ value_json.humidity }}'
* Template variable error: 'value_json' is undefined when rendering '{{ value_json.battery }}'
tom_l
February 25, 2024, 1:50am
7
This is incorrect:
device_class: battery
unit_of_measurement: "mV"
The device class battery can only have a % unit. Use the voltage device class if the unit is mV.
https://www.home-assistant.io/integrations/sensor/#device-class
tom_l
February 25, 2024, 1:51am
8
Then you are not sending this data:
Jack_B_Nimble:
e an esp32 running a simple rest server. It returns this
{"temperature":73.95800018,"pressure":30.02012825,"humidity":33.10644531,"battery":4152}
This is the data
{
“temperature”: 76.1720047,
“pressure”: 30.00678444,
“humidity”: 33.60058594,
“battery”: 4120
}
I’ll cut the battery section and try again but…
tom_l
February 25, 2024, 1:56am
10
Oh I just noticed this:
Jack_B_Nimble:
data.xml
XML to json conversion may be messing it up. As you are not sending XML but you have an XML file extension.
What does this return:
rest:
- resource: "http://192.168.1.247/data.xml"
scan_interval: 300
sensor:
- name: "Test value"
value_template: "{{ value }}"
- name: "Test value_json"
value_template: "{{ value_json }}"
tom_l
February 25, 2024, 2:01am
11
You could also try this:
rest:
- resource: "http://192.168.1.247/data.xml"
headers:
Content-Type: application/json
scan_interval: 300
sensor:
- name: "Temperature"
value_template: "{{ value_json['temperature'] }}"
device_class: temperature
unit_of_measurement: "°F"
- name: "Pressure"
value_template: "{{ value_json['pressure'] }}"
device_class: pressure
unit_of_measurement: "inHg"
- name: "Humidity"
value_template: "{{ value_json['humidity'] }}"
device_class: humidity
unit_of_measurement: "%"
- name: "Battery"
value_template: "{{ value_json['battery'] }}"
device_class: voltage
unit_of_measurement: "mV"
Template variable warning: 'value_json' is undefined when rendering '{{ value_json }}'
I think I’ve tried everything. Its been a week, totally gutted system starting over and over.
tom_l
February 25, 2024, 2:05am
13
What is the value of:
sensor:
- name: "Test value"
value_template: "{{ value }}"
Did you try this?
pasted as you posted still unknown ,
"Test value"
never got that far because above error
sensor:
- name: "Test value"
value_template: "{{ value }}"
Not found: /data.xml
- name: "Test value_json"
value_template: "{{ value_json }}"
returns nothing
tom_l
February 25, 2024, 2:26am
16
What do you get when you visit this in a web browser:
http://192.168.1.247/data.xml
Holy Stuff
rest:
- resource: "http://192.168.1.247/data"
headers:
Content-Type: application/json
scan_interval: 300
sensor:
- name: "Temperature"
value_template: "{{ value_json['temperature'] }}"
device_class: temperature
unit_of_measurement: "°F"
- name: "Pressure"
value_template: "{{ value_json['pressure'] }}"
device_class: pressure
unit_of_measurement: "inHg"
- name: "Humidity"
value_template: "{{ value_json['humidity'] }}"
device_class: humidity
unit_of_measurement: "%"
- name: "Battery"
value_template: "{{ value_json['battery'] }}"
device_class: voltage
unit_of_measurement: "mV"
It works just removing .xml I feel so stupid I wasted a week, never ever read the docs!
Thanks Tom, I really appreciate your help getting this working.
Now I’m throwing the whole damn thing off the deck!
1 Like