Need help with creating an dynamic pairing page

I’m working adding support for ESPhome devices.
Since the ESPhome API doesn’t provide details about sensors (see code below), the users should be able to select the correct corresponding Homey capability manually.

I’ve been searching for hours on Github in Homey code but haven’t been successfull.

Anyone knows or willing to point me to an pairing page which dynamically creates an list so the user can select the correct capability.

deviceInfo {
  '148960415': {
    config: {
      objectId: 'woonkamer_co2_eco2',
      key: 148960415,
      name: 'Woonkamer CO2 eCO2',
      uniqueId: 'esp32-woonkamer-co2sensorwoonkamer_co2_eco2',
      icon: 'mdi:molecule-co2',
      unitOfMeasurement: 'ppm',
      accuracyDecimals: 0,
      forceUpdate: false
    },
    name: 'Sensor',
    type: 'Sensor',
    unit: 'ppm'
  },
  '503450186': {
    config: {
      objectId: 'woonkamer_co2_screen_state',
      key: 503450186,
      name: 'Woonkamer CO2 Screen state',
      uniqueId: 'esp32-woonkamer-co2switchwoonkamer_co2_screen_state',
      icon: '',
      assumedState: false
    },
    name: 'Switch',
    type: 'Switch',
    unit: ''
  },
  '1503850894': {
    config: {
      objectId: 'woonkamer_co2_luchtdruk',
      key: 1503850894,
      name: 'Woonkamer CO2 Luchtdruk',
      uniqueId: 'esp32-woonkamer-co2sensorwoonkamer_co2_luchtdruk',
      icon: '',
      unitOfMeasurement: 'hPa',
      accuracyDecimals: 1,
      forceUpdate: false
    },
    name: 'Sensor',
    type: 'Sensor',
    unit: 'hPa'
  },
  '1902342132': {
    config: {
      objectId: 'woonkamer_co2_temperatuur',
      key: 1902342132,
      name: 'Woonkamer CO2 Temperatuur',
      uniqueId: 'esp32-woonkamer-co2sensorwoonkamer_co2_temperatuur',
      icon: '',
      unitOfMeasurement: '°C',
      accuracyDecimals: 1,
      forceUpdate: false
    },
    name: 'Sensor',
    type: 'Sensor',
    unit: '°C'
  },
  '2577714310': {
    config: {
      objectId: 'woonkamer_co2_helderheid',
      key: 2577714310,
      name: 'Woonkamer CO2 Helderheid',
      uniqueId: 'esp32-woonkamer-co2sensorwoonkamer_co2_helderheid',
      icon: '',
      unitOfMeasurement: 'lx',
      accuracyDecimals: 1,
      forceUpdate: false
    },
    name: 'Sensor',
    type: 'Sensor',
    unit: 'lx'
  },
  '2581835948': {
    config: {
      objectId: 'woonkamer_co2_relatieve_luchtvochtigheid',
      key: 2581835948,
      name: 'Woonkamer CO2 Relatieve luchtvochtigheid',
      uniqueId: 'esp32-woonkamer-co2sensorwoonkamer_co2_relatieve_luchtvochtigheid',
      icon: '',
      unitOfMeasurement: '%',
      accuracyDecimals: 1,
      forceUpdate: false
    },
    name: 'Sensor',
    type: 'Sensor',
    unit: '%'
  },
  '3044390021': {
    config: {
      objectId: 'woonkamer_co2_restart',
      key: 3044390021,
      name: 'Woonkamer CO2 Restart',
      uniqueId: 'esp32-woonkamer-co2switchwoonkamer_co2_restart',
      icon: 'mdi:restart',
      assumedState: false
    },
    name: 'Switch',
    type: 'Switch',
    unit: ''
  },
  '3634464311': {
    config: {
      objectId: 'woonkamer_co2_dauw_punt',
      key: 3634464311,
      name: 'Woonkamer CO2 Dauw punt',
      uniqueId: 'esp32-woonkamer-co2sensorwoonkamer_co2_dauw_punt',
      icon: 'mdi:thermometer-alert',
      unitOfMeasurement: '°C',
      accuracyDecimals: 1,
      forceUpdate: false
    },
    name: 'Sensor',
    type: 'Sensor',
    unit: '°C'
  },
  '3973247065': {
    config: {
      objectId: 'woonkamer_co2_total_volatile_organic_compound',
      key: 3973247065,
      name: 'Woonkamer CO2 Total Volatile Organic Compound',
      uniqueId: 'esp32-woonkamer-co2sensorwoonkamer_co2_total_volatile_organic_compound',
      icon: 'mdi:radiator',
      unitOfMeasurement: 'ppb',
      accuracyDecimals: 0,
      forceUpdate: false
    },
    name: 'Sensor',
    type: 'Sensor',
    unit: 'ppb'
  },
  usesPassword: false,
  name: 'esp32-woonkamer-co2',
  macAddress: '10:52:1C:68:93:C8',
  esphomeVersion: '2021.10.3',
  compilationTime: 'Nov 17 2021, 13:44:37',
  model: 'esp-wrover-kit',
  hasDeepSleep: false,
  ip4: '192.168.0.61',
  port: 6053
}

If you let the user select the capabilities how do you plan to map the data from the API to update the capabilities, etc?

The SmartThings app tries to map specific properties from the API to Homey capabilities so might be useful to you.

1 Like

Every API responce has an unique id.

ESPhome only gives as type sensor, that’s all.

So I guess you want to let the user select the device and then show a page that list all the objects along with a method to let them choose one of the predefined Homey capabilities for each one?
In which case you would need to create an additional custom pairing page to add after the select device option (and limit the select device to a single selection).
My ONVIF app shows how detecting which device is selected can be handled. My Version Checker app has an example of building a list on the fly.
None of my apps are probably the elegant way to do things as I am not a web designer or an expert on JavaScript, but in some ways that means they are simple and easier to follow.

1 Like

Yes, that’s exactly what I meant to say.
Thanks, I’ll look into it.