Automation for cube not turn on light

Hello,

I have configured the aquara cube so that the turns increase or decrease the brightness of an ikea bulb. It works well, but if I turn the cube to the minimum I can turn it off with that movement. But since it’s off, it’s not able to turn it on by turning it around. Can I get to tell him that in that turn I turn it on if it’s off? The brightness regulation works correctly.

- alias: Cube Left
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/0x00158d00028af5d8'
  condition:
    condition: template
    value_template: "{{ 'rotate_left' == trigger.payload_json.action }}"
  action:
    - service: light.turn_on
      entity_id: light.lampara_salon
      data_template:
        brightness: '{{states.light.lampara_salon.attributes.brightness - 60}}'

- alias: Cube Right
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/0x00158d00028af5d8'
  condition:
    condition: template
    value_template: "{{ 'rotate_right' == trigger.payload_json.action }}"
  action:
    - service: light.turn_on
      entity_id: light.lampara_salon
      data_template:
        brightness: '{{states.light.lampara_salon.attributes.brightness + 60}}'

When it’s off the brightness attribute doesn’t exist, so your brightness template causes an error in this case. You should change them to:

        brightness: "{{ state_attr('light.lampara_salon', 'brightness')|int - 60}}"

and:

        brightness: "{{ state_attr('light.lampara_salon', 'brightness')|int + 60}}"

The state_attr function will return None (instead of causing an error) for a nonexistent attribute, and the int filter will return 0 when the input (in this case None) cannot be converted to an integer.

This work perfect,

Thank you very much!!:grinning:

1 Like