New ESP user, thought I'd share how I got sensor data into Home Assistant home automation suite.
After pm_cz helped me get past my little IDX=0 problem, the key was getting the data as json.
So http://<ESP>/json gets the data like: (<ESP> is the IP or hostname of your ESP device)
Code: Select all
{
"System":{
"Build":137,
"Unit":0,
"Uptime":27,
"Free RAM":26984
},
"Sensors":[
{
"TaskName":"BMP280",
"Temperature":22.07,
"Pressure":1001.18
}
]
}
So we are after Sensors[0].Temperature.
In Home Assistant configuration.yaml that translates into a block that looks like this:
Code: Select all
- platform: rest
resource: http://<ESP>/json
name: Sensor 1 Temperature
value_template: '{{ value_json.Sensors.0.Temperature }}'
unit_of_measurement: '°C'
Possible improvements:
* match the desired array element by the TaskName rather than array index number (i.e. Sensors[where TaskName="BMP280"].Temperature)
* Home Assistant is polling the ESP, meaning it can't sleep, might be better (lower power consumption for battery power scenarios) if there was a way to push data to Home Assistant so it could sleep. (I know this is possible one set's up a MQTT service, but I don't know much about that yet)
-G