core icon indicating copy to clipboard operation
core copied to clipboard

Create Modbus Devices for each listed connection point in Modbus configuration

Open rschoell opened this issue 1 year ago • 21 comments

The problem

I've recently switched my Keba integration from the internal integration (based on unreliable UDP protocol) to Modbus TCP. So far this is far more stable and controllable, as TCP is stateful protocol. One thing that bothers me (and others: https://community.home-assistant.io/t/modbus-sensors-unique-id-and-device-support/373428) is, that we create a "device" in yaml, under which we place binary_sensors, sensors, switches, ... If you then look in Settings - Devices, it only lists the sensors as entities, but does not list the "main" device. It would be cumbersome to have some correction of this. My config looks like this:

  - name: KEBAP30
    delay: 5
    timeout: 5
    type: tcp
    host: 192.168.1.102 # your callbox IP address goes here
    port: 502
    sensors:
      # Lesbare Sensoren
      - name: KebaP30_charging_state
        address: 1000
        scan_interval: 30
        data_type: uint32
        unique_id: KebaP30_charging_state
      - name: KebaP30_cable_state
        address: 1004
        scan_interval: 30
        data_type: uint32
        unique_id: KebaP30_cable_state

I would expect to see

  • Device = KebaP30
    • Sensor: sensor.KebaP30_charging_state
    • Sensor: sensor.KebaP30_cable_state

I cannot fix this myself, but hope that you'll help the community and me. Many thanks.

What version of Home Assistant Core has the issue?

core-2024.10.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Modbus

Link to integration documentation on our website

https://www.home-assistant.io/integrations/modbus

Diagnostics information

No response

Example YAML snippet

- name: KEBAP30
    delay: 5
    timeout: 5
    type: tcp
    host: 192.168.1.102 # your callbox IP address goes here
    port: 502
    sensors:
      # Lesbare Sensoren
      - name: KebaP30_charging_state
        address: 1000
        scan_interval: 30
        data_type: uint32
        unique_id: KebaP30_charging_state
      - name: KebaP30_cable_state
        address: 1004
        scan_interval: 30
        data_type: uint32
        unique_id: KebaP30_cable_state

Anything in the logs that might be useful for us?

No response

Additional information

No response

rschoell avatar Oct 17 '24 07:10 rschoell

I'm missing that too. Implementation shouldn't be to hard though, here's some example code:

