Carlo Gavazzi Dupline Smart Light to Modbus

Hi,

I have a Carlo Gavazzi SH2WEB24 and with ShTool I can use the Modbus integration to Home Assistant. I got a light which is dimmable with the following commands:
0: Turns off the light
1: Turns on the light
2: Change the dimming to 20%
3: Change the dimming to 40%
4: Change the dimming to 80%
9: Change the dimming to 100%

So with the code under I get 5 entities with which I can control the dimming. However I would like to use a slider to change between the commands. I think I should use “modbus.write_register” somehow, but I don’t understand how. Any tips?

      - name: "Kontor - Taklys"
        address: 1182
        slave: 1
        write_type: holding
        scan_interval: 1
        command_on: 1
        command_off: 0
        verify:
          input_type: holding
          address: 1182
      - name: "Kontor - Taklys2"
        address: 1182
        slave: 1
        write_type: holding
        scan_interval: 1
        command_on: 2
        command_off: 0
        verify:
          input_type: holding
          address: 1182
      - name: "Kontor - Taklys3"
        address: 1182
        slave: 1
        write_type: holding
        scan_interval: 1
        command_on: 3
        command_off: 0
        verify:
          input_type: holding
          address: 1182
      - name: "Kontor - Taklys4"
        address: 1182
        slave: 1
        write_type: holding
        scan_interval: 1
        command_on: 4
        command_off: 0
        verify:
          input_type: holding
          address: 1182
      - name: "Kontor - Taklys5"
        address: 1182
        slave: 1
        write_type: holding
        scan_interval: 1
        command_on: 9
        command_off: 0
        verify:
          input_type: holding
          address: 1182

Hi,

Here’s what I have for my SH2WEB24. Been using this for a few months now. No problems.

modbus:
  - name: SmartHouse
    type: tcp
    host: 192.168.0.120
    port: 502
    sensors:
      - name: "sensor_loftstuetrapp"
        address: 350
        slave: 1
        data_type: uint16
        input_type: holding
        scan_interval: 5

- platform: template
  lights:
    template_loftstuetrapp:
      friendly_name: "Loftstue - Trapp"
      level_template: >
        {% set brightness = (((states('sensor.sensor_loftstuetrapp')|float)*17)/6)-(85/3) %}
        {% if brightness < 0 %}
          0
        {% elif brightness > 255 %}
          255
        {% else %}
          {{ brightness }}
        {% endif %}
      value_template: "{{ states('sensor.sensor_loftstuetrapp')|int > 0 }}"
      turn_off:
        service: modbus.write_register
        data_template:
          hub: SmartHouse
          unit: 1
          address: 350
          value: 0
      turn_on:
        service: modbus.write_register
        data_template:
          hub: SmartHouse
          unit: 1
          address: 350
          value: 1
      set_level:
        service: modbus.write_register
        data_template:
          hub: SmartHouse
          unit: 1
          address: 350
          value: "{{ (brightness/255)*90+10 }}"