Motor on a roller blind - ESPHome version?

Hello to all,

I am very new to HA, ESPHome, and boards like this and hope I am not in the wrong here. I am sorry if I am.
I have been looking into blinds control for over a year but have not come across a design that I have started on. I am sure that this group can solve my issues. Here is my outline:
I am using the 12VDc motor with an encoder using a L298n motor driver. The code needed is to count position from the encoder. One limit switch is needed to “setpoint” the “home” position. I have read on a site that is using this control for an axis on a simple cnc. He had PID with PWM to control the “move”. Having this control, PWM with PID(not a must have, but nice for accel and decel), count table( 0=closed, xxxx=open) gives variable degree of blind. Geared DC motor with encoder is around $17. I would use this same setup on all of my casement windows, roller blinds, and shades. I am sure could be used on anything that requires (Somewhat) precise position control. Any linear slides could also be controlled with this. I am too old to figure out the code, but I am very surprised no one has been heading in this direction. In my experience, stepper motors are very limited and costly when needing drives and supplies.
As I said, I hope I am not in the wrong place here. This is my first post on any site, and this group seems to me that you are ll very talented to accomplish this project.
Thank you all

Does this help @cnctech ?

1 Like

Thank you RikW for your options. This system seems to be an “on-off” control, which will work for a roller or dc motor but would most likely not control blinds or any “variable” position control. I am looking for a basic control that needs to use:

  1. PWM for variable speed.
  2. Encoder input (keeps position)
  3. One limit switch ( sets “home” reset counter for encoder)
  4. Table lookup for “set position” ( 0 -100) percent of total travel. Example," Open to 70%(70)"

I have not "played around with this for over a year now but I think there was a person that has just about all of the code worked out for a cnc machine that he made. I thought his name was something like Nisan on Github, I will try to find my information on that. This is a site that shows most of the logics involved but does not have the front end. http://www.ijsrp.org/research-paper-1118/ijsrp-p8321.pdf
I have wired my house with 16/4 speaker wire to every window and door in my house to supply these DC encoded gear motors. This system will control all of the windows, blinds, shades, and pocket doors. It is basically the same thing used on industrial cnc machines. By having acceleration and deceleration a smaller motor can move the doors with smooth action. The systems for the Arduino are using serial in to read a file for the position to head to. With a door, window, or shade the position can be set. Example, door = 0 to 83281 counts, blind = 0 to 6355 counts(pulses from encoder), etc.
I will look for the information that I was working on a year ago so that I am more prepared.
Thanks again RikW.

1 Like

@RikW I really liked your approach/picture of the direct motorization of your blinds? Are they commercially available cylindrical motors for blinds or did you make your own custom built bracket with motors inside?
I really like the approach pictured.
Can you shed some light?

Thanks

Hi Miguel @saturno
They are 28BYJ-48 ULN2003 5V Stepper Motor - a pack of five was around £12 from Amazon.
I run them at 9v to get some extra torque. So use a 9v power supply to power the steppers with a buck converter to drop down to 5v for the esp8266 NodeMCU used to control them with esphome.
The rest is all 3D printed parts :slight_smile: - motor housing, blind brackets, blind insert and control box.
Hope this helps :slight_smile:

Hi @RikW,

Of course it helps :slight_smile:
Can you share the 3D parts you are using? :pray:

Thanks

@saturno Sure - Do you have somewhere I can dump them to? I have stl all the files.

Hi Rik,

Sent you a PM with details.
Thanks for your help :+1:

@saturno Miguel,
Replied to your PM, but I have uploaded them to Thingiverse :slight_smile:
Look here https://www.thingiverse.com/thing:3954537
Hopefully it will be easier
Rik

2 Likes

Hi Rik,

Thank you so much for sharing the 3D part of the project.
I will see if they fit my blinds (mine aren’t from Ikea), but even they don’t I will adjust the endcaps as needed.

I am just a little curious to see if this little stepper motor will handle my 95cm x 195cm blinds. I would be very happy if it does.

Thanks :slight_smile:

Hi Miguel,
My blinds are not Ikea - it was just the base I used and edited the stl files from.
You will notice that there are 2 inserts - they are 2 different sizes. You can easily make a new one if neither fit your blinds.
I have the steppers running (60cm wide x 180cm long) and (90cm wide x 180cm long) blinds without issues. Running them at 9v instead of 5v gives the extra torque.
If the blinds are a little too heavy, you can always run a stepper on each end controlled by the same esp8266 - just wire one 1234 and the other 4321 as they will the opposite way round :wink:
Rik

There is also a design here https://www.thingiverse.com/thing:2392856

Here is my cheap automation: https://github.com/empenoso/diy-cheap-automated-blinds

Thought I’d share my config, I’ve done things a little differently. I set up a template cover in home assistant and used that to control the esphome stepper, rather than using a template cover in esphome.

This config gives me open, close and a slider for position. I can also set position with google home (or any other automation).