def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the sensor platform."""
    # Register both sensor entities under the same device
    add_entities([MyTemperatureSensor(hass)])

class MyTemperatureSensor(SensorEntity):
    """Representation of a Temperature Sensor."""
    
    @property
    def device_info(self):
        return DeviceInfo(
            identifiers={(self.__class__.__name__, "my_sensor_device")},
            name="My Custom Sensor Device",
            manufacturer="Custom Manufacturer",
            model="Custom Sensor Model 1.0",
        )

dkrebs avatar Oct 17 '24 08:10 dkrebs

This is a huge problem! Dealing with each sensor as entity rather than device is cumbersome and requires a lot of work. Each modbus slave should be represented as a device in homeassistant.

Gibol avatar Oct 21 '24 09:10 Gibol

A connection point is not a device. You could have multiple devices into the same connection point when you use a serial link instead of TCP. So the connection point is not the matter, but instead it could be grouping into a device the entities belonging to same slave.

crug80 avatar Oct 22 '24 10:10 crug80

Either way, if that wouldn't be possible, it would be ideal to follow the method of being able to join entities to a self defined device, like it's done in MQTT integration.

rschoell avatar Oct 24 '24 08:10 rschoell

Afaik devices only work for config flow based integrations

joostlek avatar Oct 24 '24 09:10 joostlek

In MQTT you have the device: entry for "collecting" entities into a device. a similar config in mqtt would look like this:

- name: "APS ECU Energy lifetime"
  unique_id: aps.ecuenergylifetime
  state_topic: "APsystems/aps/216300065811/energy/lifetime" # total amount of energy (in kWh) generated from the lifetime of the array
  device_class: energy
  unit_of_measurement: "kWh"
  device:
    manufacturer: "AP Systems"
    model: "DS3-S"
    identifiers:           
      - aps_ds3_s

rschoell avatar Oct 24 '24 12:10 rschoell

Yes, but you still have a config entry set up for the connection config

joostlek avatar Oct 24 '24 12:10 joostlek

It really is necessary. I have over 200 entities and it is very inconvenient without grouping them into devices.

Laxilef avatar Oct 24 '24 18:10 Laxilef

Same here. We need this or another useful solution. Having 190 ungrouped entities is a pain ...

phil11c avatar Nov 20 '24 17:11 phil11c

Is there any update, when this could eventually be picked up?

rschoell avatar Dec 05 '24 09:12 rschoell

pushing this as I'm struggling with the same problem..

DerAutomatiker avatar Dec 19 '24 19:12 DerAutomatiker

I'd greatly appreceate this, too.

cgfm avatar Dec 27 '24 16:12 cgfm

I currently have 459 entities and it is very inconvenient without grouping them into devices. I have approximately 30 devices. I have created separate configuration files for each device to make it at least a little clearer.

msmitka avatar Jan 09 '25 10:01 msmitka

The solution for today is to use device tools from hacs to grouping entities into devices.

Laxilef avatar Jan 09 '25 14:01 Laxilef

immagine Considering the disclaimer, I don't think it would be a great idea, imho.

crug80 avatar Jan 09 '25 15:01 crug80

Considering the disclaimer, I don't think it would be a great idea, imho.

This is true, but this is the only working method until there is native support for grouping modbus entities into devices.

Laxilef avatar Jan 09 '25 19:01 Laxilef

Adding my support to this feature request. Just added a Systemair unit with lots of entities. It's very messy not being able to group them under a device.

agjell avatar Jan 13 '25 01:01 agjell

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Still open.

DerAutomatiker avatar Apr 13 '25 05:04 DerAutomatiker

Image please¡¡¡

zocima avatar May 05 '25 17:05 zocima

+1, really missing

L1brTy avatar May 26 '25 10:05 L1brTy

Urgently need it. It's a mess to have all my inverter data ungrouped.

maxxberg avatar Jun 02 '25 13:06 maxxberg

Please add device grouping. It will be a helpful feature!

taskforce88 avatar Jun 12 '25 05:06 taskforce88

+1 for this feature

Bascht74 avatar Jun 19 '25 22:06 Bascht74

+1

fapgomes avatar Jul 20 '25 10:07 fapgomes

I can surely see the need for make the connection a device, especially this would potentially open the possibility to show connection status and disconnect/reconnect on demand.

However have a device pr connection is not enough, and would not help a lot of users...since many only have a single device.

What is needed is a device pr connection and a sub-device pr device-id (physical device).

I have been working on this idea for a while, but sadly enough it is quite hard to do, without rewrapping the yaml...which I am sure a lot of user would dislike. It is on my list for a future update.

janiversen avatar Aug 12 '25 18:08 janiversen

@janiversen thanks for taking care of this request, even though it'll be somewhen in the future. In all honesty, even though having a number of subdevices currently, I wouldn't mind rewriting the Yaml file, if I needed to but would have a better view in the end. I much appreciate you taking this over and look forward to your implementation ongoing.

rschoell avatar Aug 13 '25 07:08 rschoell

I also post my support for this feature. I have 250 modbus entities now and another 200 will come in next weeks. Having to deal with raw entities only (without grouping per device and area) is a pain.

ESPHome solved that: https://github.com/esphome/esphome/pull/8544

KrzysztofHajdamowicz avatar Aug 14 '25 10:08 KrzysztofHajdamowicz

+1

isi07 avatar Aug 17 '25 11:08 isi07