HOWTO: Get sensor data into Home-Assistant

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ged
Normal user
Posts: 10
Joined: 15 Oct 2016, 07:04

HOWTO: Get sensor data into Home-Assistant

#1 Post by ged » 15 Oct 2016, 20:04

Hi All,

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
      }
   ]
}
In the above case, the data I want is the Temperature value inside the first element of "Sensor". JSON arrays are 0-indexed...
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'
Hopefully that helps someone.

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

Post Reply

Who is online

Users browsing this forum: No registered users and 59 guests