Skip to content

Sensors

José Antonio Jiménez Campos edited this page Jul 16, 2022 · 47 revisions

Many HomeKit sensors have the same configurable options. The common sensors are defined here along with their available options.

Type Service Type
5 Contact Sensor
6 Occupancy Sensor
7 Leak Sensor
8 Smoke Sensor
9 Carbon Monoxide Sensor
10 Carbon Dioxide Sensor
11 Filter Change Sensor
12 Motion Sensor

The following configuration is available for sensors:

Section Key Description
Actions "0", "1" etc. The actions performed by the service
Digital Inputs "b" GPIOs that invoke specific actions
Inching Time "i" Time period before returning service to previous state
State & Status Inputs "f[n]" & "g[n]" Inputs that manage service state
Service Notifications "m" Notifications to send to another service
Initial Lock State "ks" Lock state at boot
Actions on Boot "xa" Enable / Disable execution of service actions on boot
Data History Characteristics

Example

{
  "c": { "l": 13},
  "a": [{
    "t": 12,
    "i": 10,
    "0": { "r": [{ "g": 16, "v": 0 }] },
    "1": { "r": [{ "g": 16, "v": 1 }] },
    "f1": [{ "g": 14 }]
  }]
}

This is an example of a Sonoff Basic unit with a motion sensor ("t": 12) connected to GPIO 14 ("f1": [{ "g": 14 }]) and an LED connected to GPIO 13 ("l": 13).

The motion sensor service ("t": 12) causes action "1" to be performed when activated ("f1"). 10 seconds later action "0" will be performed because of the inching time option ("i": 10)

NOTE: The following options are not needed in this example as they are the default options but are included to make the example more readable: "t": 1 & "v": 0

Digital Inputs

Digital Inputs "b" are supported by this service.

See Digital Inputs for details on how to define this mandatory option.

Actions

A sensor has two actions.

Action State Description
"0" Deactivated This action should be performed when sensor is deactivated. This is the default action on boot.
"1" Activated This action should be performed when sensor is activated

The Digital Outputs "r": [{}] for each should be configured to attain the desired state.

Service Notifications

The list of notifications "m" supported by a sensor are as follows:

Value Notification
0 Sensor DEACTIVATED (default)
1 Sensor ACTIVATED
2 Sensor status only DEACTIVATED
3 Sensor status only ACTIVATED
4 Toggle current state
5 Toggle status only
-1 Reset inching timer

See the general Service Notifications section for details of how to configure these notifications.

Initial Lock State

The Initial Lock State about Service and Physical controls.

Key Value Notification
"ks" 0 All locked
1 Service unlocked. Physical controls locked
2 Service locked. Physical controls unlocked
3 All unlocked (default)

State and Status Inputs

State inputs "f[n]" & Status Inputs "g[n]" are supported by this service. The supported list is:

Key Action
"f0" Perform action "0" (Deactivate)
"f1" Perform action "1" (Activate)
"g0" Set service state to Deactivated
"g1" Set service state to Activated

Refer to State Inputs for more detail and examples.

ICMP Ping Inputs

ICMP Ping inputs "p[n]" and "q[n]" are supported by this service. The supported list is:

Key Action
"p0" Perform action "0" (Deactivate)
"p1" Perform action "1" (Activate)
"q0" Set service state to Deactivated
"q1" Set service state to Activated

Refer to ICMP Ping Inputs for more detail.

Data History Characteristics

Characteristic Description
0 Sensor State
Clone this wiki locally