Sensor: required key 'platform' not provided

Hi,

I am trying to integrate my amis device with the given rest api template, but it doesn´t seem to be up to date. This is the error at logs:

Invalid config for 'sensor' at configuration.yaml, line 31: required key 'platform' not provided, please check the docs at https://www.home-assistant.io/integrations/sensor

I can´t find any platform config at the documentation, which is provided. And here is my configuration.yaml, which I inserted:

resource: http://192.168.188.109/rest
scan_interval: 1 # refresh interval
headers:
  accept: "application/json"
sensor:
  - name: "Amis Verbrauch minus Einspeisung"
    unique_id: AmisEnergySensorSaldo
    state_class: total_increasing
    unit_of_measurement: W
    device_class: energy
    value_template: "{{ value_json.saldo }}"
  - name: "Amis aktueller Verbrauch"
    unique_id: AmisEnergySensor_1_7_0
    state_class: total_increasing
    unit_of_measurement: W
    device_class: energy
    value_template: "{{ value_json['1.7.0'] }}"
  - name: "Amis aktuelle Einspeisung"
    unique_id: AmisEnergySensor_2_7_0
    state_class: total_increasing
    unit_of_measurement: W
    device_class: energy
    value_template: "{{ value_json['2.7.0'] }}"
  - name: "Amis Zählerstand Bezug"
    unique_id: AmisEnergySensor_1_8_0
    state_class: total
    unit_of_measurement: kWh
    device_class: energy
    value_template: "{{ value_json['1.8.0'] }}"
  - name: "Amis Zählerstand Einspeisung"
    unique_id: AmisEnergySensor_2_8_0
    state_class: total
    unit_of_measurement: kWh
    device_class: energy
    value_template: "{{ value_json['2.8.0'] }}"

Can anyone please tell me what is wrong here?

Check the difference with the doc example
RESTful - Home Assistant

1 Like

You incorrectly put that config in your sensors.yaml file.

rest: is not a sensor platform, it is an integration. It goes in your configuration.yaml file like all the other integrations.

configurationl.yaml

rest:
  - resource: http://192.168.188.109/rest
    scan_interval: 1 # refresh interval
    headers:
      accept: "application/json"
    sensor:
      - name: etc...

You can of course create your own include file to keep your configuration.yaml file tidy:

configuration.yaml:

rest: !include rest_sensors.yaml

rest_sensors.yaml

- resource: http://192.168.188.109/rest
  scan_interval: 1 # refresh interval
  headers:
    accept: "application/json"
  sensor:
    - name: etc...

As a final note, a 1 second scan interval is overkill. 10 seconds will be fine for power.

Hi,

thanks! I´ve rewritten die config and it was already placed at configuration.yaml:

rest:
    - resource: http://192.168.188.109/rest
      scan_interval: 30
      headers:
        accept: "application/json"
      sensor:
      - name: "Amis Verbrauch minus Einspeisung"
        unique_id: AmisEnergySensorSaldo
        state_class: total_increasing
        unit_of_measurement: W
        device_class: energy
        value_template: "{{ value_json.saldo }}"
      - name: "Amis aktueller Verbrauch"
        unique_id: AmisEnergySensor_1_7_0
        state_class: total_increasing
        unit_of_measurement: W
        device_class: energy
        value_template: "{{ value_json['1.7.0'] }}"
      - name: "Amis aktuelle Einspeisung"
        unique_id: AmisEnergySensor_2_7_0
        state_class: total_increasing
        unit_of_measurement: W
        device_class: energy
        value_template: "{{ value_json['2.7.0'] }}"
      - name: "Amis Zählerstand Bezug"
        unique_id: AmisEnergySensor_1_8_0
        state_class: total
        unit_of_measurement: kWh
        device_class: energy
        value_template: "{{ value_json['1.8.0'] }}"
      - name: "Amis Zählerstand Einspeisung"
        unique_id: AmisEnergySensor_2_8_0
        state_class: total
        unit_of_measurement: kWh
        device_class: energy
        value_template: "{{ value_json['2.8.0'] }}"

There are no values since 12 hours at my energy dashboard, but I can´t see any errors on reboot.

This is an example output of the resource:

{"1_8_0":50760982,"2_8_0":0,"3_8_1":11972952,"4_8_1":2745599,"1_7_0":791,"2_7_0":0,"3_7_0":0,"4_7_0":572,"1_128_0":0,"saldo":791}

After rebooting my home assistant I found this log entry:

Error adding entity sensor.amis_aktueller_verbrauch for domain sensor with platform rest
Error adding entity sensor.amis_aktuelle_einspeisung for domain sensor with platform rest
Error adding entity sensor.amis_zahlerstand_bezug for domain sensor with platform rest
Error adding entity sensor.amis_zahlerstand_einspeisung for domain sensor with platform rest
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 636, in state
    numerical_value = int(value)
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 639, in state
    numerical_value = float(value)
ValueError: could not convert string to float: ''

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 633, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 972, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1383, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/rest/entity.py", line 43, in async_added_to_hass
    self._update_from_rest_data()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/components/rest/sensor.py", line 186, in _update_from_rest_data
    self.async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in async_write_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 643, in state
    raise ValueError(
    ...<5 lines>...
    ) from err
ValueError: Sensor sensor.amis_aktueller_verbrauch has device class 'energy', state class 'total_increasing' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)

Have figured it out. The json variables were wrong 1_7_0 instead of 1.7.0 e.g. and also some sensors needed power instead of energy.

Here the complete config for amis if needed by anyone:

rest:
    - resource: http://192.168.188.109/rest
      scan_interval: 30
      headers:
        accept: "application/json"
      sensor:
      - name: "Amis Verbrauch minus Einspeisung"
        unique_id: AmisEnergySensorSaldo
        state_class: measurement
        unit_of_measurement: W
        device_class: power
        value_template: "{{ value_json.saldo }}"
      - name: "Amis aktueller Verbrauch"
        unique_id: AmisEnergySensor_1_7_0
        state_class: measurement
        unit_of_measurement: W
        device_class: power
        value_template: "{{ value_json['1_7_0'] }}"
      - name: "Amis aktuelle Einspeisung"
        unique_id: AmisEnergySensor_2_7_0
        state_class: measurement
        unit_of_measurement: W
        device_class: power
        value_template: "{{ value_json['2_7_0'] }}"
      - name: "Amis Zählerstand Bezug"
        unique_id: AmisEnergySensor_1_8_0
        state_class: total
        unit_of_measurement: kWh
        device_class: energy
        value_template: "{{ value_json['1_8_0'] }}"
      - name: "Amis Zählerstand Einspeisung"
        unique_id: AmisEnergySensor_2_8_0
        state_class: total
        unit_of_measurement: kWh
        device_class: energy
        value_template: "{{ value_json['2_8_0'] }}"