You will obviously need something that generates an event to call your code. That could be a flow action card for example (or by polling for information from the physical device if you had one).
In the flow action you set the capability value. So, in your app onInit function you would register the flow card something like this:
let change_my_capability_action = new Homey.FlowCardAction( 'change_my_capability_action' );
my_action
.register()
.registerRunListener( async ( args, state ) =>
{
return await args.device.triggerCapabilityListener( 'enum_no_on_off_capability', args.on_off );
});
app.json
"flow": {
"actions": [
{
"title": {
"en": "Switch On or Off"
},
"titleFormatted": {
"en": "Turn [[on_off ]] the lights"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=myDeviceID"
},
{
"type": "dropdown",
"name": "on_off ",
"values": [
{
"id": "off",
"title": {
"en": "Off"
}
},
{
"id": "on",
"title": {
"en": "On"
}
}
]
}
],
"id": "change_my_capability_action"
},
]
}