Automating roller blinds

Hi @ all,

i have 8 roller blinds that i wanna control with an 16 relay -card.
This means 2 relays for one roller blind:

  • 1 relay that gives power to the roller blind
  • 1 relay that controls the direction (up or down) for one roller blind

So i use 8 * 2 relays for the 8 roller blinds.

I control the relay card with an ESP32 with ESPHOME.

My first test-code is (for 1 roller blind):

esphome:
  name: livingroom
  platform: ESP32
  board: esp-wrover-kit
wifi:
  ssid: "wifihome"
  password: "***********"
logger:
api:
ota:
switch:
  - platform: gpio
    pin:
      number: 26
      inverted: True
      mode: OUTPUT
    id: power1_cover
  - platform: gpio
    pin:
      number: 27
      inverted: True
      mode: OUTPUT
    id: direction1_cover
cover:
- platform: time_based
  name: "Cover1"
  id: cover1
  open_action:
    - switch.turn_off: power1_cover
    - delay: 200ms
    - switch.turn_on: direction1_cover
    - delay: 250ms
    - switch.turn_on: power1_cover
  open_duration: 60s
  close_action:
    - switch.turn_off: power1_cover
    - delay: 200ms
    - switch.turn_off: direction1_cover
    - delay: 250ms
    - switch.turn_on: power1_cover
  close_duration: 60s
  stop_action:
    - switch.turn_off: power1_cover
    - switch.turn_off: direction1_cover

The reason why i use the delays are considerations from an electrician, to prevent damage on the motors…

It works well, but its an inefficient/redundant way if i copy it for 8 times.
And i like to toggle all roller blinds if an motion detector detects a person in front of my apartment to stratle potentially burglars.
And i like to give in home assistant with single (virtual) switches the command to close for example all front roller blinds.
Or closing the roller blinds in winter if its cloudy and open them automatically when its sunny.
And last i like to command with an other (virtual) switch in home assistant, that the roller blinds closes only for some percent. So the open_duration or close_duration should be a parameter.

Who like to write with me efficient and not “redundant” configuration code in ESPHOME to achive this goals?

I have read a little bit about lambdas and scripts but i am not sure if i can achive with them my goals…

Thanks in advance
Willi

1 Like

Ok, i see i asked to much… :slight_smile:

Anyway, can someone at least say if it is possible to achieve my goals with ESPhome?

Thanks
Willy

I think you may just need to write the code 8 times, but it is a one off isn’t it? Copy and paste will help, along with a decent text editor.

Everything else, ie the automations, is perfectly possible with home assistant. I have even seen people closing blinds not just by time of day/year, but angle of sun.

Interested in doing this myself, was looking here for the same! i am just beginning myself to learn a bit about esphome so can’t give u much advice, actually i bet u already know esphome supports template placeholders smthg like {variable} maybe that can help?

can you share ur hardware choices and how u connected those motors? i understand u managed to use only 1 relay to control up & down?? i am wondering how is the selection of direction done how would it know to go up or down?

One better is lux value. If it is over a certain lux value 4 hours before sunset… The first phase of my automations run. I use a simple zwave motion sensor that has light value built in. I have 4 phases and the blinds close a little bit each hour if there is enough light.

Hi Mouawad,

i used a “SainSmart&reg 16-Channel 12V Relay Module for Arduino”. But i modified it to achive the goal that the electronic of the esp32 is galvanically seperated from the electronic of this module.
The schematic is:

Thanks for the advise, i try in the next days with the variable…

1 Like

Hi,

if someone is intereseted i realized it now with an raspberry pi and an python - script:

#!/usr/bin/python3
import paho.mqtt.client as mqtt
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
RelayGroups = [[18,19],[21,22],[23,24],[26,29],[31,32],[33,35],[36,37],[38,40]]
DIRECTION=0
POWER=1
LastActionTime=time.time()
# Initialize GPIOs
for i in range (len(RelayGroups)):
    GPIO.setup(RelayGroups[i][DIRECTION], GPIO.OUT, initial=1)
    GPIO.setup(RelayGroups[i][POWER], GPIO.OUT, initial=1)
