MODBUS Connection with Sensor Listing to diffrent MODBUS connections

The Feature Request below is to allow modification of the Sensor: [List] arguments/parameter. The intent is to allow a specified sensor to be tied to a specified named connection, when combined into a single sensor.yaml configuration file. The MODBUS named connection is defined in MODBUS, but not in the Sensor: “as a valid option”. There are many ways to enable this feature, this is just but one, perhaps allowing all modbus config under the [-platform: Modbus] ?

[HubName] Example below:

#modbus.yaml config file

  • modbus:
  • name: hub123
  • type: tcp
  • host: 192.168.1.164
  • port: 502
  • delay: 2
  • timeout: 15

#/sensor/sensor.yaml config file

Requested Feature:

  • name: “0 - MPPT100/600 100/600 Device State”
  • unique_id: d1b7829a-d3bf-4d7f-93b3-6dbf07c3da05
  • HubName: hub123
  • data_type: uint16
  • input_type: input
  • slave: 170
  • address: 64
  • scan_interval: 1

Without this feature request/modification you have to list each sensor and MODBUS into one #.yaml file when your sensors list, connects to multiple MODBUS TCP Named Connections.


Discussion of the issue:

I have been researching what I would like to do, and have decided that I can not split my configuration the way I would like, and I am unable to make my configuration more modular, and therefore more manageable:

Example:
#MODBUS connection yaml file with defined connections:


modbus:
  - name: Victron_GX
    type: tcp
    host: 192.168.1.164
    port: 502
    delay: 2
    timeout: 15
    sensors:
      - name: "Victron Battery State Of Charge"
        unit_of_measurement: "%"
        slave: 224
        address: 266
        data_type: uint16
        scale: 0.1
        precision: 1
        device_class: power

      - name: "Victron Battery current"
        unique_id: 8529994b-63a2-4f4d-b008-d3fc76c36ba7
        unit_of_measurement: "A"
        slave: 224
        address: 841
        data_type: int16
        scale: 0.1
        precision: 0
        device_class: current

---------------------------------snip---------------------

  - name: EG4_Internal_BMS
    type: tcp
    host: 192.168.1.179
    port: 502
    delay: 2
    timeout: 15
    sensors:
      - name: "EG4 Internal BMS - Battery SOC"
        unique_id: d190cd3a-90c9-4a2c-8edc-3d71bce8604f
        data_type: uint16
        unit_of_measurement: V
        scale: 1
        precision: 2
        slave: 230
        address: 40081
        scan_interval: 15

      - name: "EG4 Internal BMS - Battery Current"
        unique_id: 33aa654a-b639-4adc-97fa-ceea9444453a
        data_type: int16
        unit_of_measurement: A
        scale: 0.01
        precision: 2
        slave: 230
        address: 40114
        scan_interval: 1
---------------------------------snip---------------------

  - name: Conext_Gateway
    type: tcp
    host: 192.168.1.179
    port: 503
    delay: 2
    timeout: 15
    sensors:
      - name: "0 - XW 4868 Inverter Enabled"
        unique_id: e71bdc4d-fbb1-483a-a864-521747ebc3dc
        data_type: uint16
        input_type: input
        slave: 10
        address: 71
        scan_interval: 1

      - name: "0 - XW 4868 Active Faults Flag"
        unique_id: cb59ac1b-89e5-4fbe-9657-296ff6a7391f
        data_type: uint16
        input_type: input
        slave: 10
        address: 75
        scan_interval: 1
---------------------------------snip---------------------

Example:
#MODBUS connection yaml file with sensors pushed to a full list, all yaml files located in dir /sensor will be combined in a single list, under sensor:

modbus:
  - name: Victron_GX
    type: tcp
    host: 192.168.1.164
    port: 502
    delay: 2
    timeout: 15

  - name: EG4_Internal_BMS
    type: tcp
    host: 192.168.1.179
    port: 502
    delay: 2
    timeout: 15

  - name: Conext_Gateway
    type: tcp
    host: 192.168.1.179
    port: 503
    delay: 2
    timeout: 15

sensor: !include_dir_merge_list sensors/

List are then combined - The lists are separate sensor lists, which are combined by:

  • sensor: !include_dir_merge_list sensors/

#example system topography for my yaml configs for each separate device:

4868sensor.yaml ======> uses Conext_Gateway connection
mpptsensor.yaml ======> uses Conext_Gateway connection
victron.yaml =========> uses Victron_GX connection
eg4battery.yaml=======> uses EG4_internal_BMS connection

The sensor listing compiled by "sensor: !include_dir_merge_list sensors/ ", will then create a single list of each sensor. However, since the connection name is not defined in the “Sensor: [arguments]”, the sensor is not aware of which connection name/hub to connect to when using multiple named connections. This is the case with: !include_dir_merge_list sensors/.

This is how I would imagine the effect of what I have discussed:

#mpptsensor.yaml

- platform: modbus
  sensors:
    - name: "0 - MPPT100/600 100/600 Device State"
      unique_id: d1b7829a-d3bf-4d7f-93b3-6dbf07c3da05
      hubname: Conext_Gateway
      data_type: uint16
      input_type: input
      slave: 170
      address: 64
      scan_interval: 1
#eg4battery.yaml

- platform: modbus
  sensors:
    - name: "EG4 Internal BMS - Battery SOC"
      unique_id: d190cd3a-90c9-4a2c-8edc-3d71bce8604f
      hubname: EG4_Internal_BMS
      data_type: uint16
      unit_of_measurement: V
      scale: 1
      precision: 2
      slave: 230
      address: 40081
      scan_interval: 15

Below is another way to affect his outcome, by implementing Hub: for the platform of MODBUS:

#mpptsensor.yaml

- platform: modbus
  hub: Conext_Gateway
  sensors:
    - name: "0 - MPPT100/600 100/600 Device State"
      unique_id: d1b7829a-d3bf-4d7f-93b3-6dbf07c3da05
      data_type: uint16
      input_type: input
      slave: 170
      address: 64
      scan_interval: 1
#eg4battery.yaml

- platform: modbus
  hub: EG4_Internal_BMS
  sensors:
    - name: "EG4 Internal BMS - Battery SOC"
      unique_id: d190cd3a-90c9-4a2c-8edc-3d71bce8604f
      data_type: uint16
      unit_of_measurement: V
      scale: 1
      precision: 2
      slave: 230
      address: 40081
      scan_interval: 15

so on, and on…