šŸ§Æ Zigbee2MQTT - Xiaomi Cube Controller

The question is why is it greyed outā€¦

Yes, that is the question I am asking.

Well I have never seen it greyed out.
Is everything else working? what version of HA. What version of Z2m.

Iā€™m an idiot.

@Sir_Goodenough

Hello!
I hope you are doing well!
Can cubeā€™s firmware can be updated if there is an available OTA update?
Also, is "Knockā€ command function will be supported on the future?

Knock is supported. It is sent out as action ā€˜tapā€™ from the action sensor and my blueprint handles it. There is gif file in the main post and the description file demonstrating how to do it.

Updates to firmware on the cube are between Aqara and Z2M, nothing to do with using the device.

I update the blueprint to keep up with Home Assistant and any suggested changes. That has to be manually installed. see:

1 Like

Thanks so much.

sorry to be ignorant. Iā€™m sick with the flu so am probably missing the obvious.
But how do I setup the scripts youā€™ve outlined? specifically dimmer control
do i need to add that as a new scripts in scripts.yaml ? something else entirely

Yes, they are independent scripts that you create and call as a service from the blueprint. Just like it shows.

In case anyone else needs help splitting up Sir_Goodenoughā€™s super helpful YAML for Seeing the cube commands for training the operator, hereā€™s what I have done in my separate template.yaml file that contains a bunch of other stuff not related to this thread:

configuration.yaml:
template: !include template.yaml

template.yaml

- sensor:
# bunch of
# other stuff
# not related
# to this thread

##################################################
# Aqara Cube Blueprint Event Listener
# https://community.home-assistant.io/t/zigbee2mqtt-xiaomi-cube-controller/393203
# After this, add an entity card in your dashboard for sensor.cube_last_action to see what actions occur as you move the cube.
##################################################
- trigger:
  - platform: event
    event_type: cube_last_action
  sensor:
    - name: "Cube Last Action"
      unique_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
      icon: mdi:eye-refresh-outline
      attributes:
        friendly_name: "Cube Action"
      state: >
        {{ trigger.event.data.friendly_name }} - 
        {{ trigger.event.data.action }} - 
        {{ trigger.event.data.side }} frm 
        {{ trigger.event.data.last_side }}

Tip: You donā€™t have to restart HA for this to take effect. Just go to sidebar Developer Tools > go down to the ā€œYAML configuration reloadingā€ section > click ā€œTEMPLATE ENTITIESā€

If you use the Code Server / VS Code for editing, you can also restart anything from there using right click in a blank area or the F1 key to get to the command pallet.

1 Like

i was able to get this blueprint working but it seems to be unstable for me.

I am on Home Assistant 2022.8.7 and am seeing this error in the logs this is just after restarting home assisant and not even using the automation yet:

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:242
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 7:57:03 AM (2 occurrences)
Last logged: 7:57:03 AM

