Another Xiaomi Cube thread

Tags: #<Tag:0x00007f32716c0f98> #<Tag:0x00007f32716c0e30>

HI folks, hoping soemone can help me here.

I have the cube installed (via zigbee2mqtt) and the actions (flip 90 rotate etc.) are working fine in my automations.

What I’d like to do is to be able to utilise the the “side” functions in combination. For exmaple if the cube has side 1 facing up and I turn the cube left/right the volume on my google hub is turned up/down. If side 2 is facing up and I turn the cube left/right the volume on my soundbar is turned up/down.

The volume stuff is easy enough because the actions are avaiable but I’m having trouble figuring out identify the “Side” and act on that.

the zigbee2mqtt logs have entries such as the following:

INFO: MQTT publish: topic 'zigbee2mqtt/MagicCube', payload '{"action":"flip90","angle":17.86,"battery":80,"from_side":0,"linkquality":123,"side":1,"to_side":1,"voltage":2965}'

INFO: MQTT publish: topic 'zigbee2mqtt/MagicCube', payload '{"action":"","angle":17.86,"battery":80,"linkquality":123,"side":1,"voltage":2965}'

INFO: MQTT publish: topic 'zigbee2mqtt/MagicCube/action', payload 'flip90'

On that basis and following some searching I thought I would be able to use a sensor like this:

sensor:
  - platform: mqtt
    name: Magic Cube Side
    state_topic: “zigbee2mqtt/MagicCube”
    value_template: “{{ value_json.to_side }}”

whilst the sensor displays in HA, giving errors config wise, I dont appear to be getting the 'side data".

I would prefer to do this without resorting to adding any more custom components. Any help appreciated :slight_smile:

hello
i use side in my automations as a condition:
{{is_state_attr('sensor.cube1_action', 'side', 0)}}
i found how to, in “templating”


---->
is_state_attr('device_tracker.paulus', 'battery', 40) will test if the given entity attribute is the specified state (in this case, a numeric value). Note that the attribute can be None and you want to check if it is None , you need to use…`

ex:

alias: cubelight
 description: 'light +10%'
 trigger:
 - platform: state
   entity_id: sensor.cube1_action
   to: rotate_right
   attribute: action
 condition:
 - condition: template
   value_template: '{{is_state_attr(''sensor.cube1_action'', ''side'', 0)}}'
 action:
 - service: light.turn_on
   data:
     brightness_step_pct: 10
   entity_id: light.lights_kitchen

@tomdudu38 SPOT ON. Thanks very much for that - working nicely :slight_smile: