Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Modbus Devices for each listed connection point in Modbus configuration #128554

Open
rschoell opened this issue Oct 17, 2024 · 17 comments
Open

Comments

@rschoell
Copy link

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

@home-assistant
Copy link

@dkrebs
Copy link

dkrebs commented Oct 17, 2024

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",
        )

@Gibol
Copy link

Gibol commented Oct 21, 2024

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.

@crug80
Copy link
Contributor

crug80 commented Oct 22, 2024

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.

@rschoell
Copy link
Author

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.

@joostlek
Copy link
Member

Afaik devices only work for config flow based integrations

@rschoell
Copy link
Author

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

@joostlek
Copy link
Member

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

@Laxilef
Copy link

Laxilef commented Oct 24, 2024

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

@phil11c
Copy link

phil11c commented Nov 20, 2024

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

@rschoell
Copy link
Author

rschoell commented Dec 5, 2024

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

@DerAutomatiker
Copy link

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

@cgfm
Copy link

cgfm commented Dec 27, 2024

I'd greatly appreceate this, too.

@msmitka
Copy link

msmitka commented Jan 9, 2025

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.

@Laxilef
Copy link

Laxilef commented Jan 9, 2025

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

@crug80
Copy link
Contributor

crug80 commented Jan 9, 2025

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

@Laxilef
Copy link

Laxilef commented Jan 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants