Template Platform

Hi All,
Please help me get started with the following.
I’m trying to get some information of my central heating system, like boiler temperature, boiler on or not, target temperature, etc, etc, visible in Home Assistant. The information needed is embedded in a JSON response from a HTTP request to a local server.
So my thought is to create entities (sensors and booleans) within Home Assistant and read the returned JSON data into these entities. Searching the Home Assistant information suggests using the Template Platform. Is this right, and how to do that (examples). Cannot figure it out based on the documentation.
Thx for your response
PPee

Please post the JSON response from your HTTP request so we can have a look at the structure. Getting values from JSON is quite easy.

This is the JSON.

{"status": "ok", "version": "3.403", "request": {"route": "/get-sensors" }, "response": {"preset":0,"time":"2020-01-22 19:21","switches":[],"uvmeters":[],"windmeters":[],"rainmeters":[],"thermometers":[],"weatherdisplays":[], "energymeters": [], "energylinks": [{"id":0,"favorite":"no","name":"EnergyLink","code":"156618","t1":"none","c1":0,"t2":"none","c2":0,"tariff":2,"s1":null,"s2":null,"aggregate":{"po":530,"dayTotal":8.51,"po+":3890,"po+t":"09:42","po-":50,"po-t":"12:26"},"used":{"po":530,"dayTotal":8.46,"po+":3890,"po+t":"09:42","po-":50,"po-t":"12:26"},"gas":{"lastHour":0.90,"dayTotal":14.10},"kwhindex":0.00,"wp":0}], "heatlinks": [{"id": 0, "favorite": "no", "name": "HeatLink", "code": "168308", "pump": "on", "heating": "on", "dhw": "off", "rte": 19.000, "rsp": 19.000, "tte": 19.000, "ttm": null, "wp": 1.699, "wte": 53.867, "ofc": 0, "odc": 0, "presets": [{ "id": 0, "te": 21.00},{ "id": 1, "te": 17.00},{ "id": 2, "te": 19.00},{ "id": 3, "te": 18.00}]}], "hues": [], "scenes": [], "kakusensors": [{"id":0,"name":"Doorbell","status":"no","type":"doorbell","favorite":"no","timestamp":"17:55","cameraid":null}], "cameras": []}}*strong text*```

Problem is how to define the appropriate entities.

"HeatLink", "code": "168308", "pump": "on", "heating": "on", "dhw": "off", "rte": 19.000, "rsp": 19.000, "tte": 19.000, "ttm": null, "wp": 1.699, "wte": 53.867, "ofc": 0, "odc": 0, "presets": [{ "id": 0, "te": 21.00},{ "id": 1, "te": 17.00},{ "id": 2, "te": 19.00},{ "id": 3, "te": 18.00}]}]

This is the relevant part

Try using a rest sensor. Place it under the sensor section:

  - platform: rest
    resource: http://your_exact_rest_url
    name: heating
    value_template: "{{ value_json.response['heatlinks'][0]['heating'] }}"

This should get you the heating attribute as on in the sensor state as an example and the sensor will be named sensor.heating

Great Tomas, this works. Thx !! -> sensor.heating = ‘on’
I presume I have to repeat this for every sensor I would like to create.
Is it possible to do the http request once, and create and fill all sensor values based on the returned JSON.

Good you got it working!
The rest sensor allows to list a number of attributes that whould be added to the sensor from the json, but it only allows first-level attributes, and your json is nested a few levels, so you need to make a sensor for each attribute that you want.

- platform: rest
  name: JSON heatlinks
  json_attributes:
    - pump              # CV Pump
    - heating           # CV Heating
    - rte               # Room Temperature
    - tte             # CV Target Temperature
  resource: !secret HW_ip_pw_getsensors
  value_template: '{{ value_json.heatlinks[0] }}'
- platform: template
  sensors:
    cv_pump:
      friendly_name: 'CV Pump'
      value_template: '{{ states.sensor.json_heatlinks[0].attributes["pump"] }}'
    cv_heating:
      friendly_name: 'CV Heating'
      value_template: '{{ states.sensor.json_heatlinks[0].attributes["heating"] }}'
    cv_rte:
      friendly_name: 'CV Room Temperature'
      value_template: '{{ states.sensor.json_heatlinks[0].attributes["rte"] }}'
    cv_tte:
      friendly_name: 'CV Target Temperature'
      value_template: '{{ states.sensor.json_heatlinks[0].attributes["tte"] }}'

This is my code now. The sensors exist in Home Assistant, but the content is “unavailable”.

I think the reference to the JSON is wrong. Any tips?
Thx,
PPee

Just copy this four times and change the name and the attribute:

  - platform: rest
    resource: http://your_exact_rest_url
    name: pump
    value_template: "{{ value_json.response['heatlinks'][0]['pump'] }}"

  - platform: rest
    resource: http://your_exact_rest_url
    name: heating
    value_template: "{{ value_json.response['heatlinks'][0]['heating'] }}"

I messed up the previous answer a bit , so I edited it to be correct.
The json_attributes sensor will not work for you.

That worked great thx.
One more question. Do you how often the http request will be made. Is it possible to limit this?
Thx again
PPee

I think its 30 seconds as default. I am not sure how to change this.