ModBus: Read Value

Hi all,
i’m replacing a broken ilon e3 with home-assistant. I need to read (and after write but it’s another story… ) some data via a serial rs485/modbus.

I connect to raspberry via a usb/serial converter that raspberry saw as ttyUSB0

I set this config but i have no reply message

2018-05-28 09:05:00 ERROR (SyncWorker_8) [homeassistant.components.sensor.modbus] No response from modbus slave 2, register 512

modbus:
      type: serial
      method: rtu
      port: /dev/ttyUSB0
      baudrate: 9600
      stopbits: 1
      bytesize: 8
      parity: N

sensor:
  platform: modbus
  registers:
    - name: Sensor1
      unit_of_measurement: °C
      slave: 2
      register: 512
      count: 2

Tonight i will check cables!!!
I upload some printscreen about how it was set on ilon

Thanks
is it correct?

ok , i made some step ahead!!!

I’m able to read the value and display to HA with code:

- name: Sensor3
  unit_of_measurement: °C
  slave: 4
  register: 514
  count: 1

The problem is that value that i receive is a value without comma (for example i see 215 that mean 21.5 °C) so i change the code to

- name: Sensor3
  unit_of_measurement: °C
  slave: 4
  register: 514
  count: 1
  scale: 0.1
  data_type: float

but the result is that I have 0 as result instead 21.5
If I remove data_type i see 21 without the value after comma

Where is the error?

Thanks

ok, found the error too

- name: Sensor3
  unit_of_measurement: °C
  slave: 4
  register: 514
  count: 1
  precision: 1
  scale: 0.1

Next question is:
I have a digital value that is 1 if a pump is runnig, 0 if not. Is it possible to display ON or OFF instead 1/0 ?

Use Modbus Binary Sensor instead of Modbus Sensor:


Or maybe not! :slight_smile: I haven’t used these and just figured it would be like other components that have both sensor and binary_sensor options.

If that doesn’t work for you then you could make a Template Binary Sensor out of your Modbus Sensor:

no luck with binary, it report always OFF

Could you expand on that? E.g., what does the configuration for this sensor (that shows 1 & 0) look like, and what binary configuration did you try?

If you have a sensor (any sensor) whose state is always shown as 1 or 0, you can make a binary sensor from it by doing something like this:

binary_sensor:
  - platform: template
    sensors:
      bin_sens:
        value_template: "{{ is_state('sensor.zero_one_sens', '1') }}"

So if sensor.zero_one_sens is showing 1, then binary_sensor.bin_sens willl show on, and if sensor.zero_one_sens is showing 0, then binary_sensor.bin_sens will show off.

thanks,
i resolve the issue using template as you suggest (I stayed on sensor instead binary_sensor but it’s the same), and now it works like a charm

sensor:
  - platform: template
    sensors:
#PDC    
      compressorepdc2:
        friendly_name: "Compressore"
        value_template: >-
          {% if is_state('sensor.compressorepdc', '1') %}
            ON
          {% else %}
            OFF
          {% endif %}
        icon_template: >-
          {% if is_state('sensor.compressorepdc', '1') %}
            mdi:power-plug
          {% else %}
            mdi:power-plug-off
          {% endif %}

I’m using RTUoverTCP (modbus component) and I have some problem with reading data.
In general when HA try to read temperature is not able to do that, but when I start reading temperature outside (external software) it gets right data. I have no idea what is happening :frowning_face:

To check if I made all OK I have made switch. And with switch I do not have any problem. I can On/Off without any problems. So looks connection is OK.

Below is my code:

modbus:
  name: RS485
  type: rtuovertcp
  host: 192.168.0.7
  port: 1234

switch:
  platform: modbus
  registers:
    - name: Switch2
      hub: RS485
      slave: 1
      register: 0
      command_on: 1
      command_off: 0

sensor:
  platform: modbus
  scan_interval: 30
  registers:
    - name: CzujnikTest
      hub: RS485
      slave: 1
      register: 1
      unit_of_measurement: °C
      count: 1
      precision: 1
      scale: 0.1
      offset: 0
      data_type: integer

Did you ever got this solved?
I’m having a similar situation, the documentation for me is too confusing.

  data_type: uint