# Need help with capabilities -\> listner

**URL:** https://community.homey.app/t/need-help-with-capabilities-listner/124783
**Category:** Developers
**Created:** [December 20, 2024, 11:44am UTC](https://community.homey.app/t/need-help-with-capabilities-listner/124783 "2024-12-20T11:44:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![H\_van\_Barneveld](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/h_van_barneveld/32/18371_2.png) [@H\_van\_Barneveld](https://community.homey.app/u/H_van_Barneveld)
#### Post date: [December 20, 2024, 11:44am UTC](https://community.homey.app/t/need-help-with-capabilities-listner/124783/1 "2024-12-20T11:44:46Z")

</div>

hello,

i really want to connect our heatpump to homey. Therefor i start my own ‘development’ . what means i try to learn and copy from other existing apps/integrations.  
Today i can connect the modbus IP interface, i can read differrent registers. also i add to different capabilities. ( picker to set mode & thermostat to adjust settings.) but from this point i miss the examples, knoledge how to proceed.

the picker i can set another mode but i do not know how to ensure the picker gets the active value from the modbusregister. when i open the device the picker doesn’t show the active setting. are there examples available to find out how to configure this?

The same question for the thermostat. for this i also am looking for code that belongs to this UI (capabilitylister ) i guess.  
Can somebody help me to proceed ?

Kind regards,  
Henk

---

<div class="post-metadata">

### Author: ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)
#### Post date: [December 20, 2024, 12:09pm UTC](https://community.homey.app/t/need-help-with-capabilities-listner/124783/2 "2024-12-20T12:09:15Z")

</div>

I just use the Modbus app and Advanced Virtual Device to display (and set) values. Works OK for me.

---

<div class="post-metadata">

### Author: ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)
#### Post date: [December 20, 2024, 5:20pm UTC](https://community.homey.app/t/need-help-with-capabilities-listner/124783/3 "2024-12-20T17:20:05Z")

</div>

You will need to poll the registers to fetch the values and set them on the capability using setCapabilityValue(‘name\_of\_capability’, value).

You could use a timer to poll registers, e.g. homey.setInterval or homey.setTimeout.

---

<div class="post-metadata">

### Author: ![H\_van\_Barneveld](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/h_van_barneveld/32/18371_2.png) [@H\_van\_Barneveld](https://community.homey.app/u/H_van_Barneveld)
#### Post date: [December 22, 2024, 4:17pm UTC](https://community.homey.app/t/need-help-with-capabilities-listner/124783/4 "2024-12-22T16:17:36Z")

</div>

Hello Adrian, or anyone els,

I have working all weekend to get it work and making some progress. however iám still struggling. i created an lister that registrate all changes. after using the picker i see the new vallue in the log. when i tried to write this new value to the right register it is not accepted. When using a modbus testtool i’am able to read and set the value by using FC 3 or FC 6.

I’am using code like below. do you have any idea how to solve this.

// Register capability listener for Operation\_mode  
this.registerCapabilityListener(‘Operation\_mode’, async (value) =\> {  
this.log(‘Changes to :’, value);  
this.log(‘Modbus register to write to is:’, OPERATION\_MODE\_ADDRESS);

```
  // Voeg een controle toe om te bevestigen dat de waarde geldig is

  // Lees de huidige waarde van het holding register
  try {
    const currentRegister = await this._client.readHoldingRegisters(OPERATION_MODE_ADDRESS, 1);
    const currentValue = currentRegister.response._body.valuesAsBuffer.readUInt16BE(0);
    this.log(`Current value in register ${OPERATION_MODE_ADDRESS} is: ${currentValue}`);
  } catch (error) {
    this.error(`Error reading current value from operation mode register: ${error.message}`);
    return;
  }

  // Voeg een vertraging van 2 seconden toe
  await this.delay(2000);
  this.log('delay2000ms');

  // Log de waarde en het adres die worden geschreven
  this.log(`Writing value ${value} to operation mode register at address ${OPERATION_MODE_ADDRESS}`);

  // Schrijf de nieuwe waarde naar het Modbus-register
  try {
    const result = await this._client.writeSingleRegister(OPERATION_MODE_ADDRESS, value);
    this.log(`Written value ${value} to operation mode register ${OPERATION_MODE_ADDRESS}`, result);
  } catch (error) {
    this.error(`Error writing to operation mode register: ${error.message}`);
  }
});

```

}

---

<div class="post-metadata">

### Author: ![H\_van\_Barneveld](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/h_van_barneveld/32/18371_2.png) [@H\_van\_Barneveld](https://community.homey.app/u/H_van_Barneveld)
#### Post date: [December 22, 2024, 8:41pm UTC](https://community.homey.app/t/need-help-with-capabilities-listner/124783/5 "2024-12-22T20:41:17Z")

</div>

Solved
