How to dim Bedside lamp with Xiaomi button?

Here’s my configuration:

configuration.yaml:

input_boolean:
  light1_dim:
    name: Light1 Dim
    initial: off

automations.yaml:

- alias: Light1 brighten on
  id: '1511197874722'
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001a5d08e
      click_type: long_click_press
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.light1_dim
      state: 'off'
    - condition: state
      entity_id: light.light1
      state: 'on'
  action:
  - service: script.turn_on
    entity_id: script.1511118763251
- alias: Light1 brighten off - bool on
  id: '1511197874733'
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: binary_sensor.switch_158d0001a5d08e
    from: 'on'
    to: 'off'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.light1_dim
      state: 'off'
    - condition: state
      entity_id: light.light1
      state: 'on'
  action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.light1_dim
- alias: Light1 dim on
  id: '1511197874724'
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001a5d08e
      click_type: long_click_press
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.light1_dim
      state: 'on'
    - condition: state
      entity_id: light.light1
      state: 'on'
  action:
  - service: script.turn_on
    entity_id: script.1511119598248
- alias: Light1 brighten off - bool off
  id: '1511197876722'
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: binary_sensor.switch_158d0001a5d08e
    from: 'on'
    to: 'off'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.light1_dim
      state: 'on'
    - condition: state
      entity_id: light.light1
      state: 'on'
  action:
  - service: input_boolean.turn_off
    entity_id: input_boolean.light1_dim

scripts.yaml:

'1511119598248':
  alias: dim_light1
  sequence:
  - condition: state
    entity_id: input_boolean.light1_dim
    state: 'on'
  - service: light.turn_on
    entity_id: light.light1
    data_template:
      brightness: '{{states.light.light1.attributes.brightness - 10}}'
  - service: script.turn_off
    entity_id: script.1511119598248
  - service: script.turn_on
    entity_id: script.1511119598248
'1511118763251':
  alias: brighten_light1
  sequence:
  - condition: state
    entity_id: input_boolean.light1_dim
    state: 'off'
  - service: light.turn_on
    entity_id: light.light1
    data_template:
      brightness: '{{states.light.light1.attributes.brightness + 10}}'
  - service: script.turn_off
    entity_id: script.1511118763251
  - service: script.turn_on
    entity_id: script.1511118763251

You can also apply this set of scripts/automations to rise or lower the Volume of a TV (with a Broadlink IR Emitter for example) with the Xiaomi Switches.