RESTful sensor and json

Hello,
I am beginner with REST api. I have a simple task:

on the address http://honeypi.local/backend/measurement.php are values from my sensors. it looks like this:
{"field2":24.6,"field3":64.1,"field5":14.43,"field4":968.3}

the code:

# Example configuration.yaml entry
#sensor:
- platform: rest
  resource: http://honeypi.local/backend/measurement.php
  method: GET
  payload: '{ "weight" : "temperature" : "humidity" : "pressure" }'

does not work. How should the sensor.yaml looks like to get the values to the sensor correctly?

Do i need to create the sensors manually, or will they be created automatically?

Thank you,
Michal, Slovakia

Should be like:

sensor:
  - platform: rest
    resource: http://honeypi.local/backend/measurement.php
    name: oranzovyUl_Temperature
    value_template: "{{ value_json.field2 }}"
    unit_of_measurement: "°C"

but the sensor is not appearing.

Is that in your configuration.yaml file? Do you only have one sensor: heading (you should)? Have you restarted HA?

If you have a sensor.yaml file included from the main config file, put the YAML in that file without the sensor: heading, aligned like the other entries.

I have two of them, on different levels. my full configuration.yaml:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#sensor: !include_dir_list sensors

#ZHA Toolkit activation
zha_toolkit:

# Telegram Bot
telegram_bot:
  - platform: polling
    api_key: !secret telegram_api
    allowed_chat_ids: !secret telegram_allowed_chat_ids

# Telegram Notifier
notify:
  - platform: telegram
    name: "sluha"
    chat_id: !secret telegram_chat_id

sensor:
  - platform: rest
    resource: http://honeypi.local/backend/measurement.php
    name: OranzovyTemperature
    value_template: "{{ value_json.field2 }}"
    unit_of_measurement: °C

#weewx MQTT
mqtt:
  sensor:
    - name: Outdoor_Temperature
      state_topic: weather/outTemp_C
      unique_id: uniqueid__weather_outtemp_c
      value_template: "{{ value | float | round(1) }}"
      unit_of_measurement: °C
      icon: mdi:thermometer
      device_class: temperature

    - name: Indoor_Temperature
      state_topic: weather/inTemp_C
      unique_id: uniqueid__weather_intemp_c
      value_template: "{{ value | float | round(1) }}"
      unit_of_measurement: °C
      icon: mdi:thermometer
      device_class: temperature

    - name: Wind_Speed_weewx
      state_topic: "weather/windSpeed_kph"
      unique_id: uniqueid__weather_windspeed_kph
      value_template: "{{ value | float | round(1) }}"
      unit_of_measurement: "km/h"
      icon: mdi:weather-windy-variant
      device_class: wind_speed

    - name: Wind_Gust_weewx
      state_topic: "weather/windGust_kph"
      unique_id: uniqueid__weather_windgust_kph
      value_template: "{{ value | float | round(1) }}"
      unit_of_measurement: "km/h"
      icon: mdi:weather-windy
      device_class: wind_speed

one is for MQTT and one is for rest. if I will remove one of them, the config seems to be invalid - tested through Dev tools.

That looks like it should work. Restart, and if you don’t see it, have a look in the logs. It may be that HA can’t resolve honeypi.local perhaps.

1 Like

thanks for pointing the direction.
I changed honeypi.local to the IP address, restarted, and! it WORKS :smile:

1 Like