Z2M - Xiaomi Cube Controller

it is a little difficult to examine the side as the state changes are happening way too quick for all the connected devices in HA I suppose. Furthermore the state changed doesn’t show “side” in particular for the xiaomi cube.

Am I supposed to look for “side” in the state changed topic?

You can start listen on that topic “state_changed”, then flip the cube and stop listening on the topic. After that you can search for “side” or “Cube”.

Example:

“new_state”: {
“entity_id”: “sensor.0x0000000000000001_action”,
“state”: “”,
“attributes”: {
“action”: “”,
“angle”: 28.57,
“battery”: 74,
“linkquality”: 28,
"side": 3,
“voltage”: 2955,
“friendly_name”: “0x0000000000000001 action”,
“icon”: “mdi:gesture-double-tap”
},
“last_changed”: “2021-04-30T10:11:00.562438+00:00”,
“last_updated”: “2021-04-30T10:11:00.562438+00:00”,
“context”: {
“id”: “d60444ed10881374e20af2f1767e1c36”,
“parent_id”: null,
“user_id”: null
}
}

1 Like

Hello @x1125 ,
What does exatly your position syntax?

position: >
    {{ [ 0, [state_attr('cover.sun_screen', 'position') | int +
        trigger.payload_json.action_angle | int / 3,
        100] | min ] | max }}

My goal is use this blueprint so that turning clockwise the roller shutter goes down 10% and CCW up 10%.

@mbacks in the template works for mee too, the problem is in the Developer Tools → Services which gives me the same error. Trying the code, the automation gets not editable from the GUI, but disabled too!
Here the content copy and pasted from the automations.yaml:

- id: '1619531322638'
  alias: Aqara Magic Cube (Z2M)
  description: ''
  use_blueprint:
    path: luckypoppy-xiaomi-cube-v2/z2m-xiaomi-cube-controller-v2.yaml
    input:
      remote: sensor.0x00158d00042efedf_action
      rotate_cw_face_0:
      - device_id: f0f3b3f0e61a046ceaa66b56dabfc1bf
        domain: cover
        entity_id: cover.rolling_shutter_switch_2
        type: set_position
        position: '{% set oldpos = state_attr(''cover.rolling_shutter_switch_2'',
          ''current_position'') | int %} {% set step =  10 | int %} {% set newpos
          = oldpos + step %} {% if newpos >= 100 %}100{% else %}{{ newpos | int }}{%
          endif %}'
      doubletap_face_0:
      - type: toggle
        device_id: 2e3761f7bb33d425546271c1ac4426a4
        entity_id: light.dimmer_switch_14
        domain: light
      rotate_ccw_face_0:
      - device_id: f0f3b3f0e61a046ceaa66b56dabfc1bf
        domain: cover
        entity_id: cover.rolling_shutter_switch_2
        type: set_position
        position: 10

Ideas?

Thanks!!

In my case turning right closes the sun screen (no idea what’s correct name of it, in Dutch it’s called zonnescherm) and turning left opens. For my cover (screen) accepted value range is 0-100 so there’s filter to prevent values beyond that range. In addition input value from cube (degrees) are divided to be more or less equal to accepted values (360* to max 100% opened screen) and for comfortable usage as it’s a bit hard to turn the cube 360* to fully open/close the cover.

So if I turn the cube just a bit → screen is moving also just a bit.
Making a big turn completely closing/opening it.

so I now know which face is face 4 for example. However from the automations under developer tools, i tried a simple automation of double tapping the cube with face 4 and the automation is not executed. However if I tried Flip the cube 90 degrees to face 4 the automation works perfectly.

Am I missing something or doing something wrong?

@luckypoppy @mbacks is it possible to have this blueprint in a python script? I.e. independent of HA? I am trying to play a video stream on a raspberry pi via ssh I.e. set up as a command line switch on HA and finding it really difficult for the automation using this blueprint to toggle the switch as its not as quick as how i would normally turn it on from HA frontend and sometimes it doesn’t turn the switch on or off at all. I am looking to make it work independent if I can. Any pointers?

