Help decoding Foobot input

Hi there!

I managed to connect my Foobot air quality sensor to Homeassistant using rest, but now im blocked trying to decode the JSON to show the actual data (temperature, humidity and so on). I tried to take a look at the templates but I cant seem to get it to work…

The JSON looks like this:

{“uuid”:“xxx”,“start”:1508500402,“end”:1508500402,“sensors”:[“time”,“pm”,“tmp”,“hum”,“co2”,“voc”,“allpollu”],“units”:[“s”,“ugm3”,“C”,“pc”,“ppm”,“ppb”,"%"],“datapoints”:[[1508500402,7.9200134,21.803,57.178,710,197,18.205727]]}

Thanks for your help!

The processing of incoming data is described in the “Processing incoming data” section.

You will only be able to get one value per sensor. According your data it’s a nested list which requires a little bit more, e.g, for the temperature {{ value_json.datapoints[0][2] }}

Hi!

that did the trick, thanks! However, now im faced with a new issue…the Foobot API limits the number of queries to 200 per day, which by default is reached in a couple hours in homeassistant, can i edit this frequency somehow?

Thanks very much!

In the configuration variables of the RESTful component, you can specify the poll interval in seconds (scan_interval). So for Foobot, which is limited to 200 queries per day, you should specifiy something higher than (24x60x60)/200 = 432 seconds, for instance:
scan_interval: 450

Do you mind sharing the FooBot integration code?

I have one and this would be really useful :slight_smile: .

Happy to :slight_smile: Here’s the configuration.yaml part:

Foobot

sensor:
platform: rest
resource: https://api.foobot.io/v2/device/xxx/datapoint/0/last/0/
name: foobot
value_template: ‘{{ value_json.datapoints[0][2] }}’
unit_of_measurement: ‘C’
scan_interval: 450
headers:
X-API-KEY-TOKEN: xxx

you can get your name and api key from api.foobot.io/apidoc/index.html. As mentioned, only the temperature works so far

Thanks mate! This did a great job.

I’ve updated it a bit in order to get multiple values with single REST call. This requires additional platform named jsonrest. Here is the config I’ve used for that:

sensor:
  - platform: jsonrest
    resource: https://api.foobot.io/v2/device/{device_id}/datapoint/0/last/0/
    name: FooBot
    scan_interval: 600
    headers:
      X-API-KEY-TOKEN: '{token}'
      Accept: application/json

  - platform: template
    sensors:
      pm:
        friendly_name: PM
        value_template: '{{ "%.1f" | format(states.sensor.foobot.attributes.datapoints[0][1]) }}'
        unit_of_measurement: 'ugm3'
      temp:
        friendly_name: Temperature
        value_template: '{{ states.sensor.foobot.attributes.datapoints[0][2] | int  }}'
        unit_of_measurement: 'C'
      humidity:
        friendly_name: Humidity
        value_template: '{{ states.sensor.foobot.attributes.datapoints[0][3] | int  }}'
        unit_of_measurement: '%'
      voc:
        friendly_name: VOC
        value_template: '{{ states.sensor.foobot.attributes.datapoints[0][5] | int  }}'
        unit_of_measurement: 'ppb'
      polution:
        friendly_name: Polution
        value_template: '{{ states.sensor.foobot.attributes.datapoints[0][6] | int  }}'
        unit_of_measurement: '%'

I made a component for foobot, it’s working so far but I have some cleaning up to do before making a PR for integration into HA mainline. Mostly related to the python package for the API and documentation, not the component itself.

In the meantime, if anyone here want to test it, it would be appreciated to get some feedback before publishing it.

It’s available at: https://github.com/reefab/home-assistant/blob/foobot/homeassistant/components/sensor/foobot.py

Just copy this file to your ~/.homeassistant/custom_components/sensor and add the following to your configuration:

sensor:
  - platform: foobot
    token: <API Key>
    username: <username>

02

It works fine in my HA 0.65.1!

Thanks :slight_smile:

But when more than 200 API call…impossible to connect again :worried:

The component is now integrated into 0.66.

And it is working fine!

EXCELLENT!

Thank you :slight_smile:

I am a newb to Hass and installed it on Ubuntu. I am trying to get Foobot working and added the device and token to my config but it doesn’t appear to be doing anything and I am not seeing anything in my logs either. I have a few devices working but not the foobot. Looking at the API, it is also not seeing any call from Hass. I verified that I have 0.66 and the foobot.py is present in the python folder. I am running python 3.6. Not sure what I am missing… The username is the email address correct?