I worked out, by a bit of trial and error, that it’s 11000 steps from fully closed to fully open. So all values passed from the ha template cover, which has a range of 0 - 100, are multiplied by 1100. A sensor is configured in esphome which stores the position and ha uses that as the position_template in ha. This keeps the position accurate if ha is restarted.

To keep the position accurate when the esp device is restarted, I’ve set it to move 11000 steps towards 0, wherever it is, when it hits the actual 0 position the motor stalls (which I understand is not a problem for steppers, although time will tell). So, when it’s finished it’s definitely at 0 and I can safely set that as the current position.

Anyhow here’s the HA config for the template cover:

cover:
  - platform: template
    covers:
      boxroom_blind:
        friendly_name: "Boxroom Blind"
        position_template: "{{ states('sensor.boxroom_blind_position') }}"

        open_cover:
          service: esphome.boxroom_window_control_blind
          data:
            target: 0

        close_cover:
          service: esphome.boxroom_window_control_blind
          data:
            target: 100

        set_cover_position:
          service: esphome.boxroom_window_control_blind
          data_template:
            target: "{{ position }}"

and here’s the esphome config:

esphome:
  name: boxroom_window
  platform: ESP8266
  board: d1_mini

  on_boot:
    priority: 80
    then:
    - stepper.set_target:
        id: my_stepper
        target:  -11000
    - delay: 20s
    - stepper.report_position:
        id: my_stepper
        position: 0
    - stepper.set_target:
        id: my_stepper
        target:  0
    - sensor.template.publish:
        id: position
        state: 0

wifi:
  ssid: xx
  password: xx

ota:
logger:

api:
  services:
    - service: control_blind
      variables:
        target: int
      then:
        - stepper.set_target:
            id: my_stepper
            target: !lambda 'return target * 110;'
        - sensor.template.publish:
            id: position
            state: !lambda 'return target;'

sensor:
  - platform: template
    name: "Boxroom Blind Position"
    id: position

stepper:
  - platform: uln2003
    id: my_stepper
    pin_a: D2
    pin_b: D1
    pin_c: D4
    pin_d: D3
    max_speed: 500 steps/s
    sleep_when_done: true

I don’t know if there are simpler / better ways of doing this, but it works :slight_smile:

9 Likes

If you dont have endstops and have no way of confirming the position of the blind the state may be lost on boot (i think I had this problem).
I had intermitent times where the roll up blinds would assume a state of open (when accually closed) and the roller blinds (from ikea) would unravel, which would require me to spend 1 min fixing.
I think I have mitigated this by creating a global variable for the stepper motor position (see below)

globals:
  - id: ${stepper_1}_global
    type: int
    restore_value: yes
#    initial_value: '0'
################# cover 1 ##########################
# items for Home Assistant 
cover:
  - platform: template
    name: $display_name_1
    id: ${stepper_1}_cover
    device_class: shade

    open_action:
      - stepper.set_target:
          id: $stepper_1
          target: 0
      - delay: 180s
      - stepper.report_position:
          id: $stepper_1
          position: !lambda return id($stepper_1).current_position; 
      - globals.set:
          id: ${stepper_1}_global
          value: !lambda return id($stepper_1).current_position; 
      - cover.template.publish:
          id: ${stepper_1}_cover
          state: OPEN

    close_action:
      - stepper.report_position:
          id: $stepper_1
          position: !lambda return id($stepper_1).current_position; 
      - stepper.set_target:
          id: $stepper_1
          target: 49000
      - delay: 180s
      - stepper.report_position:
          id: $stepper_1
          position: !lambda return id($stepper_1).current_position;
      - globals.set:
          id: ${stepper_1}_global
          value: !lambda return id($stepper_1).current_position; 
      - cover.template.publish:
          id: ${stepper_1}_cover
          state: CLOSED

    stop_action:
      - stepper.set_target:
          id: $stepper_1
          target: !lambda return id($stepper_1).current_position;     
      - globals.set:
          id: ${stepper_1}_global
          value: !lambda return id($stepper_1).current_position;  
#    optimistic: true  
2 Likes

I have been trying this example, using the ULN driver - but the stepper turns the same way on either up or down action - WHY??

I’ve got the same issue, did you manage to figure this out? Tried all variations of the wires, I’m sure they are right as the motor turns really smoothly.

Got it sorted, for anyone else struggling, there seemed to be an issue when using “Digital Pins” in the config, once I manually changed them to use GPIO pins it started working. Not sure why, because when I started up ESP using the Digital pins, it did list the GPIO pins correctly.

Hi, thanks for sharing. I too tried to use your code with nema 17 and driver A4988. But I don’t see the controls to move the engine. From the web page I don’t see any of it to move forward or behind. Some idea?

1 Like

I like this global variable approach but I’m having a bit of trouble figuring out how the position is suppose to be used to restore the state. Any chance you could provide a full file example?