RESTful sensor to read data from Thingspeak

Hi all -

I just wanted to chime in here. I just received my Hydroponics Kit from ThingSpeak and had configured it all to their specifications and calibrated everything then looked to see about implementing it into Home Assistant. I saw the MQTT topic but since I had already calibrated I didn’t want to re-wipe the chip and waste all of that so I was determined to get the API working and that led me here.

I usually don’t post questions and will dig around tirelessly until I find an answer so this topic had everything I needed except a lot of the answers seemed to have a lot of assumptions and I couldn’t put two and two together until I came to @Segdop’s post and saw the full context of the yaml needed. I was able to use what he put with some slight modifications as there was a couple of issues with it.

This is what I was able to put into my configuration.yaml where it worked beautifully for me. All you need to do is put your channel id and api key in the right spots:

sensor:
  - platform: rest
    name: Hydroponic Kit
    json_attributes:
      - field1
      - field2
      - field3
    resource: https://api.thingspeak.com/channels/[CHANNEL ID]/feeds/last.json?api_key=[API KEY]
    value_template: '{{ value_json.created_at }}'
  - platform: template
    sensors:
     hydroponic_kit_temperature:
        friendly_name: 'Temp'
        value_template: '{{ state_attr("sensor.hydroponic_kit", "field3") }}'
        unit_of_measurement: '°C'
     hydroponic_kit_ph:
        friendly_name: 'pH'
        value_template: '{{ state_attr("sensor.hydroponic_kit", "field1") }}'
        unit_of_measurement: 'pH'
     hydroponic_kit_ec:
        friendly_name: 'EC'
        value_template: '{{ state_attr("sensor.hydroponic_kit", "field2") }}'
        unit_of_measurement: 'µS/cm'

My tap water readings which yield the expected results:

image

Hopefully this helps someone.

2 Likes

Perfect I can now pull the data from my esp8266 weather station

sensor:
  - platform: rest
    name: Waynes Weather
    json_attributes:
      - field1
      - field2
      - field3
      - field4
    resource: https://api.thingspeak.com/channels/[CHANNEL ID]/feeds/last.json?api_key= [API KEY]
    value_template: '{{ value_json.created_at }}'
  - platform: template
    sensors:
     waynes_weather_temperature:
        friendly_name: 'Temp'
        value_template: '{{ state_attr("sensor.waynes_weather", "field1") }}'
        unit_of_measurement: '°C'
     waynes_weather_humidity:
        friendly_name: 'Rh'
        value_template: '{{ state_attr("sensor.waynes_weather", "field2") }}'
        unit_of_measurement: 'rH'
     waynes_weather_light:
        friendly_name: 'Lux'
        value_template: '{{ state_attr("sensor.waynes_weather", "field3") }}'
        unit_of_measurement: 'lx'
     waynes_weather_pressure:
        friendly_name: 'Hg'
        value_template: '{{ state_attr("sensor.waynes_weather", "field4") }}'
        unit_of_measurement: 'hg'

image

When I paste the code into my yaml I get problems with other stuff