ESPHome Stepper Motor Heater Controller

February 7, 2021

One of the challenges of building a smart home when you don't own a home is creating projects that work with the existing features of the home so it'll be easier when you eventually move out.

This is another project that I had dreamed up around 2013 from my first apartment. I had written a python script to control this stepper motor connected to a Raspberry Pi. Additionally, I learned how to use AutoDesk Fusion 360 and created a 3D model to hold the livestrong rubber band. I had printed at a hackerspace for about $20, which seemed a bit much for what it is, but that was in the "early" and exciting days of 3D printing lol.

I've since moved a few times and enhanced the setup. I've taken the stepper motor and connected it to an ESP8266 and used Home-Assistant to automate a baseboard heater.

I've used some screws (that are easily removable) to mount the stepper motor to the baseboard. I used a "livestrong" rubber band bracelet as a belt to control the heater knob by tension and friction.

The code within ESPHome is pretty straightforward. It uses the stepper motor and the temperature sensor to make a "bang-bang climate controller". If you're wondering where the name "Bang-Bang" controller came from, check wikipedia. Basically, it switches between two states (on/off or up/down) to keep something between a desired state.

In this example, you set the desired temperature and the stepper motor will turn the heater on or off to maintain the heat at that desired temperature.

Here are a couple pictures of what it looks like:

ESPHome Stepper Motor Heater Controller 1

Cover - ESPHome Stepper Motor Heater Controller

ESPHome Stepper Motor Heater Controller 2 Top

ESPHome Stepper Motor Heater Controller 3 Right Side

ESPHome Stepper Motor Heater Controller 4 Front

ESPHome Code:

  name: heater
  platform: ESP8266
  board: nodemcuv2

  ssid: 'Network_SSID'
  password: 'Network_PW'

# Enable logging


    - service: control_stepper
        target: int
        - stepper.set_target:
            id: my_stepper
            target: !lambda 'return target;'

  - platform: uln2003
    id: my_stepper
    pin_a: D1
    pin_b: D2
    pin_c: D3
    pin_d: D4
    max_speed: 150 steps/s
    step_mode: HALF_STEP #WAVE_DRIVE # 

  - platform: dht
    pin: D5
      name: "Heater Temperature"
      id: heater_temperature
      name: "Heater Humidity"
      id: heater_humidity
    model: AM2302

  - platform: bang_bang
    id: heater_climate
    name: climate
    sensor: heater_temperature
    default_target_temperature_low: 20 °C
    default_target_temperature_high: 22 °C

      # - switch.turn_on: heater
      - stepper.set_target:
          id: my_stepper
          target: -5000
      # - switch.turn_off: heater
      - stepper.set_target:
          id: my_stepper
          target: 5000
      - stepper.set_target:
          id: my_stepper
          target: 2500

Home Assistant Configuation

# Home Assistant Configuration
    name: Stepper Control
    initial: 0
    min: -3000
    max: 3000
    step: 1
    # mode: box

Home Assistant Automation

# Home Assistant Automation
  - alias: Write Stepper Value to ESP
      platform: state
      entity_id: input_number.stepper_control
      # Replace livingroom with the name you gave the ESP
      - service: esphome.heater_control_stepper
          target: '{{ trigger.to_state.state | int }}'

I've combined both sections of the Home Assistant side into a file called Heater.yaml that sits inside the Packages folder. Be sure to include packages: !include_dir_named packages underneath the homeassistant: section at the beginning of your YAML config.

I've moved again, and this setup is no longer in use because my new place has central heating. Let me know if you have a good use-case for this stepper motor!