A switch entity is the simplest actuator in Home Assistant and the easiest one to trust too early. Sending a command and seeing a state change are two different events, and an automation that treats them as one will report success while the relay is still open.

Before starting

Use a switch already configured and working in Home Assistant, preferably a low-risk test load. This route supports switch entities only and makes no model-specific compatibility claim. Do not use it for locks, machinery or other safety-critical control. Device integrations and permissions remain Home Assistant responsibilities.

Setup

Follow the local workbench setup. In the copied configuration, select live mode and retain only bench-switch. Set its entity to your actual switch entity and configure the Home Assistant WebSocket URL. Store the access token in the IOT_HA_TOKEN environment variable, never in a URL or public configuration.

{
  "mode":"live",
  "homeAssistant":{
    "url":"ws://127.0.0.1:8123/api/websocket",
    "tokenEnv":"IOT_HA_TOKEN"
  },
  "devices":[{
    "id":"bench-switch","route":"ha-switch",
    "entity":"switch.YOUR_ENTITY","staleAfter":3600,
    "allowCommands":false
  }]
}

Use an actual lowercase entity identifier. Loopback refers to the machine running the kit. For another machine, use a trusted secure WebSocket endpoint. Unencrypted LAN access requires explicitly setting allowInsecureLAN to true; never use that option over the public internet.

Read first, then enable control

Start with commands disabled. Verify the initial state and a new state change made through Home Assistant. Stop the kit, enable allowCommands for that one entity and restart only when you are ready to operate the test load. The dashboard offers explicit on and off commands; it cannot call arbitrary services.

Commands have unique request IDs. Repeating the same request does not resend it. The kit waits for a state change with the matching Home Assistant context. Acceptance alone is insufficient. If no matching event arrives within 15 seconds, the command times out; inspect the real device before trying again. Disconnects and process restarts fail pending commands without replaying them. These behaviours have simulated protocol tests, not physical-switch verification.

What the action actually looks like

Underneath, a confirmation loop is two Home Assistant actions and a wait. The call itself is unremarkable:

- alias: "Bench switch on"
  action: switch.turn_on
  target:
    entity_id: switch.bench_load

The confirmation is a separate step that waits for the state you expect, with a timeout so the automation cannot hang forever:

- alias: "Wait for the switch to report on"
  wait_for_trigger:
    - trigger: state
      entity_id: switch.bench_load
      to: "on"
  timeout:
    seconds: 15
  continue_on_error: false

Home Assistant runs actions in order, and a failed action stops the ones after it unless continue on error is set. That default is helpful here: a command that never confirms should stop the sequence rather than let a later step believe the load is on.

Why context matters

A state change on the entity is not automatically proof that this command caused it. Another automation, a physical button or a device-side schedule can change the same entity at the same moment.

That is why the kit matches the Home Assistant context returned by the command to the event it receives. A state change without the matching context is a state change, not a confirmation. If you build the same loop by hand, put a condition on the trigger or compare the context, and treat an unrelated change as unconfirmed.

Entities without real feedback

Some integrations expose a switch the device cannot report on: an infrared blaster, a relay board with no readback, a cloud device that acknowledges the call and nothing else. Home Assistant marks such entities as assumed state, which is why the interface shows separate on and off buttons instead of a toggle.

For these entities a confirmation loop proves only that the integration accepted the command. Say so in the automation name or the log, rather than recording a state that was never observed.

The failure table

Symptom What it means What to check
Command sent, no state change, no error The integration accepted it; the device did not act Device link, local control, power
State changes, then reverts Something else is writing the entity Other automations, device schedule
Timeout on every attempt Wrong entity, or the state you wait for is not the state reported Developer tools, entity history
Works from the UI, fails from the kit Token scope or WebSocket connection Token, URL, reconnect log
Duplicate commands No request ID de-duplication in the caller Implement idempotent request IDs

A test that proves the loop

  1. Disable commands and confirm the kit mirrors a state change made in the Home Assistant UI.
  2. Enable commands for the test entity only.
  3. Send one command and confirm you see both the call and the resulting event.
  4. Unplug the load, send the same command, and confirm the loop times out instead of reporting success.
  5. Restart the kit with a command pending and confirm it fails cleanly rather than replaying.

Step four is the one that separates a confirmation from an assumption, and it is the step most integrations skip.

Resources