Xiaomi magic cube + zigbee2mqtt: ho to detect "side" (integer) of the cube

Hi everyone,

I started to experiment with my magic cube
It is paired with zigbee2mqtt

example of mqtt message is
{"battery":97,"voltage":2995,"linkquality":39,"side":1,"angle":18.02,"action":""}

In hass, I configured following automation

# ==================================================
# XIAOMI SWITCH R02
# ==================================================
# door op de rechterknop te klikken
# doorloop je alle mogelijke combinaties van de lamp
- id: '0x00158d0002b93b6c'
  alias: '(R02) magic cube'
  trigger:
  - entity_id: sensor.0x00158d0002b93b6c_side
    platform: state
    to: 1
  condition: []
  action:
    entity_id: input_select.select_s01
    service: input_select.select_next

However, the automation does not accept the integer
to: 1

If I change it to a string
to: '1'
that doesn’t work either

Following automation does work

# ==================================================
# XIAOMI SWITCH R02
# ==================================================
# door op de rechterknop te klikken
# doorloop je alle mogelijke combinaties van de lamp

- id: '0x00158d0002b93b6c'
  alias: '(R02) magic cube'
  trigger:
  - entity_id: sensor.0x00158d0002b93b6c_action
    platform: state
    to: flip90
  condition: []
  action:
    entity_id: input_select.select_s01
    service: input_select.select_next

however, this is another kind of “action”…

What I want to achieve is

  • detect the selected side of the cube (1,2,…,6)
  • select a scene, based on the side

Can anybody help me with the correct syntax?
any help appreciated!

kind regards,
Bart

Hi Bart,

I managed to solve this problem, but I must say it’s a bit of an elaborate hack.

First I defined a MQTT sensor in configuration.yaml:

sensor:

  • platform: mqtt
    name: “cube_keuken_side”
    state_topic: “zigbee2mqtt/cube_keuken”
    value_template: “{{ value_json.to_side }}”

Please note I changed the cryptic name that zigbee2mqtt allocates to something I can remember. I guess in your case it’ll be zigbee2mqtt/0x00158d0002b93b6c

Then in automations.yaml:

  • alias: ‘magic cube side 1’
    trigger:
    platform: state
    entity_id: sensor.cube_keuken_side
    to: ‘1’
    action:
    • service: notify.alexa_media
      data:
      target:
      - media_player.echo_desk
      title: “Cube”
      data:
      type: announce
      #method: all
      message: “cube side 1”

I repeated this 6 times. I know there must be a way to do it with sort of a list, but that’s beyond my skills. The action is just an echo notification, which is easy during testing.

Steven