Adding internal static property to my new add-on

Hi
I’m try to build new binding add-on that integrate with some water consumption service
This service API require to provide some device id (some generate number with 16 digits) for each call.

Now what I’m try to do is to generate this number and save it locally on hard disk so every machine restart or openhab service restart I will use the same device id

I didn’t find any example or document how to do that.
(binding.xml is not good because there is no need to reveal this data to in client side)

I’m using openhab 2

Look at the Nest binding. I’m not sure if it does this itself or a library it uses does it, but it saves similar information to ~openhab/.java/preferences/randonsetof characters

The cloud connector binding saves a file in userdata/my openHAB/secret and userdata/uuid for connecting to my openHAB.org.

Other bindings will save things to other folders in userdata as well.

Saving the deviceId as a Thing configuration parameter would also allow for file based configurations using a .things file.

That may be true for the current Nest OH1/OH2 versions. After PR #2698 gets merged it will no longer be using a separate file.

The Nest smoke_detector in this PR for instance has a deviceId. You define these configuration parameters in thing type definition XML files. See for instance the new smoke-detector.xml file.

It contains a reference to a:
<config-description-ref uri="thing-type:nest:device" />

Which is defined in the config.xml:

    <config-description uri="thing-type:nest:device">
        <parameter name="deviceId" type="text" required="true">
            <label>Device ID</label>
        </parameter>
    </config-description>

This will make the framework save the parameter and the UI show the configuration parameter. It also allows for a file based Thing configuration as outlined in the new Nest binding documentation.

Bridge nest:account:demo_account [ productId="8fdf9885-ca07-4252-1aa3-f3d5ca9589e0", productSecret="QITLR3iyUlWaj9dbvCxsCKp4f", accessToken="c.6rse1xtRk2UANErcY0XazaqPHgbvSSB6owOrbZrZ6IXrmqhsr9QTmcfaiLX1l0ULvlI5xLp01xmKeiojHqozLQbNM8yfITj1LSdK28zsUft1aKKH2mDlOeoqZKBdVIsxyZk4orH0AvKEZ5aY", refreshInterval="120" ] {
    camera         fish_cam           [ deviceId="qw0NNE8ruxA9AGJkTaFH3KeUiJaONWKiH9Gh3RwwhHClonIexTtufQ" ]
    smoke_detector hallway_smoke      [ deviceId="Tzvibaa3lLKnHpvpi9OQeCI_z5rfkBAV" ]
    structure      home               [ structureId="20wKjydArmMV3kOluTA7JRcZg8HKBzTR-G_2nRXuIN1Bd6laGLOJQw" ]
    thermostat     living_thermostat  [ deviceId="ZqAKzSv6TO6PjBnOCXf9LSI_z5rfkBAV" ]
}

For more information on XML configurations, see also the Eclipse SmartHome XML Reference Guide.