OVEN MK110 (ОВЕН) MODBUS RTU integration

Hi there!

I was fighting with the device in subject and finally found the way how to work with it in HA.
Probably this article require Russian translation as far as this device is well known withing CIS region.

So… to read registers of OVEN MK110 or any similar OVEN device you need a RS485 USB converter. Previously I spent a lot of time figuring out why system did not work. The reason was incorrect driver support in Hassio for russian converter. I got other from AliExpress for $2.Once I got Chinese dongle everything went fine.

My device setup in configuration.yaml:

modbus:
  name: oven110
  type: serial
  method: rtu
  port: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
  baudrate: 9600
  stopbits: 1
  bytesize: 8
  parity: N

port: value may be found in Hass.io/System/Hardware menu page.

Then you may set up a sensor to read Inputs of the device. Values are stored in 51 register:

sensor:
- platform: modbus
  registers:
    - name: InputsState
      hub: oven110
      slave: 16
      register: 51
      count: 1

The value received should be parsed by bits, so I set up binary sensors for that and parsed InputsState value:

binary_sensor:
  - platform: template
    sensors:
      power_failure:
        friendly_name: "Сетевое питание"
        value_template: "{{ states('sensor.InputsState')|int|bitwise_and(1) > 0 }}"
      accum_failure:
        friendly_name: "Аккумулятор"
        value_template: "{{ states('sensor.InputsState')|int|bitwise_and(2) > 0 }}"
      switch1:
        friendly_name: "Cигнализация"
        value_template: "{{ states('sensor.InputsState')|int|bitwise_and(4) > 0 }}"
      switch2:
        friendly_name: "Вода"
        value_template: "{{ states('sensor.InputsState')|int|bitwise_and(8) > 0 }}"
      smoke_detector:
        friendly_name: "Задымление!"
        value_template: "{{ states('sensor.InputsState')|int|bitwise_and(16) > 0 }}"
      motion_sensor:
        friendly_name: "Движение"
        value_template: "{{ states('sensor.InputsState')|int|bitwise_and(32) > 0 }}"
      hydro_lock:
        friendly_name: "Датчик протечки"
        value_template: "{{ states('sensor.InputsState')|int|bitwise_and(64) > 0 }}"

To change outputs state you need to write registers using modbus function 16. And this took time to figure out how it can be done in HA. Finally I found that HA uses this function if value provided for writing is an array.

For writing registers I use automation where first value in the array is what I want to write, the second is dummy just to call function 16:

- alias: Water ON
  trigger:
    - platform: state
      entity_id: binary_sensor.switch2
      from: 'on'
      to: 'off'
  action:
  - service: modbus.write_register
    data:
      hub: oven110
      unit: 16
      address: 0000
      value: [0,0]
  - service: notify.telegram_id1
    data:
      message: "*Water should be ON.*"

Register 0000 is linked to Digital Output #1. Maximum value in output registers: 1000
Full set of registers and its functions are described in the documentation.