Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Switch Entity

A switch entity can turn something on or off and the current state should be readable by the integration driver.

If the state can't be read, the readable option property can be set to false. This should be avoided whenever possible, because the remote either has to assume the current state, or the UI needs to ask the user for the current state.

If the switch controls a light source, then the light entity is usually a better choice.

Features

NameRWDescription
on_offDefault feature of a switch. Always present, even if not specified.
toggleToggle support. If there's no native support, the remote will use the current state of the switch to send the corresponding on or off command.

Attributes

Entity attributes are controlled by features. Multiple features can act on the same attribute. See Events on how to notify the remote about an updated attribute. The attributes have to be listed as properties under attributes with their current value.

AttributeFeaturesTypeValuesDescription
stateon_offenumStatesState of the switch, it's either on or off.
toggleToggle inverts the current state. If the driver doesn't provide the toggle feature, the remote uses the current value and calls on or off.

States

The switch entity provides the following entity state values:

ValueDescription
ONThe switch is on.
OFFThe switch is off.

See common entity states.

Device classes

Optional switch type. This can be used by the UI to represent the entity with a different icon, behaviour etc.

NameDescription
outletThe switch represents a switchable power outlet.
switchGeneric switch.

Options

NameTypeDefaultDescription
readablebooleantrueIf set to false the current state of the switch cannot be read. This will make the switch stateless and the UI might ask the user for the current state.

Integration API

Commands

The integration driver has to implement a handler for the entity_command message to process the following command requests in msg_data.cmd_id.

cmd_idParametersDescription
on-Put the switch in the on state.
off-Put the switch in the off state.
toggle-Toggle the current switch state, either from on -> off or from off -> on.

Events

The entity_change event must be emitted by the integration driver if the state or an attribute of the switch changes.

The following attributes must be included:

AttributeDescription
stateNew entity state.

Command examples

on

{
  "kind": "req",
  "id": 124,
  "msg": "entity_command",
  "msg_data": {
    "entity_type": "switch",
    "entity_id": "switch-1",
    "cmd_id": "on"
  }
}

off

{
  "kind": "req",
  "id": 124,
  "msg": "entity_command",
  "msg_data": {
    "entity_type": "switch",
    "entity_id": "switch-1",
    "cmd_id": "off"
  }
}

toggle

{
  "kind": "req",
  "id": 124,
  "msg": "entity_command",
  "msg_data": {
    "entity_type": "switch",
    "entity_id": "switch-1",
    "cmd_id": "toggle"
  }
}

Event examples

Switched on

{
  "kind": "event",
  "msg": "entity_change",
  "cat": "ENTITY",
  "msg_data": {
    "entity_type": "switch",
    "entity_id": "switch-1",
    "attributes": {
      "state": "on"
    }
  }
}

Switched off

{
  "kind": "event",
  "msg": "entity_change",
  "cat": "ENTITY",
  "msg_data": {
    "entity_type": "switch",
    "entity_id": "switch-1",
    "attributes": {
      "state": "off"
    }
  }
}