# Initialize GPIO for 12 V power transformer
GPIO.setup(5, GPIO.OUT, initial=1)
# control relays for cover
def SetCover(Action,ID):
  global LastActionTime
  if 0 <= ID <= 7:
    # turn on power transformer for Relay card
    GPIO.output(5, GPIO.LOW)
    if (Action=="open"):
        GPIO.output(RelayGroups[ID][POWER], GPIO.HIGH)
        time.sleep(0.2)
        GPIO.output(RelayGroups[ID][DIRECTION], GPIO.HIGH)
        time.sleep(0.25)
        GPIO.output(RelayGroups[ID][POWER], GPIO.LOW)
        LastActionTime=time.time()
    elif (Action=="close"):
        GPIO.output(RelayGroups[ID][POWER], GPIO.HIGH)
        time.sleep(0.2)
        GPIO.output(RelayGroups[ID][DIRECTION], GPIO.LOW)
        time.sleep(0.25)
        GPIO.output(RelayGroups[ID][POWER], GPIO.LOW)
        LastActionTime=time.time()
    elif (Action=="stop"):
        GPIO.output(RelayGroups[ID][POWER], GPIO.HIGH)
        time.sleep(0.2)
        GPIO.output(RelayGroups[ID][DIRECTION], GPIO.HIGH)
def on_connect(client, userdata, flags, rc):
  print("Connected with result code "+str(rc))
  client.subscribe("/Wohnung/Rollos")
def on_message(client, userdata, message):
  Action,ID = message.payload.decode().split(",")
  print("message received " ,str(message.payload.decode("utf-8")))
  print("message topic=",message.topic)
  print("message qos=",message.qos)
  print("message retain flag=",message.retain)
  print("ID:"+ID)
  print("Action:"+Action)
  if (ID=="8"):
    #ID=8 means all covers
    for i in range (len(RelayGroups)):
        SetCover(Action,i)
        client.publish("/Wohnung/Rollos/Status", Action+","+str(i));
  else:
    #single cover
    SetCover(Action,int(ID))
    client.publish("/Wohnung/Rollos/Status", Action+","+ID);

##### start here #####
# wait till network is ready...
time.sleep(10)
client=mqtt.Client("RelayCardClient") #create client object
client.connect("192.168.0.22",1883,60)
client.on_connect = on_connect
client.on_message = on_message
client.loop_start()
# to save energy turn off 12V power transformer after some minutes...
while True:
    print("LastActionTime:"+str(LastActionTime))
    print("CurrentTime:"+str(time.time()))
    print("Difference:"+str(time.time()-LastActionTime))
    if (120 < (time.time()-LastActionTime) < 240):
        # turn off in a controlled way power transformer 12 V
        for i in range (len(RelayGroups)):
            SetCover("stop",i)
            print(i)
            client.publish("/Wohnung/Rollos/Status", "stop,"+str(i));
        GPIO.output(5, GPIO.HIGH)
    time.sleep(120)

The configuration.yaml of home Assistant contains for example:

cover BlindsControl1:
  - platform: mqtt
    name: "Alle Rollos"
    command_topic: "/Wohnung/Rollos"
    retain: true
    payload_open: "open,8"
    payload_close: "close,8"
    payload_stop: "stop,8"

cover Rollo0:
  - platform: mqtt
    name: "KĂĽchenFenster"
    command_topic: "/Wohnung/Rollos"
    retain: true
    payload_open: "open,0"
    payload_close: "close,0"
    payload_stop: "stop,0"

cover Rollo1:
  - platform: mqtt
    name: "WohnzimmerFenster"
    command_topic: "/Wohnung/Rollos"
    retain: true
    payload_open: "open,1"
    payload_close: "close,1"
    payload_stop: "stop,1"

cover Rollo2:
  - platform: mqtt
    name: "WohnzimmerTĂĽr"
    command_topic: "/Wohnung/Rollos"
    retain: true
    payload_open: "open,2"
    payload_close: "close,2"
    payload_stop: "stop,2"

and so on…

a little bit off topic, but maybe someone have fun with it…

2 Likes

Hi, can I ask you how did you galvanically isolate esp32 and the relay module? Can you fix photos?