Smart plugs make it easy to automate devices in your home. Heavy duty ones can control higher load appliances like air conditioners and refrigerators. But... you might want to take extra precaution when connecting those to the internet!

AC units, for example, often warn you to wait a few minutes before restarting them. Why? Restarting too soon forces the compressor to start under high pressure - which can damage it or trip the circuit breaker.

We can avoid this situation by creating a "cool down" switch - something that prevents a switch from turning on if it was recently turned off.


In Home Assistant we can create such a switch using a Template Switch, a Timer and an Automation.

Block diagram for "cool down" switch

For example, let's say we have an entity called switch.ac_unsafe.

We hide this switch from the UI and encode the danger into its name ("unsafe") to discourage future programmatic use.

We replace it with a Template Switch ( that mirrors the real switch's state (using value_template) and forward all its input to the real switch.

We create an Automation (automation.start_cooldown) triggered by the real switch turning off which, in turn, starts a Timer (timer.cooldown) during the lockdown period. This is preferable to coupling so the cool down still occurs even from external events (ex. physically triggering the smart plug).

We tie it all together by connecting the availability_template of to the state of the timer. If the timer is ticking, the switch control is disabled.

"Cool down" switch in action


Here's what the concept looks like in code.

In configuration.yaml:

# Create a fake switch that mirrors the real switch
  - platform: template 
        availability_template: "{{ not is_state('timer.cooldown', 'active') }}"
        value_template: "{{ is_state('switch.ac_unsafe', 'on') }}"
        friendly_name: AC
          service: switch.turn_on
            entity_id: switch.ac_unsafe
          service: switch.turn_off
            entity_id: switch.ac_unsafe

# Hide the real switch from the UI
      hidden: true

# Timer to track cool down period
    duration: '00:05:00'

In automations.yaml:

- alias: Start Cool Down
    domain: switch
    entity_id: switch.ac_unsafe
    platform: device
    type: turned_off
  condition: []
  - data: {}
    entity_id: timer.cooldown
    service: timer.start

Voice Commands

When connecting to Google Assistant or Alexa, be careful to exclude the actual switch (using include_entities or exclude_entities) and only expose the cool down switch. This extends the protection to voice commands:


An example conversation with Google Assistant:

Hey Google, turn on the AC.
Sure, turning AC on.
Hey Google, turn off the AC.
Got it, turning AC off.
Hey Google, turn on the AC.
Sorry, it looks like AC isn't available right now.

The Alexa integration doesn't handle it as gracefully, but the switch is still protected. When I tried, it verbally confirmed the AC turned on, even though it did not.