Help needed on automated curtain project

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
delmeer
New user
Posts: 4
Joined: 12 Dec 2020, 22:14

Help needed on automated curtain project

#1 Post by delmeer » 12 Dec 2020, 22:45

Hi,

Looking for some help to make my automated curtains dummy proof before installing it all.

Got an Wemos D1 to control an engine to open or close the curtains. Enabled rules and got it working based on the script below.

On curtaindown do
gpio 12,0
gpio 13,1
timerset 1,10 //set timer 1 for 10 seconds
Endon

On curtainstop do
gpio 12,0
gpio 13,0
Endon

On curtainup do
gpio 12,1
gpio 13,0
timerset 1,10 //set timer 1 for 10 seconds
Endon

Also use Domoticz to activate the rules http://192.168.178.123/control?cmd=event,curtainup, http://192.168.178.123/control?cmd=event,curtainstop and
curtainstop http://192.168.178.123/control?cmd=event,curtaindown

When curtains are fully open (0%) and the button curtainsdown is activated it runs 10 seconds based on timerset so it stops when fully closed(100%).
When it needs to be open again curtainsup Is activated an it runs exact the wright time to open again. The big risk is that the curtains are fully open (0%) and "open" button is pussed again it will again run for 10 seconds but can’t because it is already open so something will break for sure.

To prevent this a variable should be set so when status is fully open (0%) and the button "open" is pussed it checks and will not run again again because of the curent value. This should also be the done when fully closed (100%) so it can’t run for a second time.

I think it should be done with the TaskValueSet but I’m just not experienced enough how to get it done or figure it out.
Big wish is to be able to open it for 50% and be sure when half way fully open or closed can’t be used otherwise it would also go to far.
For now one thing at a time.

Would be great is someone could help me.

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Help needed on automated curtain project

#2 Post by Patou » 13 Dec 2020, 17:29

Hello
I have made a project for shutter control . This is quiet similar to curtains.
Differents things must be consider :
- May shutter close when windows is open ? No ! so I need a switch to detect windows is open
- I suppose the motor has is own open en closed limit switches but they are inside and so no acces so I detect at least if the blinds are closed with a limit switch
- For local control I use the existing switches : 1 for opening 1 for closing , when boths are off the blinds should stop in the actual position
- For remote control, I must be able to open, close and stop the shutter in an intermediate position, I have defined 10 positions.

I use a self developped pcb, this pcb include, power supply, Wemos D1 mini pro socket, socket for 4 channels optocoupler (voltage on the switches can be different from 3.3V), 2 relays that can be configure in 2 times NO contacts ( if pcb is used for light control) or 1 on/off relay and 1 direction relay ( better for shutters this avoid short-circuit if the 2 relays are operated at the same time)

You find bellow :
- Rules (delete comments before inport in esp!)
- Devices
-PCB pictures
- drawing of the circuit

Please feel free to use anything explained here
Patou

Code: Select all

On System#Boot do
  //timerset,1,5
  timerset,5,30
  gpio,15,0 // On-Off
  let,1,28 // time to move 100%
  let,10,28000 // time to move in ms
  let,11,2800 // counting interval in ms
  let,2,1.15 // time multiplier to move up ( mostly slower than moving down)

  TaskvalueSet,8,2,1 // local=1 remote=2 
endon

On Lm_Windows#State do
 Publish %sysname%/Lm_Windows,'[Lm_Windows#State]'
endon

On Lm_Shutter#State do
 Publish %sysname%/Lm_Shutter,'[Lm_Shutter#State]'
endon

On ha_start do // when Home assistant restart wait 1 sec and publish actual data
   timerset,5,1
endon

