# Blinds Control Logic?

**URL:** https://discourse.nodered.org/t/blinds-control-logic/14687
**Category:** General
**Created:** [23 August 2019 08:03 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687 "2019-08-23T08:03:08Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![superwinni2](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@superwinni2](https://discourse.nodered.org/u/superwinni2)
#### Post date: [23 August 2019 08:03 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/1 "2019-08-23T08:03:09Z")

</div>

Hello @all

I've got a little problem with programming my shutter control... I got a Shelly2.5 in use for "smarting" my blinds.  
Via MQTT I got 3 "buttons" in my ioBroker. Open, Close, Stop.

Now I want to realize with Node-RED a two button control. I don't want to visualize 3 Buttons. 2 are enought an it looks the same like the Physical Buttons in the wall.

In my visualisation I got the buttons / tasters Open and Close.  
When I press Open i get a msg.payload=open and when I'm going to release the button I get a payload=stop.  
Some with close.  
Pressed -\> close  
Released -\> stop

Logic I want:  
Blind are stopped lets say in the middle. When I press open for short time the blinds should only open. When I'm going to press longer (\>1 sec) the blinds should roll up. Same with close.  
When the blinds are rolling up or down and I press up/down again they should stop....

I cant get it done to create the right logic and flow to get it done...  
Is here somebody who can help me? Tried already about 4 hours...  
Node-RED isn't something new for myself... already got some flows to ask wifi status, control a switch in bathroom for heating etc.. But this thing won't work...

Thanks for your help  
superwinni2

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [23 August 2019 08:04 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/2 "2019-08-23T08:04:57Z")

</div>

Can you share the flow you have? Please read the following post [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) first 🙂

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [23 August 2019 08:07 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/3 "2019-08-23T08:07:51Z")

</div>

This may also come in handy at some point soon - [Momentary button on Dashboard](https://discourse.nodered.org/t/momentary-button-on-dashboard/4906/5)

---

<div class="post-metadata">

### Author: ![superwinni2](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@superwinni2](https://discourse.nodered.org/u/superwinni2)
#### Post date: [23 August 2019 08:08 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/4 "2019-08-23T08:08:41Z")

</div>

It's not much...  
Deleted much again after it doesn't did the work...  
I even can't get a good logic for this... I think thats my biggest problem...

Ahh... I'm german...  
Öffnen -\> Open  
Stop -\> Stop  
Schließen -\> Close

```auto
[
    {
        "id": "cda07a0e.4c83f8",
        "type": "ioBroker out",
        "z": "c3d2808b.6dfee",
        "name": "Close",
        "topic": "shelly.0.SHSW-25#687D5C#1.Shutter.Close",
        "ack": "false",
        "autoCreate": "false",
        "x": 1230,
        "y": 200,
        "wires": []
    },
    {
        "id": "3eebf54d.fa1f9a",
        "type": "ioBroker in",
        "z": "c3d2808b.6dfee",
        "name": "Fenster Links Open",
        "topic": "node-red.0.verschattung.fensterllinks.öffnen",
        "payloadType": "value",
        "onlyack": "",
        "func": "all",
        "gap": "",
        "x": 150,
        "y": 160,
        "wires": [
            [
                "8d8beb40.90a9b8"
            ]
        ]
    },
    {
        "id": "e3df650a.14e228",
        "type": "ioBroker in",
        "z": "c3d2808b.6dfee",
        "name": "Fenster Links Close",
        "topic": "node-red.0.verschattung.fensterllinks.schließen",
        "payloadType": "value",
        "onlyack": "",
        "func": "all",
        "gap": "",
        "x": 150,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "1a6c2840.0c1598",
        "type": "ioBroker out",
        "z": "c3d2808b.6dfee",
        "name": "Open",
        "topic": "shelly.0.SHSW-25#687D5C#1.Shutter.Open",
        "ack": "false",
        "autoCreate": "false",
        "x": 1230,
        "y": 80,
        "wires": []
    },
    {
        "id": "739ca512.b9c36c",
        "type": "ioBroker out",
        "z": "c3d2808b.6dfee",
        "name": "Stop",
        "topic": "shelly.0.SHSW-25#687D5C#1.Shutter.Pause",
        "ack": "false",
        "autoCreate": "false",
        "x": 1230,
        "y": 140,
        "wires": []
    },
    {
        "id": "2d829dbd.c08822",
        "type": "switch",
        "z": "c3d2808b.6dfee",
        "name": "Drivemode",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "öffnen",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "stop",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "schließen",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 1090,
        "y": 140,
        "wires": [
            [
                "1a6c2840.0c1598"
            ],
            [
                "739ca512.b9c36c"
            ],
            [
                "cda07a0e.4c83f8"
            ]
        ]
    },
    {
        "id": "8d8beb40.90a9b8",
        "type": "switch",
        "z": "c3d2808b.6dfee",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "öffnen",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "stop",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 330,
        "y": 160,
        "wires": [
            [
                "e5ae5d75.7a717"
            ],
            [
                "e5ae5d75.7a717"
            ]
        ]
    },
    {
        "id": "87c363af.65317",
        "type": "delay",
        "z": "c3d2808b.6dfee",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 800,
        "y": 140,
        "wires": [
            [
                "2d829dbd.c08822"
            ]
        ]
    },
    {
        "id": "e5ae5d75.7a717",
        "type": "trigger",
        "z": "c3d2808b.6dfee",
        "op1": "",
        "op2": "",
        "op1type": "pay",
        "op2type": "nul",
        "duration": "0",
        "extend": false,
        "units": "ms",
        "reset": "stop",
        "bytopic": "all",
        "name": "",
        "x": 530,
        "y": 140,
        "wires": [
            [
                "87c363af.65317"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

### Author: ![superwinni2](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@superwinni2](https://discourse.nodered.org/u/superwinni2)
#### Post date: [23 August 2019 08:13 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/5 "2019-08-23T08:13:31Z")

</div>

> This may also come in handy at some point soon - [Momentary button on Dashboard](https://discourse.nodered.org/t/momentary-button-on-dashboard/4906/5)

The problem is not the momentary button. I can also switch them to toggle Buttons. But because I want to do it "Wall like" I would also like to got them. It's 100% for sure that when I press the Open Button I got the Open (Öffnen) message and when I release it on my visualisation I get the stop message.

---

<div class="post-metadata">

### Author: ![Kinesis](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@Kinesis](https://discourse.nodered.org/u/Kinesis)
#### Post date: [23 August 2019 15:21 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/6 "2019-08-23T15:21:11Z")

</div>

I wrote the flow for controlling some doors - it should be just as applicable for blinds - you might have to edit the timer so it's 1% of the full opening/closing time

> [@Basic Timer / Intergrator for Doors Shutters or Drapes](https://discourse.nodered.org/t/basic-timer-intergrator-for-doors-shutters-or-drapes/14716):
>
> Hi - I'm realatively new to Node Red but i have a PLC based automation background. I neededed to write a flow to control the opening and closing of my garage doors via a raspberry pi. The doors use two simple linear actuator that takes about 10 second to fully open. The main aim of the project was to prevent the actuators from being energised past the point that the doors are fully open or closed to prevent damage to the motors. This meant coming up with a means of tracking how far open or close…

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [23 August 2019 16:44 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/7 "2019-08-23T16:44:50Z")

</div>

How do you know if the button was held for 1 second ? Do you get a release event ?

I used context, not sure it is even needed. unless I misunderstand your issue.

```auto
[{"id":"930d5524.6de6a","type":"inject","z":"e4ffbcc9.38355","name":"","topic":"","payload":"pressed","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":186,"y":224,"wires":[["49e94e63.58c218"]]},{"id":"16180b6d.5659d5","type":"inject","z":"e4ffbcc9.38355","name":"","topic":"","payload":"released","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":280,"wires":[["49e94e63.58c218"]]},{"id":"af16c5a2.6401d8","type":"inject","z":"e4ffbcc9.38355","name":"","topic":"","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":336,"wires":[["49e94e63.58c218"]]},{"id":"b3aafc04.918f38","type":"inject","z":"e4ffbcc9.38355","name":"","topic":"","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":168,"wires":[["49e94e63.58c218"]]},{"id":"49e94e63.58c218","type":"function","z":"e4ffbcc9.38355","name":"","func":"m = msg.payload\ns = context.get(\"state\")\nif(m ==='pressed'){\n context.set(\"state\",\"moving\")\n node.send({payload:'closing...'})\n}\nif(m==='released'){\n context.set(\"state\",\"stopped\")\n node.send({payload:'stop'})\n}\n\nif(m ==='open'){\n if(s===\"moving\"){\n node.send({payload:\"stop\"})\n }\n node.send({payload:\"open\"})\n \n \n}\n\nif(m ==='close'){\n if(s===\"moving\"){\n node.send({payload:'stop'})\n }\n node.send({payload:\"close\"})\n \n}","outputs":1,"noerr":0,"x":448,"y":252,"wires":[["24d98ce3.3c9b44"]]},{"id":"24d98ce3.3c9b44","type":"debug","z":"e4ffbcc9.38355","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":602,"y":252,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![superwinni2](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@superwinni2](https://discourse.nodered.org/u/superwinni2)
#### Post date: [24 August 2019 17:05 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/8 "2019-08-24T17:05:04Z")

</div>

Thanks for your flow. Already looked at it if it fits to my situation. But it isn't -.-

I don't know how long the button is pressed...  
I get a msgload "open" when I press the button and "stop" when i release it...  
So I need a flow or a logic where I can differate between "pressed \<1 sec" and "pressed \>1 sec"

---

<div class="post-metadata">

### Author: ![superwinni2](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@superwinni2](https://discourse.nodered.org/u/superwinni2)
#### Post date: [24 August 2019 17:14 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/9 "2019-08-24T17:14:57Z")

</div>

Thanks for your answer. 👍  
I'm going to take a look at it later...  
Need a little bit more time to understand your flow 😉

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [24 August 2019 17:39 UTC](https://discourse.nodered.org/t/blinds-control-logic/14687/10 "2019-08-24T17:39:57Z")

</div>

> [@superwinni2](#):
>
> So I need a flow or a logic where I can differate between "pressed \<1 sec" and "pressed \>1 sec"

You could possibly use a ui\_template, add a div or button and use jQuery `taphold` and `click` to send distinct `msg`s to your flow.

> **[W3Schools online HTML editor](https://www.w3schools.com/jquerymobile/tryit.asp?filename=tryjqmob_event_taphold)**
>
> The W3Schools online code editor allows you to edit code and view the result in your browser

Or something like that.
