Modbus fails to start when a custom structure is used

I am trying to read out the Power Factor of my Carlo Gavazzi EM24.
I am already sure that the register is 46 and the data type a INT16 in Big Endian format.
I tried to create a sensor with this config:

- name: "Stromzähler"
    type: tcp
    host: 192.168.*.*
    port: 502
    sensors:
      - name: "Power Factor L1"
        slave: 1
        address: 46
        data_type: custom
        structure: ">h"
        scale: 0.001
        precision: 3
        scan_interval: 5

but whenever i add the custom structure the modbus platform fails to start with this error message:

2023-05-05 18:45:09.453 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up modbus platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 304, in _async_setup_platform
await asyncio.shield(task)
File "/usr/src/homeassistant/homeassistant/components/modbus/sensor.py", line 52, in async_setup_platform
sensor = ModbusRegisterSensor(hub, entry)
File "/usr/src/homeassistant/homeassistant/components/modbus/sensor.py", line 68, in __init__
super().__init__(hub, entry)
File "/usr/src/homeassistant/homeassistant/components/modbus/base_platform.py", line 163, in __init__
self._count = config[CONF_COUNT]
KeyError: 'count'

The raw data would be “ff8a” and that should result in the value -133 or -0.133 with the right decimal place.

Solved it my self I forgot the count parameter the working config looks like this:

  - name: "Stromzähler"
    type: tcp
    host: 192.168.*.*
    port: 502
    sensors:
      - name: "Power Factor L1"
        slave: 1
        address: 46
        data_type: custom
        structure: ">h"
        count: 1
        scale: 0.001
        precision: 3
        scan_interval: 15
1 Like