MQTT Automation Hue Remote

Hi folks,

I’m loosing the will to home automate and have a bag full of frustration…

Setup since a few weeks (out of interest and tinkering):

  • External Zigbee antenna device (plugged in via ethernet)
  • Mosquitto Proxmox LXC
  • Zigbee2MQTT Proxmox LXC
  • Home Assistant OS Proxmox VM with MQTT integration

When I have time and are in the mood I move devices from my old ZHA RaspberryPi to my new setup and so far it worked fine and is fun to interact a bit more with the underlying protocol.

Today I moved my Hue switch v2 (the first “action” device) and the light bulbs in the bedroom - so far so good.
But the automation drives me crazy and I dont get a hold on the MQTT actions at all!
Can anyone shove me in the right direction on how to implement for example double-click and long-click - besides the normal click - to activate a scene?
I dont mind putting time and effort in to write these things, since I want to understand it and thus don’t use blueprints. But at the moment I feel hard stuck.

Any advice is appreciated.

Please help a fella in need before his girlfriend comes back from vacation :face_with_peeking_eye:

Here’s the applicable section of my automation for detecting a single and double-press.

  • For a single-press there’s only one on reported.
  • For a double-press there are two ons reported in rapid succesion.

I use a wait_for_trigger with a 1 second timeout to detect the second on.

actions:
    - choose:
        - conditions: "{{ trigger.to_state.attributes.event_type == 'on' }}"
          sequence:
            - wait_for_trigger:
                - platform: state
                  entity_id: event.office_dimmer_action
                  not_from: 'unavailable'
              timeout: 1
            - action: light.turn_on
              target:
                entity_id: light.office
              data:
                brightness: "{{ 255 if wait.completed and wait.trigger.to_state.attributes.event_type == 'on' else 128 }}"

That example comes from my post, where I described how I migrated my automations to use Event Actions, in this very useful topic:

Let me know if you need additional help with it.

1 Like

You can also go straight to the horses mouth and just process the raw MQTT “action” event:

triggers:
  - trigger: mqtt
    options:
      topic: zigbee2mqtt/Living Entry Switch/action

It’s a little more work to parse the JSON payload, however if you use the same type of switch throughout your place parsing the JSON is a one time task.

It also means that you don’t have to worry about device support - if the device sends the message you get it / can handle it.

1 Like

Thank you both very much @123 and @dtrott!

Yesterday morning I spend 10 minutes with a fresh mind at it and almost immediately worked out the solution - and more importantly the syntax :smiley: - for the direct MQTT action approach. Which once more shows if you get in a bad state you should call it quits and get back to it with a fresh head.

I didnt get to read the post 123 linked but I will do so the next days.

What do you mean with “It’s a little more work to parse the JSON payload”?
Atleast for the one-click actions I just went with:

triggers:
  - topic: my-topic/Hue Switch 1337/action
    payload: on_press
    id: top_button_press_one
    trigger: mqtt

And then work with it.

I guess where you are heading is my next question with the double-press and long-press?
The idea with the wait_for_trigger and timeout is interesting and I’m wondering if there is an already bullet proof solution out there to handly e.g. exactly a double-press in 0.5 seconds or a long-press with atleast 1 second.

Look in the Blueprint Exchange section of the forum. There are several available for Philips Hue dimmer switches. Review their descriptions and select whichever one meets your needs best (ensure it supports “Z2M” → Zigbee2MQTT).

They all use some variation of the technique I had described above to detect multi-press and long-press button events.

Worst case, pick the closest fit and then modify it.


NOTE

If you’re unfamiliar with the concept of blueprints, review this documentation.

1 Like

If you have a working solution that you are happy with, then I would suggest:

  • If it ain’t broke then don’t fix it.

However like everything HA, there is always and option to make it more complex, see:

1 Like

Thank you again!
I’ll look further into the material you posted :slight_smile: