Hue Tap switch controlling using event (hue event)

Hey all,

Well I had this idea to sniff out the feedback from an press of the hue tab from the hue_event state. If i go to Events and listen to the feedback from pressing on a hue tap botton I get something like:

{
    "event_type": "hue_event",
    "data": {
        "id": "hue_tap_switch_gastenkamer",
        "device_id": "a246e2240465db1ffcfc983eb157b0d6",
        "unique_id": "00:00:00:00:00:46:bb:d1-f2",
        "event": 34,
        "last_updated": "2021-11-11T09:02:10"
    },
    "origin": "LOCAL",
    "time_fired": "2021-11-11T09:02:10.282833+00:00",
    "context": {
        "id": "d12eec9dcd702e3bd3ff6234f126d634",
        "parent_id": null,
        "user_id": null
    }
}

So my thoughts were; well if I can get a event state back: like 34. I should be able to set up a scene for all of these states and make a nice automation of of this. The reason for this work around is that an other option like Interloping made is great; but seems a quite a big work. Next to that; my experience isn’t that big. So i though let’s try it an easy way. Well it seems I was wrong. As this doesn’t seem to work.

My current try of the automation is like:

- id: Hue tap
  alias: Hue tap control
  trigger:
    - event: hue_event
      device_id: a246e2240465db1ffcfc983eb157b0d6
      entity_id: hue_tap_switch_gastenkamer
      platform: state
  action:
  - delay:
      milliseconds: 20
  - data_template:
      entity_id:
      - scene.
        {%- if is_state('event.hue_tap_switch_gastenkamer', '34') -%}
          slaapkamer_licht_100
        {%- elif is_state('event.hue_tap_switch_gastenkamer', '16') -%}
          gastenkamer_licht_50
        {%- elif is_state('event.hue_tap_switch_gastenkamer', '17') -%}
          slaapkamer_licht_25
        {%- elif is_state('event.hue_tap_switch_gastenkamer', '18') -%}
          gastenkamer_licht_uit
        {%- else -%}
          gastenkamer_licht_uit
        {% endif %}
    service: scene.turn_on

So as I understand: I can’t read a hue_event, as is seems not to exist (but neither does hue). So what is the way to go there? Can you guys help me on the way; so I can proceed with my route to a nice simple automation?

device_id should go under event_data:. You should filter on event as well.
entity_id is irrelevant.

Thank you! That did help me already one step forward.

I do have a next issue with the automation though. I looked around for the right way to template. But i came to the conclusing that also in this case a ‘is_state’ is the right way to go. Where the entity is (in my case) ‘hue_tap_switch_gastenkamer’ as this is witin the data set I came to the conclusion this should refer to as: ‘trigger.event.data.hue_tap_switch_gastenkamer’

Looking to the feedback from HA I think I make a major mistake there. So playing around with the data_template didn’t really work. Where do I go wrong with my illogic?


- id: Hue tap
  alias: Hue tap control
  trigger:
    - platform: event
      event_type: hue_event
      event_data:
        entity_id: hue_tap_switch_gastenkamer
  action:
  - delay:
      milliseconds: 20
  - data_template:
      entity_id:
      - scene.
        {%- if is_state('trigger.event.data.hue_tap_switch_gastenkamer', '34') -%}
          slaapkamer_licht_100
        {%- elif is_state('trigger.event.data.hue_tap_switch_gastenkamer', '16') -%}
          gastenkamer_licht_50
        {%- elif is_state('trigger.event.data.hue_tap_switch_gastenkamer', '17') -%}
          slaapkamer_licht_25
        {%- is_state('trigger.event.data.hue_tap_switch_gastenkamer', '18') -%}
          gastenkamer_licht_uit
        {%- else -%}
          gastenkamer_licht_uit
        {% endif %}
    service: scene.turn_on

Have you tested your template in the template section of the developer tools? This should help you confirm whether pressing buttons is creating the output you expect formatted in the correct way. I think your problem might be that the output after scene. is getting whitespace added.

1 Like

Well I totally rewrote this into separate automations first. Templating is something it seems i need to train myself more