UtilityAPI for LADWP and SoCalGas

For starters, im very new to the concept of RESTful and im figuring it out as i go along – this topic helped: Adding a Name to a Rest Sensor Prevents Data From Appearing

Currently i get a lot of errors in my logging while attempting to incorporate the following YAML in Configuration.conf

I was hoping someone could come along and point me in the right direction.

I also realize that the Billing total might not be a:

state_class: total_increasing

im not sure what this value should be but the goal right now is to see somthing in the HA Energy Dashboard

rest:
  resource: https://utilityapi.com/api/v2/bills?meters=936596
  headers:
    Authorization: >
      Bearer REMOVED
  scan_interval: 1200
  sensor:
    - name: "LADWP UtilityAPI - Base"
      device_class: ENERGY
      state_class: total_increasing
      json_attributes_path: "$.bills[0]"
      json_attributes:
        - uid
        - meter_uid
        - authorization_uid
        - created
        - updated
        - notes
        - utility
        - blocks
    - name: "LADWP UtilityAPI - Blocks"
      device_class: ENERGY
      state_class: total_increasing
      json_attributes_path: "$.bills.base[0]"
      json_attributes:
        - service_identifier
        - service_tariff
        - service_class
        - service_address
        - meter_numbers
        - billing_contact
        - billing_address
        - billing_account
        - bill_statement_date
        - bill_start_date
        - bill_end_date
        - bill_total_cost
        - bill_total_volume
        - bill_total_unit
      value_template: "{{ value_json['bill_total_volume']['kwh']}}"
      unit_of_measurement: kWh
    - name: "LADWP UtilityAPI - Line Items"
      device_class: ENERGY
      state_class: total_increasing
      json_attributes_path: "$.bills.lines[0]"
      json_attributes:
        - name
        - start
        - end
        - cost
        - volume
        - rate
        - unit
        - kind
      value_template: "{{ value_json['volume']['kwh']}}"
      unit_of_measurement: kWh
    - name: "LADWP UtilityAPI - Tiers"
      device_class: ENERGY
      state_class: total_increasing
      json_attributes_path: "$.bills.tiers[0]"
      json_attributes:
        - name
        - level
        - cost
        - volume
        - unit
      value_template: "{{ value_json['volume']['kwh']}}"
      unit_of_measurement: kWh
    - name: "LADWP UtilityAPI - ToU"
      device_class: ENERGY
      state_class: total_increasing
      json_attributes_path: "$.bills.time-of-use[0]"
      json_attributes:
        - name
        - bucket
        - cost
        - volume
        - unit
      value_template: "{{ value_json['volume']['kwh']}}"
      unit_of_measurement: kWh

As far as the error logs go there is so much identifying information in there i’m not sure what’s enough to share with out DOX’ing my self. Therefor i will de-identify with out losing the integrity of the log data.

Update: Log too big for post…

1 Like

The log but broken down to bits and pieces seeing as how its over 400k in lenght:

2024-03-21 11:27:16.127 ERROR (MainThread) [homeassistant.components.sensor] Error adding entity sensor.ladwp_utilityapi_base for domain sensor with platform rest
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 668, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 

After this error was the bulk of the error message that similar to this:

'{\n    "bills": [\n        {\n            "authorization_uid": "XXXREMOVED_IDENTIFYING_INFOXXX",\n            "base": {\n                "bill_end_date": "2024-01-19T00:00:00.000000-08:00",\n                "bill_start_date": "2023-11-15T00:00:00.000000-08:00",\n                "bill_statement_date": "2024-01-19T00:00:00.000000-08:00",\n                "bill_total_cost": 594.36,\n                "bill_total_kwh": 2394.0,\n                "bill_total_unit": "kwh",\n                "bill_total_volume": 2394.0,\n                "billing_account": "XXXREMOVED_IDENTIFYING_INFOXXX",\n                "billing_address": "XXXREMOVED_IDENTIFYING_INFOXXX AVE, SAN PEDRO CA 90731",\n                "billing_contact": "XXXREMOVED_IDENTIFYING_INFOXXX",\n                "meter_numbers": [\n                    "AND00009-01504730"\n                ],\n                "service_address": "XXXREMOVED_IDENTIFYING_INFOXXX AVE, SAN PEDRO, CA 90731",\n                "service_class": "electric",\n                "service_identifier": 

Then…what looks like some JSON structure:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 576, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 865, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1327, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 161, in async_added_to_hass
    await super().async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/rest/entity.py", line 42, in async_added_to_hass
    self._update_from_rest_data()
  File "/usr/src/homeassistant/homeassistant/components/rest/sensor.py", line 180, in _update_from_rest_data
    self._process_manual_data(raw_value)
  File "/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py", line 238, in _process_manual_data
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1050, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
    raise ValueError(
ValueError: Sensor sensor.ladwp_utilityapi_base has device class 'None', state class 'total_increasing' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '{
    "bills": [
        {
            "authorization_uid": "XXXREMOVED_IDENTIFYING_INFOXXX",
            "base": {
                "bill_end_date": "2024-01-19T00:00:00.000000-08:00",
                "bill_start_date": "2023-11-15T00:00:00.000000-08:00",
                "bill_statement_date": "2024-01-19T00:00:00.000000-08:00",
                "bill_total_cost": 594.36,
                "bill_total_kwh": 2394.0,

and Lastly:

2024-03-21 11:27:16.143 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary
2024-03-21 11:27:16.165 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary
2024-03-21 11:27:16.168 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary
2024-03-21 11:27:16.170 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary

in the YAML is it get to the spot that is only the device_class of energy, or do i have to define everything that would be in the JSON?