# Problems getting custom pairing views to work

**URL:** <https://community.homey.app/t/problems-getting-custom-pairing-views-to-work/116013>\
**Category:** Developers\
**Created:** [September 14, 2024, 8:28am UTC](https://community.homey.app/t/problems-getting-custom-pairing-views-to-work/116013 "2024-09-14T08:28:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BufferOverflow](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bufferoverflow/32/12568_2.png) [@BufferOverflow](https://community.homey.app/u/BufferOverflow)\
**Post date:** [September 14, 2024, 8:28am UTC](https://community.homey.app/t/problems-getting-custom-pairing-views-to-work/116013/1 "2024-09-14T08:28:25Z")

</div>

I’m trying to get a simple custom pairing flow to work. But i get strange results and is clearly missing something obvious.

Pairing via Homey Developer Tools always get me back to the same view (manual\_pairing) when i press the ‘add device’ button. I can see in the logs that the view for some reason is shown twice.

Pairing in app gives a blank screen after pressing the button. Cancelling the pairing from there actually adds adds the device. I have tried with and without a second view called ‘done’ that has a Homey.done()

Any ideas? Thanks in advance! 🙂

Flow:

- Three fields in a form
- A connectivity/validation check in the driver/backend
- createDevice from view
- Done

driver.compose.json

```auto
  "pair": [
    {
      "id": "manual_pairing",
      "navigation": { "next": "done" }
    },
    {
      "id": "done"
    }]

```

driver.js

```auto
  async onPair(session) {

    session.setHandler('manual_pairing', async (data) => {
      //TODO: A backend connection test will be made from here, for now lets assume everything is ok.
      console.log(`FE emitted from manual_pairing - ${data.ipaddress}`);
      return true;
    });
   
    session.setHandler("showView", async (viewId) => {
      console.log("debug - view: " + viewId);
    });
  }

```

manual\_pairing.html

```auto
...3 field form and a button...
<script type="application/javascript">

  let connectElement = document.getElementById('connect');

  connectElement.addEventListener('click', (e) => manualPairing());

  function manualPairing() {
    let ipaddress = document.getElementById('ipaddress').value.trim();
    let deviceid = document.getElementById('deviceid').value.trim();
    let accesscode = document.getElementById('accesscode').value.trim();

    Homey.emit('manual_pairing', {
      ipaddress: ipaddress,
      deviceid: deviceid,
      accesscode: accesscode
    })
      .then(result => {
        console.log('back from backend with result ' + result);

        if (result) {
          console.log('debug - adding ' + deviceid);
          Homey.createDevice({
            name: deviceid,
            data: {
              id: deviceid,
            },
            store: {},
            settings: {
              ipaddress: ipaddress,
              accesscode: accesscode
            }
          })
          .then(() => {
            console.log('Device created successfully');
            //Homey.done();
          })
          .catch(error => {
            console.error('Error creating device:', error);
          });

          console.log('debug - added ' + deviceid);
        }
      });
  }

</script>

```

done.html

```auto
<script type="application/javascript">
    Homey.done();
</script>

```

## Logs

### Backend

```auto
debug - view: manual_pairing
FE emitted from manual_pairing - testip
debug - view: manual_pairing

```

### FrontEnd

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/f/6f76ca649941fb4dc60d7170ccd4fe0f5bc353bb.png)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 14, 2024, 8:53am UTC](https://community.homey.app/t/problems-getting-custom-pairing-views-to-work/116013/2 "2024-09-14T08:53:22Z")

</div>

Since it’s not showing “Device created successfully’”, the issue is probably caused by `Homey.createDevice()` failing (perhaps if you’re trying to create devices with the same id as an existing device).

There’s however an issue with that method ([see here](https://github.com/athombv/homey-apps-sdk-issues/issues/330)) that can cause it to fail silently.

---

<div class="post-metadata">

**Author:** ![BufferOverflow](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bufferoverflow/32/12568_2.png) [@BufferOverflow](https://community.homey.app/u/BufferOverflow)\
**Post date:** [September 14, 2024, 10:08am UTC](https://community.homey.app/t/problems-getting-custom-pairing-views-to-work/116013/3 "2024-09-14T10:08:49Z")

</div>

> [@robertklep](#):
>
> Since it’s not showing “Device created successfully’”, the issue is probably caused by `Homey.createDevice()` failing (perhaps if you’re trying to create devices with the same id as an existing device).

Thanks Robert for your help! And yes you are correct. It is somewhere in createDevice it blowing up without an error.

Do you know if i can add it directly in the onPair on the backend? It has all the information anyway.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 14, 2024, 10:46am UTC](https://community.homey.app/t/problems-getting-custom-pairing-views-to-work/116013/4 "2024-09-14T10:46:18Z")

</div>

> [@BufferOverflow](#):
>
> Do you know if i can add it directly in the onPair on the backend? It has all the information anyway.

I don’t think so, no (which has always struck me as very strange: _most_ of the pairing process is done in the backend, but actually creating the device has to be done in the frontend).

---

<div class="post-metadata">

**Author:** ![BufferOverflow](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bufferoverflow/32/12568_2.png) [@BufferOverflow](https://community.homey.app/u/BufferOverflow)\
**Post date:** [September 14, 2024, 10:47am UTC](https://community.homey.app/t/problems-getting-custom-pairing-views-to-work/116013/5 "2024-09-14T10:47:49Z")

</div>

> [@robertklep](#):
>
> Since it’s not showing “Device created successfully’”, the issue is probably caused by `Homey.createDevice()` failing (perhaps if you’re trying to create devices with the same id as an existing device).
> 
> There’s however an issue with that method ([see here](https://github.com/athombv/homey-apps-sdk-issues/issues/330)) that can cause it to fail silently.

Thanks to one of your other replies in another thread i think i found the problem. At least the initial tests shows much better results now.

I had simply forgot to set the type on the button.

```auto
<button type="button" ...

```

And there i was deep in trying to find the issue with promises and async/awaits…

Thanks again Robert!