On Rules#Timer=5 do
 If [Lm_Shutter#State]=0  // shutter closed
  gpio,0,0 // 1 = Open 0 = Close
  TaskValueSet,7,1,0 // Position 0
  TaskValueSet,8,1,0 // Internal Target Position 0
  Publish %sysname%/State,'Fermé' // Publish "Closed"
 else
  //gpio,0,1
  TaskValueSet,8,1,[Pos#Position] // Actual pos = target
  Publish %sysname%/State,'Ouvert' // Publish "Open"
 endif
 Publish %sysname%/Target,'[Pos#Position]'
 Publish %sysname%/Position,'[Info#Position]'
 Publish %sysname%/Lm_Shutter,'[Lm_Shutter#State]'
 Publish %sysname%/Lm_Windows,'[Lm_Windows#State]'
 endon

// Local switch commands

On Up#state=1 do
 let,5,10-[Info#Position] // Set target position 
 TaskvalueSetAndRun,8,2,1 // Set to local=1 
 event,VoletOpen
 endon

On Down#state=1 do
 let,5,[Info#Position] // Set target position
 TaskvalueSetAndRun,8,2,1 // Set to local=1 
 event,VoletClose
 endon

On VoletOpen do
 If [Info#Position]<10 // not yet fully open
  let,6,1+%v5%*%v11%*%v2%/1000 // calculate the run time of the shutter going up
  TaskValueSetAndRun,7,4,%v5% // give the number of position to target
  timerset,1,%v6% // set the run time of the shutter
  looptimerset_ms,3,%v11%,%v5%  // start timer time = v11 nb of timer run = v5 
  Publish %sysname%/Target,'[Pos#Position]'
  Publish %sysname%/State,'Ouvrant' // Publish "Opening"
  gpio,0,1 // open
  gpio,15,1 // on
 endif
endon

On VoletClose do
 If [Info#Position]>0 and [Lm_Windows#State]=0 // not yet closed
  let,6,1+%v5%*%v11%/1000
  TaskValueSetAndRun,7,4,%v5%
  timerset,1,%v6%
  looptimerset_ms,3,%v11%,%v5%  
  Publish %sysname%/Target,'[Pos#Position]'
  Publish %sysname%/State,'Fermant' // Publish "Closing"
  gpio,0,0 // close
  gpio,15,1 // on
 endif
endon

// Rules Set 2

On Target_Position do // When Home assistant send new target position 
 TaskvalueSet,8,2,2 // Set to remote=2
 Publish %sysname%/Lm_Shutter,'[Lm_Shutter#State]'
 Publish %sysname%/Lm_Windows,'[Lm_Windows#State]'
 TaskValueSetAndRun 8,1,%eventvalue% // store target position
 
 if [Pos#Position] > [Info#Position] // volet opening
  Let,5,[Pos#Position]-[Info#Position] // store delta target / actual position
  event, VoletOpen
 endif

 if [Pos#Position] < [Info#Position] and [Lm_Windows#State]=0 // volet closing
  let,5, [Info#Position]-[Pos#Position] // store delta actual /target position 
    event, VoletClose
  endif
endon

On Rules#timer=1 do // when run time is over
 gpio,15,0 // Off
 gpio,0,0
 if [Lm_Shutter#State]=0 // 
  TaskValueSetAndRun 7,1,0 // set Info Position to 0 in case it was not 
  TaskValueSetAndRun 8,1,0 // set Target Position
  Publish %sysname%/State,'Fermé' // Publish "Closed"
 else
  Publish %sysname%/State,'Ouvert' // Publish "Open"
  TaskValueSetAndRun 8,1,[Info#Position] // put actual position  as target
endif
Publish %sysname%/Target,'[Pos#Position]'
Publish %sysname%/Position,'[Info#Position]'
Publish %sysname%/Lm_Shutter,'[Lm_Shutter#State]'
Publish %sysname%/Lm_Windows,'[Lm_Windows#State]'
endon

On Rules#timer=3 do // Increment or decrement actual position
 If [Open-Close#State]=1 and [On-Off#State]=1 and [Info#Position] < 10 // Opening and not yet arrived
  TaskValueSetAndRun 7,1,[Info#Position]+1 // increment position
 endif
 If [Open-Close#State]=0 and [On-Off#State]=1 and [Info#Position] > 0 // Closing and not yet closed
  TaskValueSetAndRun 7,1,[Info#Position]-1 // decrement position
 endif
 Publish %sysname%/Position,'[Info#Position]'
 If [Up#State]=0 and [Down#State]=0 and [Pos#Local]=1 // If switch down and switch up are open and local mode
  gpio,15,0 // Stop the shutter
  gpio,0,0
  timerset,1,0
  TaskValueSetAndRun 8,1,[Info#Position] // put actual pos as target position
  Publish %sysname%/State,'Stop'
  Publish %sysname%/Target,'[Pos#Position]'
 endif
endon
 


// Rules et 3 volet 1 // only to mesure temp, hum, atm and send to HA 


On Temp#°C do
 Publish %sysname%/Temp_Ext,'[Temp#°C]'
endon

// Rules Set 3 Volet 2 

On Temp-Hum#°C do
 Publish %sysname%/Temp_Living,'[Temp-Hum#°C]' 
 Publish %sysname%/Hum_Living,'[Temp-Hum#%]'
 Publish %sysname%/Atm_Living,'[Temp-Hum#hPa]'
endon
Image

Image

Image
Attachments
Koningslo-box.png
Koningslo-box.png (1.69 MiB) Viewed 18252 times
Drawing-Volet-2020-12-13.png
Drawing-Volet-2020-12-13.png (180.89 KiB) Viewed 18252 times
EspEasy-Volets-Devices-2020-12-13.png
EspEasy-Volets-Devices-2020-12-13.png (54.17 KiB) Viewed 18252 times

jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Help needed on automated curtain project

#3 Post by jgrad » 13 Dec 2020, 19:36

For controlling rolling shutters I use following ready made HW https://www.electrodragon.com/product/w ... d-esp8266/

Based on my experience all rolling shutter motors (I bought many of them here https://www.rohrmotor24.eu/) have limiting switches inside and after installation you just have to adjust (up/down) end positions.

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Help needed on automated curtain project

#4 Post by Patou » 13 Dec 2020, 21:13

@ jgrad,
Hello,
Your ready made solution with dragon seems interesting. It has 2 relays and can be used to control shutters.
But... how do you keep local control and send to HA or Domoticz the state changes done locally ?
Indeed all shutters have limit switches inside ( needed to stop the motor at max open or close) but no way to get some signal out.
So how does your supervisor software knows that shutter is open or closed, or at what position it has stopped.
When power fails or Esp reboot how to know that shutter is open or closed ?
It is all so quiet frustating if your supervisor system close the shutter automatically when darks comes and that you have open the windows and are in the garden at that moment.
So it is a good idea that your supervisor system knows that the windows is open !
Intelligent automation is not so easy !
Patou

delmeer
New user
Posts: 4
Joined: 12 Dec 2020, 22:14

Re: Help needed on automated curtain project

#5 Post by delmeer » 14 Dec 2020, 19:53

OK, change of plans... first off al I’m going to build a little test setup.
Ordered 2 limit switches. These will be at the start and at the end so when triggered the motor will stop.

What I’m dealing with now is how to wire the switches to the wemos. Can’t really find a good tutorial based on the Wemos so made a setup. Will this work? Is this the proper way to connect them?

Also wrote a piece off script based on google search, absolutely no idea if this will work but that’s why I make de test setup.
You need to know I’m not a programmer😬
(https://espeasy.readthedocs.io/en/lates ... witch.html)

On curtaindown do
if [Switch_B#State]=1 //Curtains already closed!
GPIO,12,0
GPIO,13,0
else
GPIO,12,0
GPIO,13,1
timerset 1,7 //set timer 1 for 7 seconds incase switch doesn’t work
endif
Endon

On curtainstop do
GPIO 12,0
GPIO 13,0
Endon

On curtainup do
if [Switch_A#State]=1 //Curtains already open!
GPIO,12,0
GPIO,13,0
else
GPIO,12,1
GPIO,13,0
timerset 1,7 //set timer 1 for 7 seconds incase switch doesn’t work
endif
endon

On Rules#Timer=1 do
GPIO,12,0
GPIO 13,0
endon

//
// https://espeasy.readthedocs.io/en/lates ... witch.html
//
on Switch_A#State do
if [Switch_A#State]=1 //Switch triggered turn power off
GPIO,12,0
GPIO 13,0
endif
endon

on Switch_B#State do
if [Switch_B#State]=1 //Switch triggered turn power off
GPIO,12,0
GPIO 13,0
endif
endon

All will be operated from domoticz or a 3 button remote (up/down/stop) that will activate the domoticz buttons.

So don’t have anything to do with open doors or windows.
Attachments
C2D1D2FF-C685-4F3F-B77A-7DA988B5E2B3.png
C2D1D2FF-C685-4F3F-B77A-7DA988B5E2B3.png (834.59 KiB) Viewed 18204 times

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Help needed on automated curtain project

#6 Post by Patou » 14 Dec 2020, 23:37

Hello Delmeer,
I try to make some suggestions on some of your proposals :
Drawing with switches :
- If these are momentairy switches 1 up, 1 down and 1 stop OK ... to save 1 input : Stop can also be made with up and down pressed together
- if these are normal switches (on my shutter they are normal switches) then : just detect transition from OFF to ON then only 2 switches needed
- 10 K resistor is ok to 3.3 V if wires are long between Esp and switches, best is also to put a 0.1 mf capacitor to ground. There is also a buildin resistor in the Esp gpio that can be activated
- to choice the best gpio please look at : https://espeasy.readthedocs.io/en/lates ... n-esp8266 for the best choice.
Please consider also to put capacitor 50 mf to 100 mf on 5V and on 3.3 V to have stable DC supply ( see my drawing)
Please consider also that if you use 2 relays in parallel (one for up and one for down)if,for any reasons, boths are activated you make a short-circuit on the power supply. So better 1 relay for on/off and 1 relay for up/down.
Ones you have fixed the hardware we can talk about the software part.
Do you want to stop the shutter in differents positions or only open and closed ?
Have a good night
Patou

jgrad
Normal user
Posts: 92
Joined: 29 Aug 2016, 22:03
Location: Slovenia

Re: Help needed on automated curtain project

#7 Post by jgrad » 15 Dec 2020, 23:39

@Patou

My rolling shutters/blinds are controlled from HA controller (loxone in my case, same as Domoticz) and HA controller knows current position of particular blind. ESP HW installed near shutter/blinds controls just send pushbutton events (up/down) to HA controller and then HA controller (based on current position, blind travel time up/down) send commands back to ESP HW (relays) to activate motor for down or up. So NO local logic within ESP.

in HA controller I use "automatic blinds" function block which provides all logic to control blinds
https://www.loxone.com/enen/kb/automatic-blinds/

Just to add: controlling blinds in HA controller is based on "travel time" up and down. If you want to fully close blind you have to move it down for XX seconds, same for up. And you know where blind is is base on how long particular relay was switched on. And if you reset system - you have to make somehow callibration. eg to move blind "fully up" (this means switch on relay for YY seconds) and when you have it fully opened and then continue based on current state of day or based on current light conditions.

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Help needed on automated curtain project

#8 Post by Patou » 16 Dec 2020, 10:51

@igrad
Hello
This is an interesting approch to manage the automation only in HA. Unfortunately, for me, my programming skill in HA is poor regarding my experience in Esp Easy.
Advantage to keep automation in esp is that it can run alone without wifi, network and controller !
Is it possible to share you automation.yaml in HA for this project ?
Good day
Patou

delmeer
New user
Posts: 4
Joined: 12 Dec 2020, 22:14

Re: Help needed on automated curtain project

#9 Post by delmeer » 16 Dec 2020, 18:14

@Patou

Thanks for your reply. Sorry I didn’t respond sooner,
Somehow I don’t get a notification when a new reply is added.

The switches in the image are dummy’s, ordered limit switches.
So I’m not going to use physical push buttons to operate it.
Al will be done by Domoticz and a remote control to activate a rule.

With the stop button off the remote I will stop it halfway manually. When closing or opening the limit switch will stop it.
So there is no need to stop it halfway anymore as long as the limit switch at the end and beginning work.

Waiting for the limit switches to arrive and will contact you then.
Hopefully it will be today.

Best wishes

delmeer
New user
Posts: 4
Joined: 12 Dec 2020, 22:14

Re: Help needed on automated curtain project

#10 Post by delmeer » 24 Dec 2020, 17:55

Yesss received the limit switches and installed them on my test setup.

Almost ready to test but now need to know for sure what pins
to connect the limit switches to and what the code should look like. Will the above code work??

The idea now is that the limit switches will stop the curtains at fully opened or fully closed, switch A or B equals a value 1. With the remote I will stop them manually at 50% if wanted.

The code needs to check if curtain is already open, switch A=1, so it won’t open any farther otherwise is will break or damage the setup. When fully closed the same but then check if switch B=1.

All help is welcome because I do not want to damage the esp board because off the wrong pin setup of the 2 limit switches.

Merry Christmas 🎄
Attachments
9AC2A7DB-DFC0-4D80-8423-FB6FFE4CACF1.jpeg
9AC2A7DB-DFC0-4D80-8423-FB6FFE4CACF1.jpeg (2.91 MiB) Viewed 17722 times
2CBDBED3-BF17-48BC-B7CF-EB05BA56E737.jpeg
2CBDBED3-BF17-48BC-B7CF-EB05BA56E737.jpeg (2.74 MiB) Viewed 17722 times
576D44A5-6EB5-4A7E-88D1-FD2D5A7227E0.jpeg
576D44A5-6EB5-4A7E-88D1-FD2D5A7227E0.jpeg (3.31 MiB) Viewed 17724 times
AFD5D8D8-C95E-4D5F-8908-ABEFB7C82B78.jpeg
AFD5D8D8-C95E-4D5F-8908-ABEFB7C82B78.jpeg (3.6 MiB) Viewed 17724 times

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Help needed on automated curtain project

#11 Post by pw444 » 20 Mar 2021, 15:45

Hya.

i'm trying something similar.

How to you calculate the percentage of open or close?

Thx in advance.

Multimull
New user
Posts: 5
Joined: 24 Oct 2020, 13:46

Re: Help needed on automated curtain project

#12 Post by Multimull » 07 Apr 2022, 10:31

have a look at the new PWM motor control plugin!
You can define end switches etc, works with H-bridge or relais and also rotary encoder for position control!

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests