Modbus. Need help from experts

Here is an answer from BMS support:

so just send 00 00 00 00 00 06 01 03 11 00 00 2D to read system running information

the id should be 0x01

start register 0x1100

1101 is char/dischg status
** you read from 1100 to 112C**

here is log from modbus test tool:

[12:07:28.099]OUTˇúˇó00 00 00 00 00 06 01 03 11 00 00 2D ˇő
[12:07:28.099]INˇűˇô00 00 00 00 00 5D 01 03 5A 09 D4 00 11 AA AA 00 0F 00 00 01 11 FF B2 00 54 00 64 00 19 00 01 00 01 00 17 00 03 00 07 0F 62 00 02 00 02 0F 29 00 01 00 02 00 00 00 00 00 DF 00 0F 00 00 00 0F 00 00 00 0F 00 00 00 00 00 00 00 0E 09 46 00 00 09 2F 00 00 00 19 00 2A 02 36 00 00 00 14 00 00 00 08 00 2A 
[12:07:42.679]OUTˇúˇó00 00 00 00 00 06 01 03 11 00 00 2D ˇő
[12:07:42.695]INˇűˇô00 00 00 00 00 5D 01 03 5A 09 D6 00 11 AA AA 00 0F 00 00 01 11 FF 71 00 54 00 64 00 19 00 01 00 01 00 17 00 03 00 07 0F 65 00 03 00 06 0F 2B 00 01 00 02 00 00 00 00 00 DF 00 0F 00 00 00 0F 00 00 00 0F 00 00 00 00 00 00 00 0E 09 46 00 00 09 2F 00 00 00 19 00 2A 02 36 00 00 00 14 00 00 00 08 00 2A 
[12:07:42.848]OUTˇúˇó00 00 00 00 00 06 01 03 11 00 00 2D ˇő
[12:07:42.864]INˇűˇô00 00 00 00 00 5D 01 03 5A 09 D6 00 11 AA AA 00 0F 00 00 01 11 FF 6E 00 54 00 64 00 19 00 01 00 01 00 17 00 03 00 07 0F 65 00 03 00 06 0F 2B 00 01 00 02 00 00 00 00 00 DF 00 0F 00 00 00 0F 00 00 00 0F 00 00 00 00 00 00 00 0E 09 46 00 00 09 2F 00 00 00 19 00 2A 02 36 00 00 00 14 00 00 00 08 00 2A

so how to config HA to reach the same?

OH!

now I used:

    - name: "Test 1101 status"
      slave: 1
      address: 4353
      input_type: holding
      count: 1
      data_type: uint16

and it returns (into HA) number 17 it means 0x0011 in HEX which means it is CHARGING (descibed in the PDF). How can I translate this into “charging” state in HA?

Thank you

###  templates

template:
#2
  - sensor:
###4
    - name: "Battery Status"
      unique_id: battery_status
      state: >
        {% set x = states('sensor.test_1101_status')|int(0) %}
        {% if x == "17" %}
          {{ "Charge" }}
        {% elif x == "2222" %}
          {{ "discharge" }}
        {% elif x == "33333" %}
          {{ "ssssss" }}
        {% else %}
          {{ "error" }}
        {% endif %}

Thank you very much. But I think there should be no % symbol?

BMS return just three states: 17 or 34 or 51.

17=charging, 34=discharging, 51=stand by

Jinja2 templates language

Try in HA > Dev Tools

Hm, still shows only “error” status.

sensor is configured this way:

    - name: "Test 1101 status"
      slave: 1
      address: 4353
      input_type: holding
      count: 1

it returns value 17 (mostly), also 34 and 51. It means charge, discharge, standby. Value 17 is translated from 0x0011 hexadecimal.

