What form should be `temperature` attribute in Schema connector to refresh states?

I’m using capabilities with Schema connector, and I met problem about states.


As we know, we can use capability like below.

capability

"attributes": {
    "switch": {
        "schema": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "value": {
                    "title": "SwitchState",
                    "type": "string",
                    "enum": [
                        "on",
                        "off"
                    ]
                }
            },
            "required": [
                "value"
            ]
        }
    }
}

part of StateRefresh response

"states": [{
    "component": "main",
    "capability": "st.switch",
    "attribute": "switch",
    "value": "on"
}]

And we can do like this if there are many fields under attributes field.

capability

"attributes": {
    "hue": {
        "schema": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "value": {
                    "title": "PositiveNumber",
                    "type": "number",
                    "minimum": 0
                }
            }
        }
    },
    "saturation": {
        "schema": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "value": {
                    "title": "PositiveNumber",
                    "type": "number",
                    "minimum": 0
                }
            }
        }
    }
}

part of StateRefresh response

"states": [
    {
        "component": "main",
        "capability": "st.colorControl",
        "attribute": "hue",
        "value": 0
    },
    {
        "component": "main",
        "capability": "st.colorControl",
        "attribute": "saturation",
        "value": 0
    }
]

But what should I do if there are multiple field under properties?

capability

"attributes": {
    "coolingSetpoint": {
        "schema": {
            "title": "Temperature",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "value": {
                    "title": "TemperatureValue",
                    "type": "number",
                    "minimum": -460,
                    "maximum": 10000
                },
                "unit": {
                    "title": "TemperatureUnit",
                    "type": "string",
                    "enum": [
                        "F",
                        "C"
                    ]
                },
                "constraints": {
                    "title": "NumberConstraint",
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "min": {
                            "type": "number"
                        },
                        "max": {
                            "type": "number"
                        }
                    }
                }
            },
            "required": [
                "value",
                "unit"
            ]
        }
    }
}

I tried below form and others, but didn’t works.

"states": [
    {
        "component": "main",
        "capability": "st.temperatureMeasurement",
        "attribute": "temperature",
        "value": {
            "unit": "C",
            "value": 10
        }
    }
]

I found SmartApp connector API reference, but I couldn’t find about Schema connector API.

1 Like

Hello, @zldxkdlrj_dlcmaldml

Attributes inside the properties are the information about how the capability must be used. Taking the Thermostat Cooling Setpoint as example, we can read the next information:

  1. The value attribute must be a number data type (integer, float, etc.).
  2. The unit attribute must be a string data type following the enum reference.
  3. The constraints attribute is declaring that the limits for the value attribute are referenced as numbers.

Finally, we can read at the required attribute that the capability’s value/state must be expressed using the value and unit parameters at our StateRefresh/Command responses.

Temperature Measurement state for example, can be configured as following:

{
    "component": "main",
    "capability": "st.temperatureMeasurement",
    "attribute": "temperature",
    "value": 10,
    "unit": "C"
}

Best regards,
Erick.

1 Like

Works perfectly! Thanks a lot.

1 Like