Event information deconz with Xiaomi Cube

Hello, I did the same thing and the new name cube_rotation isn’t exposed in the deconz_event. Is there a way to refresh device metadata?

{
    "event_type": "deconz_event",
    "data": {
        "id": "mi_magic_cube",
        "unique_id": "00:15:8d:00:02:a3:76:9c",
        "event": 6000
    },
    "origin": "LOCAL",
    "time_fired": "2019-10-06T14:32:58.710379+00:00",
    "context": {
        "id": "6145043fdfe64d8595bfa15fc3c40394",
        "parent_id": null,
        "user_id": null
    }
}

Hi

Great forum thread.

For those needing the renaming of the two cube devices in deconz I have summarized the workaround in another forum thread.

Hi @fantomnotabene
How do you get the Eventdata (this 4numbers) with templating?
I try to make a template sensor, but ehitout luck.

sensor:

  • platform: template
    sensors:
    aqara_cube_01:
    friendly_name: ‘aqara_cube_01’
    value_template: “{{states (‘sensor.cube_01’)}}”

I created the name cube_01 when i had conneting the aqara cube in the deconz web interface. The battery-State is shown as entity: sensor.cube_01_battery_level So i just guess the name in the template sensor script. The result: the state of the template sensor are always ‘unknown’.
Can sombody help?

Inside of an automation, triggered by “platform: event”, you can use
{{ trigger.event.data }}
Event should be filtered by deconz_event and your cube’s device id.

thanks - but that aren’t i’m looking for. i like to have the sensor data…

You can use input_text instead of sensor (or create template sensor and sync their states) and set its value via automation. Don’t know if there’s a better way.

Thanks - sounds good. Would you give me an example, to bring me on the right track?

Create an input_text entity.
Create a template sensor entity, which value_template points to an input_text's state (something like {{ states('input_text.cube') }}).
Then create an automation like this one:

- alias: ...
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: cube
  action:
    service: input_text.set_value
    entity_id: input_text.cube
    data_template:
      value: "{{ trigger.event.data.event }}"

Or you can even set text value to an input_text accordingly to event number if you know how to use template conditions.

2 Likes

Works perfect! Thanks a lot

I’ve been tried code under, I have two cubes, but it doesn’t working. When I’ve been trying deconz_event, it shows me events with event and gesture elements, but all sensors has only value 0 and nothing has been changed.

input_text:
  mi_magic_cube_1_event:
    name: Mi Magic Cube 1 Event
    initial: 0000
  mi_magic_cube_1_gesture:
    name: Mi Magic Cube 1 Gesture
    initial: 0
  mi_magic_cube_2_event:
    name: Mi Magic Cube 2 Event
    initial: 0000
  mi_magic_cube_2_gesture:
    name: Mi Magic Cube 2 Gesture
    initial: 0

sensor:
  - platform: template
    sensors:
      mi_magic_cube_1_event:
        value_template: "{{ states('input_text.mi_magic_cube_1_event') }}"
      mi_magic_cube_1_gesture:
        value_template: "{{ states('input_text.mi_magic_cube_1_gesture') }}"
      mi_magic_cube_2_event:
        value_template: "{{ states('input_text.mi_magic_cube_2_event') }}"
      mi_magic_cube_2_gesture:
        value_template: "{{ states('input_text.mi_magic_cube_2_gesture') }}"

automation mi_magic_cube_1_event:
- alias: Mi Magic Cube 1 event
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: mi_magic_cube_1
  action:
    service: input_text.set_value
    entity_id: input_text.mi_magic_1_event
    data_template:
      value: "{{ trigger.event.data.event }}"

automation mi_magic_cube_1_gesture:
- alias: Mi Magic Cube 1 gesture
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: mi_magic_cube_1
  action:
    service: input_text.set_value
    entity_id: input_text.mi_magic_1_gesture
    data_template:
      value: "{{ trigger.event.data.gesture }}"

automation mi_magic_cube_2_event:
- alias: Mi Magic Cube 2 event
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: mi_magic_cube_2
  action:
    service: input_text.set_value
    entity_id: input_text.mi_magic_2_event
    data_template:
      value: "{{ trigger.event.data.event }}"

automation mi_magic_cube_2_gesture:
- alias: Mi Magic Cube 2 gesture
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: mi_magic_cube_2
  action:
    service: input_text.set_value
    entity_id: input_text.mi_magic_2_gesture
    data_template:
      value: "{{ trigger.event.data.gesture }}"


The second. How to create code which changes numbers to human text ie. 1 - Shaking etc.? Thank you

input_texts has a _cube_ in their entity ids, but inside of an automations they are not.

Something like:

value: >-
  {% if trigger.event.data.gesture == X %}
  Sliding
  {% elif trigger.event.data.gesture == Y %}
  Shaking
  {% elif trigger.event.data.gesture == Z %}
  Dropping
  {% else %}
  etcetera...
  {% endif %}