template is configured as:

    - name: "Battery Status"
      unique_id: battery_status
      state: >
        {% set x = states('sensor.test_1101_status')|int(0) %}
        {% if x == "17" %}
          {{ "Charging" }}
        {% elif x == "34" %}
          {{ "Discharging" }}
        {% elif x == "51" %}
          {{ "StandBy" }}
        {% else %}
          {{ "error" }}
        {% endif %}

But the result of template shows error only. Maybe I should read 17 value in HEX by template? I tried 0x0011 but without success. Test 1101 status sensor output which I see in HA is just 17.

Any idea where could be problem?

    - name: "Battery Status"
      unique_id: battery_status
      state: >
        {% set x = states('sensor.test_1101_status')|int(0) %}
        {% if x == 17 %}
          {{ "Charging" }}
        {% elif x == 34 %}
          {{ "Discharging" }}
        {% elif x == 51 %}
          {{ "StandBy" }}
        {% else %}
          {{ "error" }}
        {% endif %}
1 Like

Bro @nikito7 you are God!

1 Like

Hello, please could someone help me with this error?
The system cannot restart because the configuration is not valid: Invalid config for [modbus]: extra keys not allowed @ data['modbus'][0]['host']. Got '192.168.10.10' extra keys not allowed @ data['modbus'][0]['scan_interval']. Got 10 not a valid value for dictionary value @ data['modbus'][0]['type']. Got 'tcp' required key not provided @ data['modbus'][0]['baudrate']. Got None required key not provided @ data['modbus'][0]['bytesize']. Got None required key not provided @ data['modbus'][0]['method']. Got None required key not provided @ data['modbus'][0]['parity']. Got None required key not provided @ data['modbus'][0]['stopbits']. Got None. (See /config/configuration.yaml, line 79).

modbus.yaml is:

- name: BMS
  type: tcp
  host: 192.168.10.10
  port: 502 #your port number
  scan_interval: 10
  sensors:
    - name: "bms_soc"
      slave: 1
      address: 11 # 0x2012
      input_type: holding
      data_type: uint16
    - name: "bms_daily_delivered_pw"
      slave: 1
      address: 0020 # 0x2012
      input_type: holding
      data_type: uint16
      count: 1
      precision: 1
      scale: 0.1
    - name: "bms_status"
      slave: 1
      address: 1 # 0x2012
      input_type: holding
      data_type: uint16

Comment #modbus: in modbus.yaml

There is no “modbus” word in modbus.yaml file
“modbus” word is only in configuration.yaml as modbus: !include modbus.yaml

Seems like something inside HASS regarding to modbus is corrupted. I updated to newest supervisor/hass but without success. Even if I set modbus TCP the error seems like it wants SERIAL configuration (baudrate, bytesize etc.). Just seems like there is some cache or something somewhere that prevents modbus service to read actual config…? It worked before (3 days ago) and I think I didn´t change anything.

I found it. scan_interval: 10 was wrong. It should by on “sensors” part.

1 Like

Anyway could you help me @nikito7 with this?
I have register (R) described as:

Holding address:40011
Format: Word
Unit: % 
Data type:float 
Value range:0.0 - 100.0; Ref = value/10 (Rounded)

and register (R/W)

Address:40102 
Format: Word
Data type: Int 
Request: 1 = Manual, 2 = Auto P, 3 = Auto Q, 4 = Auto PQ

This last register would I like to use as a switch and automation.

How should look config in HASS? Thank you.

float16

Services

You could try in Dev Tools > Services

Search for modbus

Thank you for suggestion. But regarding the first register - it is not my config, it is from manufacturer table. How should look hass config for such register?
And regarding modbus service - how should look command?
Thank you.

Just change uint16 to float16

Address 11 maybe

If it was a simple on off

Service

I never used it

# Example configuration.yaml entry
modbus:
  - type: tcp
    host: IP_ADDRESS
    port: 502
    switches:
      - name: Register1
        address: 11
        command_on: 1
        command_off: 0
        verify:
            input_type: holding
            address: 127
            state_on: 25
            state_off: 1