* Blueprint Aqara Magic Cube Zigbee2MQTT - 2022-05-05 generated invalid automation with inputs OrderedDict([('remote', 'sensor.magic_cube_action'), ('flipped90_face_0', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('brightness_pct', 98), ('color_name', 'purple')])), ('target', OrderedDict([('device_id', 'c44e5f4ded082a8473581468057dc043')]))])]), ('flipped90_face_2', []), ('rotate_cw_face_2', []), ('flipped90_face_1', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('brightness', 255), ('color_name', 'red')])), ('target', OrderedDict([('device_id', 'c44e5f4ded082a8473581468057dc043')]))])]), ('rotate_cw_face_0', [OrderedDict([('service', '')])]), ('rotate_ccw_face_0', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('brightness_step_pct', -10)])), ('target', OrderedDict([('device_id', 'c44e5f4ded082a8473581468057dc043')]))])]), ('shake', [OrderedDict([('service', 'media_player.play_media'), ('data', OrderedDict([('media_content_id', 'https://music.youtube.com/watch?v=ZxDlvx-s3lo'), ('media_content_type', 'music')])), ('target', OrderedDict([('device_id', '7feaf0fe9e51cfb7226cc38661de7178')]))])])]): Service does not match format <domain>.<name> for dictionary value @ data['action'][3]['choose'][4]['sequence'][0]['choose'][0]['sequence'][0]['service']. Got None
* Blueprint Aqara Magic Cube Zigbee2MQTT - 2022-05-05 generated invalid automation with inputs OrderedDict([('remote', 'sensor.magic_cube_action'), ('flipped90_face_0', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('rgb_color', [255, 0, 208]), ('brightness_pct', 100)])), ('target', OrderedDict([('device_id', 'c44e5f4ded082a8473581468057dc043')]))])]), ('flipped180_face_1', []), ('flipped90_face_1', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('rgb_color', [255, 0, 0])])), ('target', OrderedDict([('device_id', 'c44e5f4ded082a8473581468057dc043')]))])]), ('rotate_cw_face_1', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('brightness_step_pct', 10)]))])]), ('rotate_ccw_face_1', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('brightness_step_pct', -10)])), ('target', OrderedDict([('device_id', 'c44e5f4ded082a8473581468057dc043')]))])]), ('rotate_cw_face_2', [OrderedDict([('service', ''), ('data', OrderedDict())])])]): Service does not match format <domain>.<name> for dictionary value @ data['action'][3]['choose'][4]['sequence'][0]['choose'][2]['sequence'][0]['service']. Got None

It appears to me to show errors with the automation(s) you built, not the blueprint it is calling.
Can you share the automation(s)?

From what I can read from that error, you have 2 automations with partially filled in entries.
The first one

('rotate_cw_face_0', [OrderedDict([('service', '')])]), 

which fails as

Service does not match format <domain>.<name> for dictionary value @ data['action'][3]['choose'][4]['sequence'][0]['choose'][0]['sequence'][0]['service']. Got None

The other one

('rotate_cw_face_2', [OrderedDict([('service', ''), ('data', OrderedDict())])])]): 

which fails as

Service does not match format <domain>.<name> for dictionary value @ data['action'][3]['choose'][4]['sequence'][0]['choose'][2]['sequence'][0]['service']. Got None

Itā€™s only stable if you give it valid sequences when building an automation. I doubt seriously that these automations passed config check before you restarted Home Assistant.

ok this helped - turns out in the autmoations yaml it can created a few orphaned versions of the automation. iā€™m checking now if itā€™s working ok.

My daughter loved this cube and your blueprint made it really easy to be a good Dad thank you!

1 Like

Holy shizzā€¦ this is magic bro. I owe you a beer. :beer:

1 Like

There are links around to buy me one if you are so inclinedā€¦ (end of the top message)

How can I fix this?

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:255
Integration: Automation (documentation, issues)
First occurred: 10:46:04 (4 occurrences)
Last logged: 10:46:04

