Search code examples
azure-iot-central

IoT Central - State values error: Another instance with the same id already exists


I just don't get it.

If I want to define a status, I must be able to refer to a value several times, right?

Sensor value is occupancy with value 0 (Free) or 1 (Occupied). So I have 2 states, but I can only use "occupancy" in the Name it once ...

Regards, Matthias

enter image description here


Solution

  • For better understanding, let's call the State property (such as a device twin reported property) as an Occupancy.

    The following screen snippet shows its declaration, where the Occupancy state property has two states such as the Free and Occupied (Occupancy.Free and Occupancy.Occupied):

    enter image description here

    and its declaration in the Interface instance of the Capability Model (in my example):

    {
      "@id": "urn:rigado:interfaces:S1_Sensor:Occupancy:3",
      "@type": [
        "Property",
        "SemanticType/State"
      ],
      "displayName": {
        "en": "Occupancy"
      },
      "name": "Occupancy",
      "schema": {
        "@id": "urn:rigado:interfaces:S1_Sensor:Occupancy:xkuwdf9p:3",
        "@type": "Enum",
        "valueSchema": "integer",
        "enumValues": [
          {
            "@id": "urn:rigado:interfaces:S1_Sensor:Occupancy:xkuwdf9p:Free:3",
            "@type": "EnumValue",
            "displayName": {
              "en": "Free"
            },
            "enumValue": 0,
            "name": "Free"
          },
          {
            "@id": "urn:rigado:interfaces:S1_Sensor:Occupancy:xkuwdf9p:Occupied:3",
            "@type": "EnumValue",
            "displayName": {
              "en": "Occupied"
            },
            "enumValue": 1,
            "name": "Occupied"
          }
        ]
      }
    }
    

    As you can see in the above schema, the names in the enumValues array must be unique, that is a reason why you get the error, when you used the same enum name.

    Note, that the device can change the state of the Occupancy property between the values such as Free (0) and Occupied (1).

    For testing purpose can be used the Azure IoT Hub Tester, see the following screen snippet:

    enter image description here

    The following screen snippets show changing a state in the Occupancy reported property on the PnP device (sensor3) connected to the IoTC App:

    Publishing a Occupancy state:

    enter image description here

    Get the device twin properties:

    enter image description here

    and the IoTC App Dashboard for Occupancy State property:

    enter image description here

    As you can see, the about state has a value Free.