Skip to content
José Antonio Jiménez Campos edited this page Apr 17, 2023 · 44 revisions

A fan service

This service was implemented in firmware version 1.7.0

Type Service Type
65 Fan

The following configuration is available for fans:

Section Key Description
Actions "0", "1", etc. The actions performed by the service
Binary 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
ICMP Ping Inputs "q[n]" & "p[n]" Ping inputs that manage service state
Wildcard Actions "y[n]" Perform an action when an service reaches a target value
Service Notifications "m" Notifications sent by another service
Initial Lock State "ks" Lock state at boot
Initial State "s" State a switch service enters on boot
Speed Step "e" Change in speed for each speed increment action
Actions on Boot "xa" Enable / Disable execution of service actions on boot
Service Characteristics

Example

{
  "c":{"io":[[[13],3],[[12,14,15],2],[[0,9],6,1]],"l":13,"b":[{"g":0,"t":5}]},
  "a":[{
    "t":65,
    "0":{"r":[{"g":15},{"g":12},{"g":14}]},
    "y0":[
      {"v": 1, "0":{"r":[{"g":15,"v":1,"i":0.5},{"g":12},{"g":14,"i":0.6}]} },
      {"v":33, "0":{"r":[{"g":15,"v":1,"i":0.5},{"g":12,"i":0.6},{"g":14,"i":0.6}]} },
      {"v":67, "0":{"r":[{"g":15,"v":1},{"g":12},{"g":14}]} }
    ],
    "es":[{
      "t":1,
      "1":{"r":[{"g":9}]},
      "0":{"r":[{"g":9,"v":1}]},
      "b":[{"g":0}]
    }]
    }
  ]
}

This is an example of a Sonoff iFan03 ("t":65). The fan speed is controlled using GPIOs 15, 12 and 14. The button is connected to GPIO 0 and the on/off relay is connected to GPIO 9. A wildcard action ("y0") is defined to control the speed of the fan. Each step change in the value monitored by the wildcard action changes the fan control GPIO lines to adjust its speed.

Actions

Key Action Description
"0" Off The default action after boot unless the Initial State has been set
"1" On

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

Speed Step

The Speed Step option is used to define the number of speed steps the fan has. When a request is made to increment or decrement the fan speed then the next or previous step in speed will be selected.

Speed Step is defined by the "e" key contained within the service object.

Key Value Description
"e" 100 (default)
1 to 100 Integer value specifying percentage or step change on each speed change request

Setting the Speed Step to a value of 3 gives the fan three speeds, plus stop. When viewing the fan speed from within the Home App the fan service will show speeds of 0%, 33%, 66% & 100% depending on which speed step has been selected.

Service Notifications

The list of Service Notifications "m" values supported are:

Value Notification
0 Fan OFF (default)
101 Fan ON
1 to 100 Set fan target speed
-100 to -1 Increase fan target speed
-200 to -101 Decrease fan target speed (-100)
-201 Reset inching timer

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

Digital Inputs

Digital Inputs "b" are supported by this service.

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

State and Status Inputs

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

Key Action
"f0" Set service state and perform action "0" (Off)
"f1" Set service state and perform action "1" (On)
"g0" Set service state to Off
"g1" Set service state to On

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" Set service state and perform action "0" (Off)
"p1" Set service state and perform action "1" (On)
"q0" Set service state to Off
"q1" Set service state to On

Refer to ICMP Ping Inputs for more detail.

Wildcard Actions

Wildcard Actions "y[n]" are supported by this service. The supported list is:

Key Action
"y0" Trigger action when accessory reaches a specific fan speed

Wildcard actions cam be mapped to each of the Speed Steps. For example, if 3 Speed Steps have been defined ("e":3) then wildcard actions can be set for 0, 1, 2 and 3.

Refer to Wildcard Actions for more detail.

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)

Initial State

The Initial State key is supported by this service. Refer to Initial State for details of the available values.

Service Characteristics

Characteristic Description
0 On / Off
1 Rotation speed
Clone this wiki locally