Basic REST integration

Here’s my /homeassistant/configuration.yaml code, however I can’t find the device/entity with the name “External IP”. Restarted/reloaded HASS multiple times but nothing happens. What am I missing?

# 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

# Custom code here
sensor:
  - platform: rest
    resource: http://ip.jsontest.com
    name: External IP
    value_template: "{{ value_json.ip }}"
    scan_interval: 120

Should be sensor.external_ip under Developer Tools / States. If it’s not there, check the logs for relevant entries.

Juts to be clear, this is configuration.yaml, isn’t it?

1 Like

Yes, configuration.yaml, fixed the typo in the post.

Here’s what I assume it’s relevant from the logs: Platform rest not ready yet: [Errno -5] Name has no usable address; Retrying in background in 30 seconds

Looks like I believe that I had to surround the name with quotes as it’s working now. I believe that the documentation RESTful Sensor - Home Assistant has to be updated?

I have unquoted resource lines that work fine: not sure what caused your issue.

strange indeed.

Anyway, further, how to reformat the below code to comply? Getting “duplicated mapping key (19:3)”

rest:
  scan_interval: 120
  resource: https://www.meteoromania.ro/wp-json/meteoapi/v2/starea-vremii
  sensor: 
    - name: "RO Weather Humidity"
      value_template: '{{ value_json["features"][15].properties.umezeala }}'
  sensor: 
    - name: "RO Weather Updated"
      value_template: '{{ value_json["features"][15].properties.actualizat }}'
  sensor: 
    - name: "RO Weather Clouds"
      value_template: '{{ value_json["features"][15].properties.nebulozitate }}'
  sensor: 
    - name: "RO Weather Pressure"
      value_template: '{{ value_json["features"][15].properties.presiunetext }}'
  sensor: 
    - name: "RO Weather Location"
      value_template: '{{ value_json["features"][15].properties.nume }}'
  sensor: 
    - name: "RO Weather Temperature"
      value_template: '{{ value_json["features"][15].properties.tempe }}'
  sensor: 
    - name: "RO Weather Wind"
      value_template: '{{ value_json["features"][15].properties.vant }}'```

Remove all but the first sensor: line.

Do you really need to check every two minutes? Might get banned from the API for too many requests…

You are also relying on the order of the JSON list. Perhaps you could look up your area so that you get the correct forecast even if the list order changes. For the temperature, for example:

{{ (value_json["features"]|selectattr("properties.nume","eq","POIANA STAMPEI")|first)["properties"]["tempe"] }}
2 Likes

Thank you! Is it better to build multiple sensors with different values, or a single sensor with multiple attributes/values?

With the Rest integration, it doesn’t matter as you are only making one API call.

The advantage of separate sensors with individual states is that you can assign units of measurement, and track history easily. Attributes are more fiddly to work with.

Alternatively, you could use this to create a proper weather entity:

1 Like