REST Sensor (Meteobridge) - JSON - no sensors/values

I am trying to integrate some temperature/humidity sensors read by Meteobridge into my Home Assistant.
I am relative new to HA with some programming knowledge in VBA/VB.NET.
The existing Meteobridge Integration is not able to serve my (rather awkward) needs.

Therefore I am trying to evaluate a call to Meteobridge as several HA sensors.

Here is my YAML code:

- platform: rest
  name: meteobridge_rest
  resource: http://user:[email protected]/cgi-bin/template.cgi?template={"th1":{"temp":"[th1!1temp-act:0]","hum":"[th1!1hum-act:0]"},"th2":{"temp":"[th1!2temp-act:0]","hum":"[th1!2hum-act:0]"},"th3":{"temp":"[th1!3temp-act:0]","hum":"[th1!3hum-act:0]"},"th4":{"temp":"[th1!4temp-act:0]","hum":"[th1!4hum-act:0]"},"th5":{"temp":"[th1!5temp-act:0]","hum":"[th1!5hum-act:0]"},"th6":{"temp":"[th1!6temp-act:0]","hum":"[th1!6hum-act:0]"},"th7":{"temp":"[th1!7temp-act:0]","hum":"[th1!7hum-act:0]"},"th8":{"temp":"[th1!8temp-act:0]","hum":"[th1!8hum-act:0]"}}
  scan_interval: 60
  json_attributes:
    - th1
    - th2
    - th3
    - th2
    - th5
    - th6
    - th7
    - th8
    - platform: template
      sensors:
        MB_rest_TH1_temperature:
          value_template: "{{ state_attr('sensor.meteobridge_rest', 'th1')['temp'] }}"
          device_class: temperature
          unit_of_measurement: "°C"
        MB_rest_TH1_humidity:
          value_template: "{{ state_attr('sensor.meteobridge_rest', 'th1')['hum'] }}"
          device_class: humidity
          unit_of_measurement: "%"

It is inside sensors.yaml, called from configuration.yaml with this command.

sensor: !include sensors.yaml

The answer of Meteobridge is following:

{"th1" : {"temp":"22.7","hum":"70.0"},"th2" : {"temp":"23.4","hum":"71.0"},"th3" : {"temp":"23.5","hum":"70.0"},"th4" : {"temp":"25.3","hum":"72.0"},"th5" : {"temp":"26.4","hum":"57.0"},"th6" : {"temp":"0","hum":"0"},"th7" : {"temp":"0","hum":"0"},"th8" : {"temp":"0","hum":"0"}}

I get no error message in the log, but neither are the sensors created or have values.

The format of the answer is defined by me.
I was trying to replicate this example from documentation.

What am I doing wrong?

The indentation for the Template sensor is incorrect. It should be like this:

- platform: rest
  name: meteobridge_rest
  resource: http://user:[email protected]/cgi-bin/template.cgi?template={"th1":{"temp":"[th1!1temp-act:0]","hum":"[th1!1hum-act:0]"},"th2":{"temp":"[th1!2temp-act:0]","hum":"[th1!2hum-act:0]"},"th3":{"temp":"[th1!3temp-act:0]","hum":"[th1!3hum-act:0]"},"th4":{"temp":"[th1!4temp-act:0]","hum":"[th1!4hum-act:0]"},"th5":{"temp":"[th1!5temp-act:0]","hum":"[th1!5hum-act:0]"},"th6":{"temp":"[th1!6temp-act:0]","hum":"[th1!6hum-act:0]"},"th7":{"temp":"[th1!7temp-act:0]","hum":"[th1!7hum-act:0]"},"th8":{"temp":"[th1!8temp-act:0]","hum":"[th1!8hum-act:0]"}}
  scan_interval: 60
  json_attributes:
    - th1
    - th2
    - th3
    - th2
    - th5
    - th6
    - th7
    - th8
- platform: template
  sensors:
    MB_rest_TH1_temperature:
      value_template: "{{ state_attr('sensor.meteobridge_rest', 'th1')['temp'] }}"
      device_class: temperature
      unit_of_measurement: "°C"
    MB_rest_TH1_humidity:
      value_template: "{{ state_attr('sensor.meteobridge_rest', 'th1')['hum'] }}"
      device_class: humidity
      unit_of_measurement: "%"

However, you may still encounter a problem. The response from the Meteobridge is 280 characters long which exceeds the length of what any entity’s state value can hold (255 characters).

You may be better served by using the RESTful integration which is designed to perform one REST call and use the response for multiple sensors.

Here’s an example of how it’s used:

rest:
  - resource: http://user:[email protected]/cgi-bin/template.cgi?template={"th1":{"temp":"[th1!1temp-act:0]","hum":"[th1!1hum-act:0]"},"th2":{"temp":"[th1!2temp-act:0]","hum":"[th1!2hum-act:0]"},"th3":{"temp":"[th1!3temp-act:0]","hum":"[th1!3hum-act:0]"},"th4":{"temp":"[th1!4temp-act:0]","hum":"[th1!4hum-act:0]"},"th5":{"temp":"[th1!5temp-act:0]","hum":"[th1!5hum-act:0]"},"th6":{"temp":"[th1!6temp-act:0]","hum":"[th1!6hum-act:0]"},"th7":{"temp":"[th1!7temp-act:0]","hum":"[th1!7hum-act:0]"},"th8":{"temp":"[th1!8temp-act:0]","hum":"[th1!8hum-act:0]"}}
    scan_interval: 60
    sensor:
      - name: "MB TH1 Temperature"
        value_template: "{{ value_json.th1.temp }}"
        device_class: temperature
        unit_of_measurement: "°C"
      - name: "MB TH1 Humidity"
        value_template: "{{ value_json.th1.hum }}"
        device_class: humidity
        unit_of_measurement: "%"
      - name: "MB TH2 Temperature"
        value_template: "{{ value_json.th2.temp }}"
        device_class: temperature
        unit_of_measurement: "°C"
      - name: "MB TH2 Humidity"
        value_template: "{{ value_json.th2.hum }}"
        device_class: humidity
        unit_of_measurement: "%"
      - name: "MB TH3 Temperature"
        value_template: "{{ value_json.th3.temp }}"
        device_class: temperature
        unit_of_measurement: "°C"
      - name: "MB TH3 Humidity"
        value_template: "{{ value_json.th3.hum }}"
        device_class: humidity
        unit_of_measurement: "%"
1 Like

Thank you very much. The RESTful integration works perfectly.