Guys the first page template, is it completely updated after al of yours comments on this thread, can i just use that bluepint copy paste???

@luckypoppy

I don’t know how to do that, but first thing I’m thinking about is to listen to the zigbee2mqtt topic so your script doesn’t depends on HA.

Yes, this blueprint is recently updated and I’m running this version. You can import by url or copy/paste the template.

I have subscribed to the zigbee2mqtt topic and I can get the actions of the cube when I slide it or rotate it etc. However I dont get the extra information like which side is facing up? I only get the original basic actions of the cube.

I’ve subscribed (node-red) on the same topic and below is an example from a received message including side-information.

"{"level":"info","message":"MQTT publish: topic 'zigbee2mqtt/0x00XXXX000XXXXX', payload '{\"action\":\"flip90\",\"action_from_side\":4,\"action_side\":0,\"action_to_side\":0,\"angle\":77.56,\"battery\":86,\"from_side\":4,\"linkquality\":84,\"side\":0,\"to_side\":0,\"voltage\":2975}'"}"
1 Like

Thanks @luckypoppy I tried and get the same payload as you.

Do you know how to extract the action and side as a simple str in python?

So I had a question about using this blueprint. What should the entity be that I look at? I see multiple sensor.magic_cube_action, sensor.magic_cube_action_angle, sensor.magic_cube_action_from_side, sensor.magic_cube_action_side, sensor.magic_cube_action_to_side, sensor.magic_cube_linkquality. I thought, it would one entity like sensor.magic_cube…

1 Like

I am using the “sensor.magic_cube_action_side” and that is working fine.

Ok, I’ll give that a try.

I had some issues with this blueprint and used it as inspiration to make a better version: Home-Assistant-Blueprints/zigbee2mqtt_aqara_magic_cube.yaml at 9a63ee03f1d0cf10448fb89a28528ac4105461ac · golles/Home-Assistant-Blueprints · GitHub

4 Likes

Thank you so much for this updated blueprint! I had it working with my cubes a week or two ago with zigbee2mqtt in a separate docker container. But they stopped working and I can’t tell why. The cubes talk to z2m, z2m sends mqtt to hass’s mosquitto, mosquitto shows that the mqtt events are received, the entities in hass show their states, but the automation won’t fire. I don’t get where the disconnect is.

I’m not quite sure how to troubleshoot it since the automation won’t fire at all, so a trace doesn’t exist to debug.

Didn’t work for me.
Checked the automation trace and it stops on the condition.

I have the same issue :frowning:. Things where working for quite a wile. But now the automation stopped working.
I might be related to some recent updates of either homeassistant core, homeassistant host or Zigbee2mqtt .

Home assistant is running on a raspberrypi4 and a CC2531 USB stick is used for Zigbee.
MQTT server runs externally.

The MQTT integration in homeassistant does not show any entities in the Aqara device MQTT info.
It seems like the MQTT addresses exposed by Zigbee2MQTT did change and therefore the auto MQTT discovery in homeassistant no longer works.
Looking at the published MQTT messages (using MQTT Explorer), the only aqara related (retained) topic I see in /homeassistant is: /homeassistant/device_automation/<my_aqara_id>/action_shake/config. Containing the following message:

{
  "automation_type": "trigger",
  "device": {
    "identifiers": [
      "zigbee2mqtt_<my_aqara_id>"
    ],
    "manufacturer": "Xiaomi",
    "model": "Mi/Aqara smart home cube (MFKZQ01LM)",
    "name": "Aqara",
    "sw_version": "Zigbee2MQTT 1.21.2"
  },
  "payload": "shake",
  "subtype": "shake",
  "topic": "zigbee2mqtt/Aqara/action",
  "type": "action"
}

Solved my problem. Not sure how :frowning:
After adding some new zigbee lights, I was not able to add more lights. Google gave me the tip to unplug the zigbee USB stick and plug it in again.
After this action, I was able to add the remaining lights.
The next day I found out that my aqara was working again :slight_smile:
Inspcting the /homeassistant/device_automation/<my_aqara_id> topic now also shows the topics action_wakeup, action_slide, action_flip180 and some others.