Blueprint Aqara Magic Cube Zigbee2MQTT - 2022-05-05 generated invalid automation with inputs OrderedDict([('remote', 'sensor.cube_1_living_room_action_angle'), ('slide_any', []), ('doubletap_any', [OrderedDict([('type', 'turn_on'), ('device_id', 'dab8e2497c63bd8c393d94f80ae89456'), ('entity_id', 'light.0x00178801036fb1ab'), ('domain', 'light'), ('flash', 'short')]), OrderedDict([('device_id', ''), ('domain', ''), ('entity_id', '')])]), ('flipped90_any', [OrderedDict([('type', 'turn_off'), ('device_id', 'dab8e2497c63bd8c393d94f80ae89456'), ('entity_id', 'light.0x00178801036fb1ab'), ('domain', 'light')])]), ('rotate_cw_any', [OrderedDict([('device_id', 'dab8e2497c63bd8c393d94f80ae89456'), ('domain', 'light'), ('entity_id', 'light.0x00178801036fb1ab'), ('type', 'brightness_increase')])]), ('rotate_ccw_any', [OrderedDict([('device_id', 'dab8e2497c63bd8c393d94f80ae89456'), ('domain', 'light'), ('entity_id', 'light.0x00178801036fb1ab'), ('type', 'brightness_decrease')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0x7fd493fc1060>
Blueprint Aqara Magic Cube Zigbee2MQTT - 2022-05-05 generated invalid automation with inputs OrderedDict([('remote', 'sensor.cube_1_living_room_action'), ('rotate_ccw_any', [OrderedDict([('device_id', ''), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0x7fd4940209d0>
Blueprint Aqara Magic Cube Zigbee2MQTT - 2022-05-05 generated invalid automation with inputs OrderedDict([('remote', 'sensor.0x00158d0007e39ff6_action'), ('shake', [OrderedDict([('service', 'scene.create'), ('data', OrderedDict([('scene_id', 'antesVictor'), ('snapshot_entities', 'light.hue_2_victor')]))]), OrderedDict([('repeat', OrderedDict([('count', '5'), ('sequence', [OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('rgb_color', [0, 255, 0])])), ('target', OrderedDict([('device_id', 'bfa6e23d5dc48fdd1e384f747737d3b6')]))]), OrderedDict([('delay', OrderedDict([('hours', 0), ('minutes', 0), ('seconds', 1), ('milliseconds', 0)]))]), OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('rgb_color', [0, 255, 255])])), ('target', OrderedDict([('device_id', 'bfa6e23d5dc48fdd1e384f747737d3b6')]))]), OrderedDict([('delay', OrderedDict([('hours', 0), ('minutes', 0), ('seconds', 1), ('milliseconds', 0)]))])])]))]), OrderedDict([('service', 'scene.turn_on'), ('target', OrderedDict([('entity_id', 'antesVictor')])), ('metadata', OrderedDict())])])]): not a valid value for dictionary value @ data['action'][2]['choose'][6]['sequence'][2]['target']['entity_id']. Got None
Blueprint Aqara Magic Cube Zigbee2MQTT - 2022-05-05 generated invalid automation with inputs OrderedDict([('remote', 'sensor.cube_2_babaciuni_room_action'), ('rotate_cw_any', [OrderedDict([('device_id', '32dc34d856fb18390539e535b30dee96'), ('domain', 'light'), ('entity_id', 'light.hue_bulb_babaciuni'), ('type', 'brightness_increase')]), OrderedDict([('device_id', ''), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0x7fd493ef72b0>

Well, first of all you have 4 failed attempts at answering the blueprint questions. they appear to be incomplete (blank entities), one has a bad remote sensor selected ( sensor.cube_1_living_room_action_angle).

My suggestion is to delete all four, and start over. Get one working with one simple action like toggle a light, and add on to it or change it after you figure it out.

1 Like

I have started getting the following error every minute. I sure it used to work fine, and tbh I can still use the cube for what I want (most the timeā€¦). Any idea how to fix this?

2022-10-21 10:30:46.031 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'trigger' is undefined when rendering '{{ trigger.event.data.friendly_name }} - {{ trigger.event.data.action }} - {{ trigger.event.data.side }} frm {{ trigger.event.data.last_side }}'

Here aremy trigger and template sensors from my templates.yaml file

  - trigger:
      - platform: event
        event_type: cube_last_action
  - sensor:
      - name: "Cube Last Action"
        unique_id: cubelastaction
        icon: mdi:eye-refresh-outline
        attributes:
          friendly_name: "Cube Action"
        state: >
          {{ trigger.event.data.friendly_name }} - 
          {{ trigger.event.data.action }} - 
          {{ trigger.event.data.side }} frm 
          {{ trigger.event.data.last_side }}

Cheers

That is not the correct format for the event sensor.
If you donā€™t use or need the event sensor, you can just delete that. Itā€™s optional. Otherwise check back and fix the type.
Link to the correct code

You can see where I have it in my template stack in my Home Assistant Config