Configuration.yaml for rest platform

I have a PicoW that reads temperature and humidity from a DHT22 sensor. Readings are then put into json format.

I can make Home Assistant get the readings via two sensors configured as follows:

sensor:

  • platform: rest
    name: Temperature
    scan_interval: 4
    resource: “http://172.16.0.69:80
    value_template: “{{ value_json.temperature }}”
    unit_of_measurement: “℃”

  • platform: rest
    name: Humidity
    scan_interval: 4
    resource: “http://172.16.0.69:80
    value_template: “{{ value_json.humidity }}”
    unit_of_measurement: “%”

My question is: is this the right way to do this please?

I notice that Home Assistant connects to the PicoW twice in quick succession, presumably because I have created two separate sensors. Is it possible to set this up in a more “elegant” way so Home Assistant only needs to connect once?

Any other improvements please?

Many thanks.

Please format your post correctly. See: How to help us help you - or How to ask a good question

If you use the restful integration rather than the rest sensor platform you can populate as many sensors as you want from the one call to the resource.

The docs have a poor example:

Each sensor can have a value template (like you have in your post).

EDIT: now that I my at my PC, here’s an example:

configuration.yaml (not sensors.yaml)

rest:
  - resource: "http://172.16.0.69:80"
    scan_interval: 4
    sensor:
      - name: Temperature
        value_template: "{{ value_json.temperature }}"
        unit_of_measurement: "℃"
      - name: Humidity
        value_template: "{{ value_json.humidity }}"
        unit_of_measurement: %"

This will populate both sensors with one call to the resource.

Apologies for not formatting the code correctly.

But many thanks to Tom_I: solution tested and confirmed as working exactly how I want.

Thanks again, much appreciated.

1 Like