RESTful Sensor wird nicht angezeigt. // Shelly 3EM // YAML

Hallo Team,

ich stocke beim erstellen eines Sensors per REST in der configuration.yaml.
Es soll die aktuelle Leistung ausgegeben werden, die vom Shelly 3EM per JSON alle 2 Sekunden übermittelt werden soll.

sensor:
- platform: rest
  scan_interval: 2
  name: demo_power
  resource: http://192.168.1.151/status
  value_template: "{{ value_json.emeters.total_power }}"
  unit_of_measurement: "W"
  force_update: true

- platform: template
  sensors:
    energy_total:
      friendly_name: 'Total Energy'
      entity_id:
usw.

Die Sensoren per template funktionieren hingegen wunderbar.
Jetzt etwas, was mich verwundert:
Unter Einstellungen/Geräte wird erkannt, dass ein Sensor existieren soll:
2024-12-23 21_27_38-Einstellungen – Home Assistant – Mozilla Firefox

wenn ich diese Entität anwähle, ist die Liste allerdings leer.

Folgende Fehler finden sich im Log:

Logger: homeassistant.helpers.template
Quelle: helpers/template.py:2746
Erstmals aufgetreten: 22:15:33 (218 Vorkommnisse)
Zuletzt protokolliert: 22:22:50

Template variable warning: 'list object' has no attribute 'total_power' when rendering '{{ value_json.emeters.total_power }}'

sowie

Logger: homeassistant.helpers.entity
Quelle: helpers/entity.py:960
Erstmals aufgetreten: 22:15:35 (217 Vorkommnisse)
Zuletzt protokolliert: 22:22:50

Update for sensor.demo_power fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 672, 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 675, 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.py", line 960, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1318, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/rest/entity.py", line 64, in async_update
    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 679, in state
    raise ValueError(
    ...<5 lines>...
    ) from err
ValueError: Sensor sensor.demo_power has device class 'None', state class 'None' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)

Habt ihr einen Tipp?

Gruß und Dank
Lunch

Hi Lunch,

warum denn so kompliziert? Richte doch einfach MQTT in deinem Shelly ein. Siehe dazu auch: Shelly 3EM via MQTT in HA einbinden!