Outsmarting your "smart" electric blanket this winter

Winter is here in Australia and how annoying is it to automate an electric blanket? As some other posts have mentioned, modern electric blankets have an annoying (?) safety feature called auto-off - and it may or may not go into a sensible state on power-on. I am sharing this because it took me ages to figure out :laughing: and did not involve sewing an ESP32 into a blanket.

In my case the electric blanket (Sunbeam from memory) when powered on, turns on at the last temperature setting, so far so good. But by default (without using a physical switch), it turns itself off after only an hour. To fix this the power needs to be cycled off and then back on again - every hour.

No problem I thought, I will just turn it off and back on again every hour with an AU$15 Arlec smart plug from Bunnings. Trouble was, the Arlec smart “grid connect” plug (or the Tuya integration) does not offer a sensor that allows you to tell the difference between you manually turning your blanket off with the physical button on the Arlec, and what you are doing in your automation. So how to keep your bed warm for the maybe 3 hour period when you may choose to go to bed, but still turn off, and stay off, when you turn the plug off manually (because you are in bed and warm enough)?

I figured a global toggle (input.boolean) would do the job. Turn it off every hour when doing automated on/off and back on again when “waiting” in case the physical plug is turned off.
It seems (and I am no expert) that even using the “run in sequence” option in the automation that HA does not guarantee that automation events happen in sequence. So to get this reliably working I had to have the automation wait (wait_template) to confirm that the last action had happened before continuing.

This automation also checks that the blanket is drawing power and not turned off by hand in a way the automation cannot fix and lets you know.

This is the automation YAML which requires one automation per blanket/person (it could be parameterised further). You would need to replace device names and check the device parameters (e.g. …_socket_1 etc to match your devices and as you see I am checking the temperature with a shelly and that we are “in town” vs in home zone.

This YAML requires you to define a global helper input.boolean called Plug6toggle or similar.

If this helps somebody, please let me know!

automation YAML

Blockquote

alias: Leckly blanket
description: Seperate per bed/pers
trigger:
  - platform: time
    at: "20:40:00"
condition:
  - condition: numeric_state
    entity_id: sensor.shellyplusht_083a8d3_temperature
    below: 18
  - condition: numeric_state
    entity_id: sensor.home_me_distance
    below: 10000
action:
  - variables:
      delay_minutes: 50
      person: Me
  - service: script.turn_on
    target:
      entity_id: script.electric_blanket_cycle
    data:
      variables:
        entity_name: plug6
  - service: notify.mobile_app_iphone
    metadata: {}
    data:
      title: Home Assistant
      message: "{{ person }} electric blanket turned on (1)"
  - delay:
      hours: 0
      minutes: 4
      seconds: 0
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: sensor.plug6_current
        below: 0.02
    then:
      - delay:
          hours: 0
          minutes: 2
          seconds: 0
          milliseconds: 0
      - if:
          - condition: numeric_state
            entity_id: sensor.plug6_current
            below: 0.02
        then:
          - service: notify.mobile_app_iphone
            metadata: {}
            data:
              title: "Home Assistant "
              message: "Warning: {{ person }} blanket not on"
  - delay:
      hours: 0
      minutes: "{{ delay_minutes | int }}"
      seconds: 0
      milliseconds: 0
  - service: script.turn_on
    target:
      entity_id: script.electric_blanket_cycle
    data:
      variables:
        entity_name: plug6
  - service: notify.mobile_app_iphone
    data:
      message: "{{ person }} electric blanket turned on (2)"
      title: Home Assistant
  - delay:
      hours: 0
      minutes: "{{ delay_minutes | int }}"
      seconds: 0
      milliseconds: 0
  - service: script.turn_on
    target:
      entity_id: script.electric_blanket_cycle
    data:
      variables:
        entity_name: plug6
  - service: notify.mobile_app_iphone
    metadata: {}
    data:
      title: Home Assistant
      message: "{{ person }} electric blanket turned on (3)"
  - delay:
      hours: 0
      minutes: "{{ delay_minutes | int }}"
      seconds: 0
      milliseconds: 0
  - service: script.turn_on
    target:
      entity_id: script.electric_blanket_cycle
    data:
      variables:
        entity_name: plug6
  - service: notify.mobile_app_iphone
    metadata: {}
    data:
      title: Home Assistant
      message: "{{ person }} electric blanket turned on (last)"
mode: single

This script simplifies the above automation and makes it easier to have per-person automations:

alias: Electric blanket cycle
description: relies on some naming conventions
fields:
  entity_name:
    selector:
      text: null
    name: entity_name
    description: name of the blanket plug
    default: plug6
sequence:
  - variables:
      toggle_name: input_boolean.{{ entity_name }}toggle
      switch_name: switch.{{ entity_name }}
  - service: input_boolean.turn_off
    target:
      entity_id: "{{ toggle_name }}"
    data: {}
  - wait_template: "{{ is_state(toggle_name, 'off') }}"
    continue_on_timeout: true
    timeout: "00:00:15"
  - service: switch.turn_off
    target:
      entity_id: "{{ switch_name }}_socket_1"
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: switch.turn_on
    target:
      entity_id: "{{ switch_name }}_socket_1"
    data: {}
  - wait_template: "{{ is_state(switch_name, 'on') }}"
    continue_on_timeout: true
    timeout: "00:00:15"
  - service: input_boolean.turn_on
    target:
      entity_id: "{{ toggle_name }}"
    data: {}
mode: parallel
max: 2
2 Likes

frozen bike
LOL. I expect a lot of people are scratching their heads thinking why you would ever need an electric blanket in Oz. I suspect you may be inland >100Km or well south. It brings back memories of news stories from Australia of things being left out over night being encased in ice.

1 Like