Sensors

The mobile_app component supports exposing custom sensors that can be managed entirely via your app.

Registering a sensor

All sensors must be registered before they can get updated. You can only register one sensor at a time, unlike updating sensors.

To register a sensor, make a request to the webhook like this:

{
"data": {
"attributes": {
"foo": "bar"
},
"device_class": "battery",
"icon": "mdi:battery",
"name": "Battery State",
"state": "12345",
"type": "sensor",
"unique_id": "battery_state",
"unit_of_measurement": "%"
},
"type": "register_sensor"
}

The valid keys are:

KeyTypeRequiredDescription
attributesobjectNoAttributes to attach to the sensor
device_classstringNoOne of the valid device classes. Binary Sensor Classes, Sensor Classes
iconMaterial Design Icon (string)NoMust be prefixed mdi:. If not provided, default value is mdi:cellphone
namestringYesThe name of the sensor
statebool, float, int, stringYesThe state of the sensor
typestringYesThe type of the sensor. Must be one of binary_sensor or sensor
unique_idstringYesAn identifier unique to this installation of your app. You'll need this later. Usually best when its a safe version of the sensor name
unit_of_measurementstringNoThe unit of measurement for the sensor

Sensors will appear as soon as they are registered.

Updating a sensor

Once a sensor has been registered, you need to update it. This is very similar to registering it, but you can update all your sensors at the same time.

For example, to update the sensor we registered above, you would send this:

{
"data": [
{
"attributes": {
"hello": "world"
},
"icon": "mdi:battery",
"state": 123,
"type": "sensor",
"unique_id": "battery_state"
}
],
"type": "update_sensor_states"
}

Only some of the keys are allowed during updates:

KeyTypeRequiredDescription
attributesobjectNoAttributes to attach to the sensor
iconMaterial Design Icon (string)NoMust be prefixed mdi:
statebool, float, int, stringYesThe state of the sensor
typestringYesThe type of the sensor. Must be one of binary_sensor or sensor
unique_idstringYesAn identifier unique to this installation of your app. You'll need this later. Usually best when its a safe version of the sensor name