How to add this modbus sensor to yaml

I have a modbus device with address 26 that shows the temperature, here are its data types on the screenshot, I can’t understand how to write all this in yaml correctly.

I write this

modbus:
  - name: modbus_hub
    type: tcp
    host: 192.168.0.15
    port: 502
    sensors:
      - name: sensor1
        address: 26

how to correctly specify the type, address, etc. ?
there are two temperature sensors at address 26, they must be separated, please show me an example.

image

???

Maybe this:

modbus:
  - name: modbus_hub
    type: tcp
    host: 192.168.0.15
    port: 502
    sensors:
      - name: sensor1
        address: 8
        input_type: input
        data_type: float16  # or maybe int16
        swap: byte # for little endian. Modbus is usually big endian, yours is not, see below

image

26 it is device ID
image

and 8 is address of register if I understand correctly

Then you need:

not 26.

You also need this:

Because the default input type for a sensor is “holding”

brave_screenshot_www.home-assistant.io

image

1 Like

Well, where to write 26 ? I understand that without it it is not clear from which device to read data, with address 8 I have many other devices.

Ah ok, then try this:

modbus:
  - name: modbus_hub
    type: tcp
    host: 192.168.0.15
    port: 502
    sensors:
      - name: sensor1
        slave: 26 # <- Device address
        address: 8 # <- Register address
        input_type: input
        data_type: float16  # or maybe int16
        swap: byte # for little endian. Modbus is usually big endian, yours is not, see below

You can also use device_address: instead of slave: if you don’t like that word.

I can’t link directly to this in the documentation because it has the same relative url as another section but it is there at the top of the entities configuration section, it applies to all entities:

1 Like

I started to get values from the sensor, it’s temperature in Celsius, but it’s not right

When the type int16 outputs the value -16639
When type float16 outputs -1.25
The correct value should be about 27.9.

I have a modifier in iridium that converts the value

function modify_m1w2 (in_Type, in_Name, in_Value)
{
   in_Value *= 0.0625;
   return in_Value;
}

that is just multiplying by 0.0625;
but I don’t understand how this can be applied in a yaml file ?

First try int16 and float16 without the line swap: byte

Then if that does not look any better you can use these options:

This will fit a linear calibration of the form y = mx + c

1 Like

please give me an example in yaml, I dont understed how to use offset or scale

modbus:
  - name: modbus_hub
    type: tcp
    host: 192.168.0.15
    port: 502
    sensors:
      - name: sensor1
        slave: 26 # <- Device address
        address: 8 # <- Register address
        input_type: input
        data_type: int16  # or maybe int16
        scale: 0.0625

Work only like that I received 28 but real value was 27.812500
how to get at least double decimal precision ?

First of all you have only calibrated at one point. That may not be enough.

You need to make a list of at least three sets of these value pairs (widely spaced apart in actual value if possible):

Reported by modbus, Actual value.

Then I’ll work out the linear equation for you.

I’m sorry, but I’m not quite sure what I’m supposed to do.

And I also have this modifier for other modbus metrics.

function modify_Kitchen_P (in_Type, in_Name, in_Value)
{
  in_Value = (in_Value-830)/37.5;
   if (in_Value > 100)
    {
        in_Value = 100;
    }
    
   if (in_Value < 0)
    {
        in_Value = 0;
    }    
   return in_Value.toFixed();
}

so here the value must be subtracted, divided and there is a condition, can this be realized in home assistant ?
I just need to call the function

Just tell me three of these number pairs.

28 27.875000
11 10.687500
2048 2047.937500

Is this with your scaling factor?

Looks like you don’t need an offset.

This is the option you need to set for more decimals:

image

1 Like

precision: 2
works! thanks!

but what about this function How to add this modbus sensor to yaml - #12 by mill7
it can be prescribed to change the incoming value ?

Yes you can do that with the offset and scale. the limits can be set with the min and max value options.

I need to apply the formula in_Value = (in_Value-830)*0.026666 to the value from the modbus sensor; that is, first do the subtraction and then the multiplication, using offset: -830 and scale: 0.026666 on the docks, multiplication occurs first, and then subtraction, can this be changed somehow ?

Expanding your equation:


(in_Value-830)*0.026666  

= in_Value*0.026666 - 830*0.06666
= in_Value*0.026666 - 22.13278

Therefore use scale = 0.026666 and offset = -22.13278

1 Like

I have the same problem! When the sensor is connected, the readings differ from the real ones.
The SHT20 sensor reads both temperature and humidity. If I read only one value (either temperature or humidity), then the readings are correct, but if I read both, then the temperature is too low and the humidity is too high!

Снимок

I understand that you can write a correction, but:

  1. this is not correct - after entering the coefficient, I try to breathe into the sensor and it shows me a temperature of 70°C;
  2. when connecting any one sensor, the readings are correct, which means it can work without corrections!
    my code:
sensors:
  - name: 'Температура'
    scan_interval: 5
    slave: 1
    scale: 0.01
    address: 1
    data_type: int16
    input_type: input
    unit_of_measurement: °C
    device_class: temperature
    state_class: measurement
    precision: 2

  - name: 'Влажность'
    scan_interval: 5
    slave: 1
    scale: 0.01
    address: 2
    data_type: int16
    input_type: input
    unit_of_measurement: '%'
    device_class: humidity
    state_class: measurement
    precision: 2