Home assistant

Home Assistant Toggle Switch: Complete Guide 2026

On this page
    TL;DR: A Home Assistant toggle switch for a “dumb” device is three pieces: a Toggle helper (input_boolean) you tap on the dashboard, two scripts that send the real on and off commands, and one automation that runs the right script when the toggle changes. It works for anything you can send a command to: IR (infrared, like a TV remote) or RF (radio, like many fan remotes) through a Broadlink, a REST call, MQTT, or a smart plug.

    Updated November 2026 for Home Assistant 2026.10. All YAML on this page (YAML is the plain text format Home Assistant uses for its settings) uses the current syntax (triggers:, actions: and action: instead of the old service:), so you can paste it straight into a recent install.

    Some devices will never get a proper integration. A fan with an RF remote, an old air conditioner, a projector, a cheap LED strip with an IR remote. Home Assistant can still control them, it just needs a bit of glue. This guide builds that glue step by step, then covers dashboard cards, schedules, voice control and the template switch alternative.

    What you need

    A running Home Assistant install (see our Raspberry Pi install guide if you are starting out) and some way to send the command. For IR and RF devices that usually means a learning remote like the Broadlink RM4 Pro (IR and RF) or the cheaper RM4 mini (IR only). If the device only needs power cut and restored, a plain Zigbee smart plug does the job and you can skip the scripts entirely.

    What you needAqara Wireless Mini Switch (Zigbee button)A physical button for any helper, scene or toggle. Single, double and long press.Check price on AliExpressAthom smart plug (ESPHome or Tasmota preflashed)Wi-Fi plug with power metering and no cloud. Flashed and ready for Home Assistant.Check price on AliExpress

    The three pieces and how they fit

    • Toggle helper (input_boolean): a virtual on/off switch that lives only inside Home Assistant. It stores a state and nothing else.
    • Scripts: the actions that actually talk to the device, one for on and one for off.
    • Automation: watches the toggle and runs the matching script when it flips.

    The flow is simple: you tap the toggle, its state changes, the automation fires, the script sends the command, the device reacts.

    Step 1: Learn the remote codes

    Skip this step if your device already has an action you can call (MQTT, REST, a smart plug). For a Broadlink, first add it under Settings > Devices & services > Add integration > Broadlink. Then open Developer tools > Actions, switch to YAML mode and run:

    action: remote.learn_command
    target:
      entity_id: remote.living_room_rm4_pro
    data:
      device: bedroom_fan
      command:
        - power_on
        - power_off
      command_type: rf

    A notification tells you when to press each button on the original remote. Drop command_type: rf for infrared devices. Home Assistant stores the learned codes under the name you gave, so your scripts can refer to bedroom_fan and power_on instead of long Base64 strings.

    AliExpress deals

    Many fans have a single power button that toggles. In that case learn one command (for example power) and have both scripts send it. Keep in mind that Home Assistant then cannot know the real state if someone uses the physical remote.

    Step 2: Create the on and off scripts

    Create them in the UI under Settings > Automations & scenes > Scripts, or paste this into scripts.yaml:

    bedroom_fan_on:
      alias: Bedroom fan on
      icon: mdi:fan
      mode: single
      sequence:
        - action: remote.send_command
          target:
            entity_id: remote.living_room_rm4_pro
          data:
            device: bedroom_fan
            command: power_on
    
    bedroom_fan_off:
      alias: Bedroom fan off
      icon: mdi:fan-off
      mode: single
      sequence:
        - action: remote.send_command
          target:
            entity_id: remote.living_room_rm4_pro
          data:
            device: bedroom_fan
            command: power_off

    Replace remote.living_room_rm4_pro with your own remote entity. An entity is Home Assistant’s name for one thing it can see or control, like a light, a sensor or a remote. Run each script once from the Scripts list to confirm the device reacts before you go further.

    Step 3: Create the Toggle helper

    The UI route is the easiest: go to Settings > Devices & services > Helpers, click Create helper, pick Toggle, name it “Bedroom fan” and choose an icon. Home Assistant creates input_boolean.bedroom_fan.

    Creating a Toggle helper in the Home Assistant Helpers screen

    If you prefer YAML, add this to configuration.yaml and restart:

    input_boolean:
      bedroom_fan:
        name: Bedroom fan
        icon: mdi:fan

    Leave out initial:. Without it the helper remembers its last state across restarts, which is what you want for something that mirrors a real device.

    Step 4: Link them with an automation

    This automation uses trigger IDs and a to: state, so it only fires on a real on or off change and ignores restarts where the helper briefly shows as unavailable:

    alias: Bedroom fan follows toggle
    mode: queued
    triggers:
      - trigger: state
        entity_id: input_boolean.bedroom_fan
        to: "on"
        id: turned_on
      - trigger: state
        entity_id: input_boolean.bedroom_fan
        to: "off"
        id: turned_off
    actions:
      - choose:
          - conditions:
              - condition: trigger
                id: turned_on
            sequence:
              - action: script.bedroom_fan_on
          - conditions:
              - condition: trigger
                id: turned_off
            sequence:
              - action: script.bedroom_fan_off

    Paste it in Settings > Automations & scenes > Create automation > Create new automation, then open the three-dot menu and choose Edit in YAML. If you already have older automations with platform: and service:, they still work. The new keys are just the current standard, and the editor converts old ones when you save them.

    Step 5: Put the toggle on your dashboard

    A tile card is the cleanest option and toggles on tap by default:

    type: tile
    entity: input_boolean.bedroom_fan
    name: Bedroom fan
    icon: mdi:fan
    tap_action:
      action: toggle

    For a bigger square button, use a button card instead:

    type: button
    entity: input_boolean.bedroom_fan
    name: Bedroom fan
    show_state: true
    tap_action:
      action: toggle

    Visually they differ, functionally they do the same thing. Pick whichever matches the rest of your dashboard. If you want one button that flips several entities at once, we have a separate guide on toggling several entities with one helper.

    Useful variations

    Voice control

    Expose input_boolean.bedroom_fan under Settings > Voice assistants > Expose. “Turn on bedroom fan” from Assist, Alexa or Google Assistant flips the helper, and your automation does the rest.

    Turn it on at bedtime

    alias: Bedroom fan at bedtime
    triggers:
      - trigger: time
        at: "22:00:00"
    actions:
      - action: input_boolean.turn_on
        target:
          entity_id: input_boolean.bedroom_fan

    Turn it on when the room gets warm

    alias: Bedroom fan when warm
    triggers:
      - trigger: numeric_state
        entity_id: sensor.bedroom_temperature
        above: 26
        for: "00:05:00"
    actions:
      - action: input_boolean.turn_on
        target:
          entity_id: input_boolean.bedroom_fan

    The for: line stops the fan from flapping when the temperature hovers right at the threshold. Automating the helper instead of the script keeps the dashboard state correct no matter what turned the fan on.

    Template switch: the one-entity alternative

    A template switch wraps the two scripts into a single switch entity, so you can skip the automation. It is cleaner when Home Assistant is the only thing controlling the device. You can create one in the UI (Helpers > Create helper > Template > Switch) or in YAML with the current template: format:

    template:
      - switch:
          - name: Bedroom fan
            unique_id: bedroom_fan_switch
            state: "{{ is_state('input_boolean.bedroom_fan', 'on') }}"
            turn_on:
              - action: input_boolean.turn_on
                target:
                  entity_id: input_boolean.bedroom_fan
              - action: script.bedroom_fan_on
            turn_off:
              - action: input_boolean.turn_off
                target:
                  entity_id: input_boolean.bedroom_fan
              - action: script.bedroom_fan_off

    The old switch: - platform: template style is the legacy format. If your config still uses it, move it to the template: block, since Home Assistant has been warning about the legacy template entity syntax.

    When the device also gets used with its physical remote, neither approach can know the true state, because IR and RF are one-way. The fix is a real feedback signal: a smart plug with power monitoring in front of the device, or a vibration or contact sensor. Then use a template sensor on the power reading as the state: of your template switch.

    Troubleshooting

    • Toggle flips but nothing happens. Open the automation and check its trace (three-dot menu, Traces). If it never ran, the entity ID in the trigger is wrong. If it ran, test the script on its own.
    • Script runs but the device ignores it. Relearn the code with the remote closer to the Broadlink, and make sure the Broadlink has line of sight for IR.
    • Device turns on after a Home Assistant restart. You probably have a trigger without to:, so the unavailable to off transition fires it. Use the automation from Step 4.
    • State gets out of sync. Someone used the original remote. Add a feedback sensor as described above.

    Once this pattern clicks, you can reuse it everywhere. Turning it into a blueprint saves you from writing the same automation for every fan and heater in the house.

    Frequently Asked Questions

    How do I create a toggle switch in Home Assistant?

    Go to Settings > Devices & services > Helpers > Create helper > Toggle. That gives you an input_boolean you can put on a dashboard. To make it control a device, add an automation that runs your on and off scripts when the toggle changes.

    What is the difference between a toggle helper and a switch entity?

    A toggle helper (input_boolean) is virtual and only stores on or off. A switch entity belongs to a real device or a template, and turning it on or off actually does something. You can combine them: a template switch can use a toggle helper as its state.

    Do I need an automation if I use a template switch?

    No. A template switch has its own turn_on and turn_off actions, so it calls your scripts directly. The helper plus automation pattern is mainly useful when you want several triggers, like schedules, sensors and voice, to all go through one state.

    Why does my toggle not match the real device state?

    IR and RF remotes are one-way, so Home Assistant only knows what it sent. If someone uses the physical remote, the states drift apart. A smart plug with power monitoring or a simple sensor on the device gives Home Assistant real feedback.

    Can I use a Broadlink to control a device with only one power button?

    Yes. Learn the single power code and send it from both scripts. It works fine, but the toggle can get out of sync if a command is missed, so a feedback sensor helps here too.

    Related guides

    Leave a comment

    Your email address will not be published. Required fields are marked *

    This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    Coming soon
    The ready-made Home Assistant dashboard
    One email when it's ready, with an early-bird price. No spam. Privacy