Using template to controll dimmer

I recently bought a aqara cube. I want to use the cube to set a dimmer to a brighter level when I move it. I believe I need a template to do that, since I need to get the current brightness level and make it higher.

I created this automation for it:

- alias: cube dimmer woonkamer feller
  trigger:
    platform: event
    event_type: xiaomi_aqara.cube_action
    event_data:
      entity_id: binary_sensor.cube_woonkamer
      action_type: move
  action:
    - service: homeassistant.turn_on
      entity_id: light.dimmerwoonkamer_level
      data:
        brightness: "{{ (state_attr('light.dimmerwoonkamer_level','brightness') + 25) }}"

Unfortunately, when I now trigger the automation, I get this error: voluptuous.error.MultipleInvalid: expected int for dictionary value @ data[‘brightness’]

Apparently the value is not seen as an int. When I cast it to a int like this:

        brightness: "{{ (state_attr('light.dimmerwoonkamer_level','brightness') + 25) | int }}"

I still get the same error. I saw some suggestions around here that the quotes should be removed, but when I do that I get this error in the log:

ERROR (MainThread) [homeassistant.components.automation] while parsing a flow mapping
in “/home/nuc/.homeassistant/automations.yaml”, line 1811, column 22
expected ‘,’ or ‘}’, but got ‘’

I’ve also tried this approach:

        brightness: {{ states.light.dimmerwoonkamer_level.attributes.brightness + 25 }}

But that gives me the error:

ERROR (Thread-11) [homeassistant.util.yaml] invalid key: “OrderedDict([(‘states.light.dimmerwoonkamer_level.attributes.brightness + 25’, None)])”
in “/home/nuc/.homeassistant/automations.yaml”, line 1811, column 0

When I put quotes around it, I’m back at this error again: voluptuous.error.MultipleInvalid: expected int for dictionary value @ data[‘brightness’]

All templates do work in the template editor, so I’m a bit puzzled at where I’m going wrong. Any ideas?

All I needed was this

- id: cube_turn_up_vol
  alias: "Turn up volume with cube"
  trigger:
  - platform: state
    entity_id: sensor.cube1
    to: rotate_right
  action:
    service: media_player.volume_up
    entity_id: media_player.kitchen

Admittedly I am adjusting volume, but the principle is the same.

The problem was actually not with the cube, but with the template.
Turned out that instead of “data” I should have used “data_template”. I also had to take into account that I had to set a default value for when the light was turned off.

I now have it working with this automation:

- alias: cube dimmer woonkamer feller
  trigger:
    platform: event
    event_type: xiaomi_aqara.cube_action
    event_data:
      entity_id: binary_sensor.cube_woonkamer
      action_type: move
  action:
    - service: homeassistant.turn_on
      entity_id: light.dimmerwoonkamer_level
      data_template:
        brightness: "{{ states.light.dimmerwoonkamer_level.attributes.brightness| default(0) |int + 25 }}"

The aqara cube is awesome by the way, great toy for a great price

how to make it decrease brightness or does the same template does both?

You’d create another automation that triggered on the opposite rotation with - 25.

Got it. Thanks