Knocki integration

Hi everyone!

We’re currently attempting to integrate Knocki into Home Assistant (HA). Knocki is a smart home device that transforms any surface into a gesture-enabled control interface for managing your favorite functions.

For our initial release, We’re aiming to execute a Home Assistant automation whenever a specific action is triggered through Knocki. Each action is identified by an ID along with a description. Knocki will send a payload to a topic configured in Home Assistant using either MQTT or WebSockets, whichever is easiest. Essentially, the payload will only contain the triggered action ID. Upon reception, Home Assistant should then verify existing automations using the action id as a trigger.

We’ve prepared a diagram illustrating the flow:

However, we have some uncertainties regarding how Home Assistant operates, such as:

We’re relatively new to Home Assistant, and any assistance you can offer would be greatly appreciated! Our aim is to keep things as straightforward as possible during this initial phase. Therefore, we believe your insights could provide valuable guidance on how to proceed.

Yes that would be best. One event for each action.

1 Like

Thank you @tom_l!

We’re excited to get our Home Assistant integration ready for the community - our customers have been requesting this for a long time.

@juanknocki do we have any other technical questions for Tom_I and/or the community?

If any of you are willing to connect with us via Slack and help out with the integration, we’d gladly throw a free Knocki your way to show our appreciation.

Hey @tom_l! We’re fairly new here. We’ve created the Event Entity and successfully instantiated our first entity. Now, we’re exploring methods to subscribe to incoming events, such as MQTT or WebSockets. What would you recommend? In your documentation (Event entity | Home Assistant Developer Docs), it’s mentioned that we need to call my_device_api.listen . Could you provide some examples or guidelines to get started on this? While I’ve begun examining examples on GitHub of your existing integrations, having a straightforward method would be greatly appreciated! Additionally, as @knocki mentioned earlier, we’re open to collaborating with anyone interested in working together.

I am not a developer, just a lowly forum moderator. You would be best to ask these questions in one of the developer channels on the Home Assistant Discord server.

@tom_l thanks for the pointer. We’ve posted our questions on HA’s Discord per your advice and already have a few folks generously offering to help. Hopefully we can get the integration out by June!

2 Likes

@knocki @juanknocki Hi. I hadn’t heard about Knocki before the integration appeared in the last HA release. So I bought one to evaluate. After some challenges it is now sitting on one of my VLANs and I’m receiving notifications on my phone.
My next challenge is to build an HA/Node-RED automation and I note that the integration fires an event - but which event? Is it a state_changed event for example, or something else?
I really like MQTT for this kind of thing and use zigbee2MQTT extensively for my sensors. I consider its pub/sub architecture to be superior to webhooks on many counts. If my Knocki could send MQTT packets to my Mosquitto broker I’d be a happy bunny.

I should add…If you are new to HA you might not know that the MQTT integration can create devices and entities for you - something called MQTT Discovery:

Hey, just got my knocki integrated and everything works.

Im trying to figure out how to create an automation trigger for the event entity it makes.

At the moment, have separate event entities for 3 and 4 knocks. When it activates, it just says event detected.

I’d rather not use just any state change for the automation trigger so therefore finding the actual event details would be beneficial here.

Listening to events I’ve tried already but for some reason I can’t see it on the list of events maybe because I have too many events happening? How do I listen to a specific entity?

Thank you!

@Anto79-ops Same problem here. I am used to events being behind-the-scenes things which change device/entity states, not things I should find a way to ‘subscribe to’ in my automations. For me, triggers are usually based on entity state changes not events. I’m pretty sure that’s the way HA users think, generally.

I can see that an event arrived named:

event.knc1_w_000xxxxx_testing_knocki_1

but can’t capture any data associated with it so I can’t proceed. Perhaps that’s all there is. Maybe @knocki can clarify.

From my testing, for anyone trying out Knocki -

  • Get the latest firmware (ask Knocki support to push it to your device). Mine is currently 1.0.5-rc4. The Knocki app’s Home Assistant Task doesn’t appear in 1.0.2 which the device arrived with.
  • Then reload the knocki integration
  • In the mobile app log out and back in.

