Deconz, Xiaomi Cube and Value_template in automation triggers?

Hi

The guys who manages deconz implemented the possibility to use each side of the xiaomi cube as it’s own event, this is really nice but also a hassle since it takes some really long automations to trigger correctly if you dont want to use the sides for individual automations.

These are the event ID’s available for each move you can do with the cube.

  • x000 for push, so 1000, 2000, 3000, 4000, 5000, 6000;
  • x00x for double tap, so 1001, 2002, 3003, 4004, 5005, 6006;
  • x00o for 180° flip (where o = 7 - x), so 1006, 2005, 3004, 4003, 5002, 6001;
  • x00y for 90° flip (where y ≠ x and y ≠ 7 - x), so 1002, 1003, 1004, 1005, 2001, 2003, 2004, 2006, 3001,
    3002, 3005, 3006, 4001, 4002, 4005, 4006, 5001, 5003, 5004, 5006, 6002, 6003, 6004, 6005;
  • 7007 for shake.
  • 7000 for wakeup (the cube sends raw value 2 when I just tap it after a while).

So for the Push I need 6 triggers, double tap 6 etc, but the 90° needs 24 triggers. I’ve been searching the forum for any way to use a value_template trigger instead, but the issue I have is that I cant understand how to format it since the cube works on the “event” platform, not “state”.

This is what an automation looks like with 1 trigger

automation:
  - alias: Cube Home Theatre - tap_twice - Power on
    initial_state: True
    trigger:
      - platform: event
        event_type: deconz_event
        event_data:
          id: hemmabio_kub
          event: 1001
    action:
      service: script.home_theatre_on

And i would like it to work like this example, but with several if statements and on the event platform.

automation:
  trigger:
    platform: template
    value_template: "{% if is_state('device_tracker.paulus', 'home') %}true{% endif %}"

Anyone who can give me a push in the right direction? I’ve googled and searched the forum for everything that I see even remotely close to what i want.

5 Likes

I’d recommend doing this in Appdaemon instead. It will probably be much faster to realise.

Maybe it’s time for me to go into the world off Appdaemon then… :slight_smile: Been holding of since everything i’ve wanted to do so far has been possible with HA’s limits.

1 Like

Well there is supposed to be built in python automations built in to HASS as well. But I haven’t delved into how those work. Might be sufficient for you

Now I found a way that works without doing very long automation triggers.

See here for an example of how I’ve done it for my xiaomi cube: https://hastebin.com/ebocohabum.cs

The link doesn’t work. It might be worth adding this as an example to the documentation

hastebin has gotten back so the link should work again :slight_smile:

Oh nice, the python part, is that an appdaemon script? Or how do I go about using it?

You need to add the python_script component and then you just do as I do in the automation :slight_smile:


I’m gonna upload an updated python script that’s a bit more efficient and reliable in a bit

Here is a better one: https://hastebin.com/iqojiravox.cs

@martikainen I am in the same situation. Did you solved this ?

Yes I did, it’s regular .yaml code but it’s a bit messy since i have to trigger on all different events the different sides of the cube

https://github.com/martikainen87/hass.io/blob/master/packages/hometheatre/home_theatre_cube.yaml

1 Like

Thank you :slight_smile:

Sorry for necroposting. I think, this can be useful for someone:

- initial_state: on
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: mi_magic_cube
  condition:
    condition: template
    value_template: >
      {% set valid_events = [1006, 6001, 2005, 5002, 3004, 4003] %}
      {{ trigger.event.data.event in valid_events }}
  action:
    service: media_player.toggle
    entity_id: media_player.tv_kitchen
4 Likes

Sorry for once again awakening this thread but, just to be sure of the logic. Your automation trigger calls for any event from the cube and the condition defines what events to include for the specific action right?

Exactly. I don’t know if this solution is someway bad. But it works.

1 Like

Thanks! Just unpacked my cube so I’ll try your solution. To me it looks good, but I’m not that advanced in templates just yet.

Can you please reshare your python script solution? Hastebin link is dead.

@martikainen, I’ve played with the cube in node-red with some fun for the grand-kids. If it is of interest I can upload the code behind.

1 Like

Nice to see that people contribute with their findings, I actually migrated my config to node-red shortly after my initial post. But this might be of use for someone else so please share your code :slight_smile:
Mine is much more “simple” (stupider) and uses a switch to parse the ID from the cube.