Adding a Name to a Rest Sensor Prevents Data From Appearing

I’ve added a rest sensor to pull data from UtilityAPI. Took a bit to get the JSON formatting to work but I got it. Then I wanted to change the name to something meaningful rather than just “REST Sensor”. When I add the “name” parameter the new entity appears, however, the data stops showing up. I’ve restarted many times and tried a few different was of adding the rest sensor, but can’t get it to work with a proper name.

Config that works without a name…

sensor:
  - platform: rest
    resource: https://utilityapi.com/api/v2/intervals?meters=xxxxxxx&limit=1&order=latest_first
    headers:
      Authorization: >
        Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    scan_interval: 120
    device_class: ENERGY
    state_class: total_increasing
    value_template: "{{ value_json['intervals']['readings']['kwh']}}"

image

All I do is add a name like below and it stops working…

sensor:
  - platform: rest
    name: Energy Demo
    resource: https://utilityapi.com/api/v2/intervals?meters=xxxxxxx&limit=1&order=latest_first
    headers:
      Authorization: >
        Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    scan_interval: 120
    device_class: ENERGY
    state_class: total_increasing
    value_template: "{{ value_json['intervals']['readings']['kwh']}}"

[There was supposed to be another screenshot here, but I’m new, so…]

I’ve tried it with quotes and without.

I also tried this method of adding a rest sensor, however it keeps giving an error…
“JSON result was not a dictionary or list with 0th element a dictionary”

rest:
    resource: https://utilityapi.com/api/v2/intervals?meters=xxxxxxxx&limit=1&order=latest_first
    headers:
      Authorization: >
        Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    scan_interval: 120
    sensor:
      name: "EnergyDemo"
      device_class: ENERGY
      state_class: total_increasing
      json_attributes_path: "$.intervals.readings[0]"
      json_attributes:
        - kwh
      value_template: "{{ value_json['intervals']['readings']['kwh']}}"

Any help getting this to work with a name would be great.

Also, when trying to use the unit_of_measure parameter it gives an error…

“Invalid config for ‘rest’ at configuration.yaml, line 42: ‘unit_of_measure’ is an invalid option for ‘rest’, check: rest->0->sensor->0->unit_of_measure”

Adding the name will also change the entity id. If you use this config below It will now be called sensor.energy_demo.

sensor:
  - platform: rest
    name: Energy Demo
    resource: https://utilityapi.com/api/v2/intervals?meters=xxxxxxx&limit=1&order=latest_first
    headers:
      Authorization: >
        Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    scan_interval: 120
    device_class: ENERGY
    state_class: total_increasing
    value_template: "{{ value_json['intervals']['readings']['kwh']}}"

Or this is how you indent the rest integration:

rest:
    resource: https://utilityapi.com/api/v2/intervals?meters=xxxxxxxx&limit=1&order=latest_first
    headers:
      Authorization: >
        Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    scan_interval: 120
    sensor:
      - name: "Energy Demo"
        device_class: ENERGY
        state_class: total_increasing
        json_attributes_path: "$.intervals.readings[0]"
        json_attributes:
          - kwh
        value_template: "{{ value_json['intervals']['readings']['kwh']}}"
1 Like

No problem finding the new entity, however, the new entity doesn’t get any data.

so a new entity gets created, sensor.energy_demo.
Whats its state ? Is it unknown, unavailable, something else ?

to set the unit, its unit_of_measurement not unit_of_measure

2 Likes

Thanks, I’ve been overlooking “unit_of_measurement” for more hours than I’d like to admit.

The entity shows unknown.

Do you see any attributes ? Or are they also not listed ?
Anything in logs RE rest sensor?

You could try enabling debug logging for rest.

Below is the yaml that ended up working. Thanks for all the help. Unfortunately, the data coming from UtilityAPI isn’t suitable for a sensor.

sensor:
  - platform: rest
      name: Energy Rest Sensor
      resource: https://utilityapi.com/api/v2/intervals?meters=xxxxxxx&limit=1&order=latest_first
      headers:
        Authorization: >
          Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      scan_interval: 3600
      device_class: ENERGY
      state_class: total_increasing
      value_template: "{{ value_json['intervals'][0]['readings'][0]['kwh']}}"
      unit_of_measurement: kWh
1 Like

Commenting to say that this post helped me a lot and pushed me into paying for the UtilityAPI service (Monthly pull/year) for both my LADWP and SoCalGas reporting, both are considered “Bills” on the UtilityAPI side, where as this integration looks liek to be a direct to the meter? – im very green when it comes to understanding how RESTful even works.

That being said i think i’m going to open my own topic about this same integration (RESTful and UtilityAPI.com) i have strange loggings and will link/reference this topic.