A thing that can only be created from a discovery result

Hello,

For a binding of mine, I’m communicating with a system that gives a list of “devices” attached to it, all with a unique identifier that is only discoverable via that API call.
I can thus place the identifier in a property associated to the discovery result and when the user adds the thing from that result, the property is propagated. All is well.

But, when the user adds a new thing via MainUI, it’s impossible for them to figure out which value is to be given for the identifier and the Thing remains in an unconfigured state that cannot be changed.

To avoid this confusing situation, I would like to prevent the thing type to be visible in MainUI so that a user cannot manually create things for it.

Is this at all possible?

I think the preferred way to approach this is not to prevent manual thing creation, but instead

  • To make that identifier value a configuration value instead of a property and
  • To provide a OH console command to list the devices (essentially doing the same thing the discovery does and just printing the output to the console)

That way users can still create the thing manually if they desire, getting the identifier either from the console command or from a manual discovery run.

Propagating a property from discovery result to thing then to thing configuration is something that I already know how to do.

But providing a new console command specific to my addon, that’s something I’d be happy to get an example for.

You need a subclass of AbstractConsoleCommandExtension for that. The hue binding is an example for that.

you could also go to inbox, click the discovery result, and click Copy Thing File Definition.

Well, that turned out quite nice:

openhab> mylight mylight:mylight:3b5544c98c devices
*--------------------------------*---------------------------*---------------------------*--------------*
| Name                           | Device Id                 | Type                      | Has actuator |
*--------------------------------*---------------------------*---------------------------*--------------*
| Battery 1                      | 2DFOFOtzq4ttHav9_msb      | my_smart_battery          | false        |
| Virtual 1                      | rXEYcci1453tycya          | virtual                   | false        |
| Master                         | BD743101F4CF              | asoka_red_plug            | false        |
| Compteur                       | BD743201F4CF              | composite_device          | false        |
| Compteur 1                     | BD743101F4CF_RS_01        | water_heater              | false        |
| Compteur de consommation       | JpB45678fRG96ZZZ          | asoka_electric_counter    | false        |
| Compteur de production         | AAAATJDhZZZZZZZZ          | production_counter        | false        |
| Compteur de production 1       | 1111c1I001234567          | production_counter        | false        |
| Relais                         | BD743301F4CF              | water_heater              | true         |
*--------------------------------*---------------------------*---------------------------*--------------*