@hunterdrayman I hear you, from what I understand, you ahve to listen to any events that the entity gives, at least for now. Here’s my automation, for example, that turns a lightt on and off. Notice the not to and not from additions. I relize this is not the most robost way to do it, but it works.

PS. you may wish to edit your post and remove the serial number in your entity.

alias: Knocki control for master bedroom
description: Control various tasks from the Knocki
trigger:
  - platform: state
    entity_id:
      - event.knc1_bxxxxxxx_3_knocks
    not_from:
      - unknown
      - unavailable
      - None
    not_to:
      - unknown
      - unavailable
      - None
    id: 3_knocks
  - platform: state
    entity_id:
      - event.knc1_bbxxxxxxx_4_knocks
    not_from:
      - unknown
      - unavailable
      - None
    not_to:
      - unknown
      - unavailable
      - None
    id: 4_knocks
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - 3_knocks
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.master_bedroom_main_lights
            data: {}
      - conditions:
          - condition: trigger
            id:
              - 4_knocks
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.master_bedroom_main_lights
            data: {}
mode: single
1 Like

Thanks @Anto79-ops. That was a very helpful example and after some customisation (and integration reload) it worked for me. I can now experiment further whilst hoping that a more conventional mechanism will be developed.
I might just emit an MQTT message and have the MQTT integration create a device/state entity on which I can base my automations.

How were you guys able to configure the Knocki side? In the Android app the “Home Assistant” option is greyed out and says “coming soon”

@virtualbitzz E-mail [email protected] and ask to be added to the beta programme.

Log off/on in the app.

That worked, I was able to create a gesture and I can see the event on the event bus when i run a test for the gesture. What I’m confused about now is how to actually use this to create automations. The state of the sensor is always “Triggered”. It never resets to another state, so I can’t use state change without yet another automation to reset the sensor.

Is this still a work in progress? It seems like this integration isn’t ready yet. The Knocki really should be a “device” in home assistant. Dealing with raw events are beyond the ability of most users, myself included.

EDIT: I see from the previous post that this is still in beta. I didn’t realize that beta integrations were included in Home Assistant core.

event_type: state_changed
data:
  entity_id: event.knc1_w_00037943_dim_lights
  old_state:
    entity_id: event.knc1_w_00037943_dim_lights
    state: unknown
    attributes:
      event_types:
        - triggered
      event_type: null
      friendly_name: "KNC1-W-00037943 Dim Lights "
    last_changed: "2024-07-22T17:41:00.662047+00:00"
    last_reported: "2024-07-22T17:41:00.662047+00:00"
    last_updated: "2024-07-22T17:41:00.662047+00:00"
    context:
      id: 01J3DRGJKP22F7WKE1TEHWEPFF
      parent_id: null
      user_id: null
  new_state:
    entity_id: event.knc1_w_00037943_dim_lights
    state: "2024-07-22T18:38:07.025+00:00"
    attributes:
      event_types:
        - triggered
      event_type: triggered
      friendly_name: "KNC1-W-00037943 Dim Lights "
    last_changed: "2024-07-22T18:38:07.025504+00:00"
    last_reported: "2024-07-22T18:38:07.025504+00:00"
    last_updated: "2024-07-22T18:38:07.025504+00:00"
    context:
      id: 01J3DVS4NH8SHQJCQ8VC45FVXT
      parent_id: null
      user_id: null
origin: LOCAL
time_fired: "2024-07-22T18:38:07.025504+00:00"
context:
  id: 01J3DVS4NH8SHQJCQ8VC45FVXT
  parent_id: null
  user_id: null

I ended up getting this to work. I didn’t realize that by simply specifying the event in the automation trigger and nothing else that it would look for the firing of the event and not a state change.

alias: Knocki
description: ""
trigger:
  - platform: state
    entity_id:
      - event.knc1_w_00037943_dim_lights
condition: []
action:
  - service: light.turn_on
    metadata: {}
    data:
      brightness_pct: 35
    target:
      area_id: living_room
mode: single

I’m a fairly experienced user with about 50 integrations over 3 years. This is the first time I’ve had to interact with the event bus directly.