Help with Aqara Cube zigbee2mqtt (Rotate to increase/ decrease brightness)

Hey guys!
I want to increase and decrease some lights with the “rotate” action from my Aqara Cube.
After searching the forum i decided to use an automation like this:

- id: '1601415207224'
  alias: Dim light from cube
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.aqara_cube_terrasse_action
    to: rotate_left
    attribute: action
  - platform: state
    entity_id: sensor.aqara_cube_terrasse_action
    attribute: action
    to: rotate_right
  condition:
  - condition: state
    entity_id: sensor.aqara_cube_terrasse_action
    state: '0'
    attribute: side
  action:
  - service: light.turn_on
    entity_id: light.schreibtischlampe_buro
    data:
      brightness: "'{{ (state_attr('sensor.aqara_cube_terrasse_action','angle') / 5 ) | int }}'"
  mode: single

While testing it (in the development template testing tool) the template seems to work. The Angle rotation is translated to a +/ - value. But after using it in the automation, nothing happens to the lightbulb. Does someone has any idea? Where is the fault?
Best regards!
Marcus

1 Like

You should fetch the MQTT topic :nerd_face:

alias: Cube - rotate
  initial_state: 'on'
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/0x00158d000278d768'
  condition:
    condition: template
    value_template: "{{ trigger.payload_json.action in ['rotate_right', 'rotate_left'] }}"
  action:
    - service: light.turn_on
      data:
        entity_id: light.hue_led_tv
    - service: light.turn_on
      data_template:
        entity_id: light.hue_led_tv
        brightness: >-
          {% if trigger.payload_json.angle | float > 0 %}
          {{  states.light.hue_led_tv.attributes.brightness | int + 30 }}
          {% else %}
          {{  states.light.hue_led_tv.attributes.brightness | int - 30 }}
          {% endif %}
1 Like

Sorry i’m new to HA. I have a Blueprint but thats it. With a Mediaplayer i can adjust the volume etc. but for the lights a Dimmer is missing.
I use aswell the mqqt binding and the Blueprint from “SirGoodenough”. I came from openhab where you just could create a Dimmer Switch and the use it wherever you want. Is this here a possibility?

Otherwise it would be really nice, if someone can give me a code snippet on how to dimm lights.
I just need it for 1 Side on the cube, so i can dimm multiple lights and Mediaplayers (which is already working)