Aqara cube and yeelight brightness

Tags: #<Tag:0x00007f7806d4d6b0>

Hello,

I’m configuring my aqara cube trough zigbee2mqtt.
I have already configured some others automations, but I’m in stuck with this one.
I want to change the brightness of my yeelight lamp while rotating the cube.

In my automation I have this action:

entity_id: light.luce_soggiorno
service_template: |
    {%if trigger.to_state.state == 'rotate_right' %} 
      brightness: '{{states.light.luce_soggiorno.attributes.brightness + 10}}'
    {% else %} 
      brightness: '{{states.light.luce_soggiorno.attributes.brightness - 10}}'
    {% endif %}

When i rotate the cube I receive this error in the log:
2020-02-15 13:28:35 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.cubo_intensita_luci. Invalid data for call_service at pos 1: Service brightness: ‘109’ does not match format ..

Thanks for your support.

You don’t have a service here, only the brightness. You should also use the state_attr(xxx) notation instead of the states.xxx notation, see here for more details.

It should look something like this:

entity_id: light.luce_soggiorno
service: light.turn_on
data_template:
  brightness: >
    {%if trigger.to_state.state == 'rotate_right' %} 
      {{ state_attr('light.luce_soggiorno', 'brightness') | int + 10}}
    {% else %} 
      {{ state_attr('light.luce_soggiorno', 'brightness') | int - 10}}
    {% endif %}

Please be also informed that the automation as you have it now, will turn the brightness down for every possible action of the aqara cube except for “rotate_right” (which will turn the brightness up).

Ciao Michele.
I did it in this way using an Ikea Zigbee bulb:

automation:

- id: 'cube_right'
  alias: Respond to Cube action right
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/0x00158d00029aaf18'
  condition:
    condition: template
    value_template: "{{ 'rotate_right' == trigger.payload_json.action }}"
  action:
    - service: script.alzaluce_ikea
      
- id: 'cube_left'
  alias: Respond to Cube action left
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/0x00158d00029aaf18'
  condition:
    condition: template
    value_template: "{{ 'rotate_left' == trigger.payload_json.action }}"
  action:
    - service: script.abbassaluce_ikea
    

script:

alzaluce_ikea:
    sequence:
      - service: light.turn_on
        data_template:
          entity_id: light.0x000d6ffffe688544_light
          brightness: "{{ (state_attr('light.0x000d6ffffe688544_light', 'brightness')|round(0)) + 50 }}"
         
abbassaluce_ikea:
    sequence:
      - service: light.turn_on
        data_template:
          entity_id: light.0x000d6ffffe688544_light
          brightness: "{{ (state_attr('light.0x000d6ffffe688544_light', 'brightness')|round(0)) - 50 }}"
1 Like