🧯 Zigbee2MQTT - Xiaomi Cube Controller

Hi is it possible with this blueprint to brighten a light by rotating clockwise and dim counterclockwise? How? Thanks. I see the instruction in post 1, but how to add this??

EDIT I changed the blueprint automation manually, but where to change the script integration?

what am I missing?

I don’t know where you pasted that code. I don’t know if there is typo in it because it is a picture.
i can show you exactly where I have this in my configuration.yaml, maybe that will help you. It goes in the script: integration
It is also possible that the lights you are controlling do not have a brightness control.

In editor

I copy pasted your code

Found the Bug. You are correct, my friend, It seems HA has changed the syntax and data_template: no longer works, needs to be just data:.

The code in message 1 is fixed, but if you just make that change it will work fir you.


November 30, 2022 > Update. Added ZHA Cube Controller version to library.

So Brian and everyone else, St. Nick brings you treats this day. Well, I do, but who’s counting…

I have re-Written the back end of this blueprint to use MQTT Based triggering.

Why you might ask?

Well because there were plenty of people that had their Z2M running in HA Legacy mode which is supposed to be the least favored method (but works great for this). There are others of you that are running Z2M in non-Legacy mode (which looks painful to implement). But everyone has the MQTT Trigger mode available regardless of how you have your triggers set. So rather than excluding anyone, that’s what I used.

As a special bonus, on my system anyway, it responds faster.

As a special treat this blueprint created it’s own number entity to store the last_side variable which the legacy mode did for me before, now I have to do it, but for those of us that are geeks out there you can see how to generate a number entity using MQTT Discovery for your own needs should you need it.

Feel free to ask questions.here. If you found a bug please add it to Github as an issue so I can take care of it.

Please Click the :orange_heart: at the end of the Top Post if you find this Useful

1 Like

I have updated blueprint, but they don’t work. MQTT receives data, but automation does not see them.:face_with_monocle:
Any ideas?

Screenshot 2022-12-06 183946

There are always null triggers.
Z2M usually has a wake-up trigger, then the actual trigger, then a null trigger on every action. (sometimes more…)
That’s why the condition is there to only act on real actions & avoid log spam.
Look thru other triggers and see if the action shows in one of those.

In the second screenshot, I showed that the topic is specified correctly)

There are two errors in the system logs

Logger: homeassistant.components.automation.cube
Source: helpers/script.py:409
Integration: Автоматизация ([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: 6 декабря 2022 г., 18:10:21 (36 occurrences)
Last logged: 6 декабря 2022 г., 18:37:35

cube: Error executing script. Error rendering template for variables at pos 1: TemplateError: str: Must provide a device or entity ID
Logger: homeassistant.components.automation.cube
Source: components/automation/__init__.py:572
Integration: Автоматизация ([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: 6 декабря 2022 г., 18:10:21 (36 occurrences)
Last logged: 6 декабря 2022 г., 18:37:35

Error while executing automation automation.cube: TemplateError: str: Must provide a device or entity ID

Just to double check everything, I deleted the copy on my HA instance, I pushed the download blue button in the top post here, installed it, built a tap action, and it worked, no log errors. I need to see your automation if I am to find anything further.

Can you post that to me in a personal message here or on my discord? I will help you troubleshoot further.

Update…Later that Evening…
I found a place where non ASCII characters could effect the friendly name, so I added a filter and I increased the HA rev requirement in case that was causing an issue.
You may want to try it again, maybe I found it. I don’t have a way to know as it works here.

December 11, 2022 > Update. Added Device Tracker Blueprint to the list.

  • 2022-12-12: Add Update Method Note, minor code change.
    • Name of Blueprint may have changed meaing you have to re-download with a new link.
    • If name changed, it is similar. Variables have not changed.

OMG! I just realized that you updated your blueprint! This is wonderful. I’m so grateful to you. It works perfectly.

Thank you so much :slight_smile:

I do have one error, though, in configuring the example you have of rotate for dimmer control. I haven’t spent much time digging into it. I get this error in the logs when the action is triggered:

2022-12-19 15:40:41.036 ERROR (MainThread) [homeassistant.components.script.cube_dimmer_control] cube_dimmer_control: Error executing script. Error for call_service at pos 1: Error rendering data template: TypeError: can’t multiply sequence by non-int of type ‘float’

I assume this refers to the variable: angle. I tried replacing
{% set step_size = angle * 0.4 %}
{% set step_size = (float(angle)) * 0.4 %}
which also failed – I’m sure I have the syntax wrong. Maybe the value isn’t being passed correctly, however?
EDIT: I changed the line to:
{% set step_size = float(angle) * 0.4 %}
and got this error:
2022-12-19 23:16:26.407 ERROR (MainThread) [homeassistant.components.script.cube_dimmer_control] cube_dimmer_control: Error executing script. Error for call_service at pos 1: Error rendering data template: ValueError: Template error: float got invalid input ‘’ when rendering template '{% set step_size = float(angle) * 0.4 %}

So, it looks as if the value of ‘angle’ isn’t being passed at all from the template in the automation:

      - service: script.cube_dimmer_control
          angle: '{{ trigger.payload_json.angle }}'
          light: light.office_inside

Any advices are welcomed!

Thank you so much again James for all your work!

I’ll have to see what I have different on mine…

OK. I have left legacy stuff on. When I look at MQTT-explorer the topic zigbee2mqtt/yertle (which is the cube name and is the topic I’m using to grab the changes) has the angle as an attribute. I see it, mine is working.


What are you seeing?
What topic are you using?
If you are using the equiv of zigbee2mqtt/yertle/action, that won’t work.


This is the script I’m using…

I have turned on all Legacy settings:

It seems that I’m not getting the “angle” payload piece. I get the action_angle though:


I am using the cube name (Cube1) as the topic:

And again, it looks like “angle” isn’t included in the payload as it is in yours.

Maybe I could use “action_angle” as the input?

EDIT: Sure enough, "changing the code to use ‘{{ trigger.payload_json.action_angle }}’ has it working as expected. :man_shrugging:

I’m having the same exact issue.

This is my automation from the blueprint: dpaste/XtSiD (YAML)

home assistant log errors: Imgur: The magic of the Internet

I looked in mqtt explorer and see the mqtt messages showing it working for shake, tap etc. I also see the home assistant actions showing the expected actions. There’s some issue with the blueprint that home assistant doesn’t like and throws those errors in the log.

I just tried the shake action to control an area with light.toggle like you did… it works for me OK

      - service: light.toggle
        data: {}
          area_id: office

The only difference I see from your example is my area is using a friendly name, and my Cube name contains no spaces.

For light.toggle, entity_id is a required parameter…

I don’t see where it talks about area toggles. But if it worked with a name, I would go with that.

What’s your cube model or firmware and version / type of Z2M. If I need to change it I can, trying to figure out exactly why, however. I also have action_angle, but was weird about using it because it goes to null sometimes. Maybe it’s right when it needs to be, but that would need to be tested.

My cube reports as: MFKZQ01LM
I’m not sure how to extract the firmware version.
Z2M running in HASS, directly installed on Raspberry Pi with Sonoff 3.0 USB dongle:


I changed this specific setting in Z2M settings for the cube (it was un-set before):

And suddenly, I get this:


Success! I guess I should leave all the other Legacy things enabled as well? Everything seems to work with my other Zigbee devices.

1 Like

I deleted everything and started fresh and changed the name in z2m to one with no spaces and it all works. Thanks for the help and man what a great blueprint I really appreciate it!

1 Like