# Shutters with Shelly 2.5 opened/closed dectection via powerdrae

**URL:** <https://discourse.nodered.org/t/shutters-with-shelly-2-5-opened-closed-dectection-via-powerdrae/36388>\
**Category:** General\
**Created:** [23 November 2020 10:30 UTC](https://discourse.nodered.org/t/shutters-with-shelly-2-5-opened-closed-dectection-via-powerdrae/36388 "2020-11-23T10:30:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnScherf](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@AnScherf](https://discourse.nodered.org/u/AnScherf)\
**Post date:** [23 November 2020 10:30 UTC](https://discourse.nodered.org/t/shutters-with-shelly-2-5-opened-closed-dectection-via-powerdrae/36388/1 "2020-11-23T10:30:43Z")

</div>

Hello,

I'm running nodered on home assistant. My shutters are controlled by shelly 2.5 devices. With the node-red-contrib-shelly most of all is working fine. I've got a switch, which is not connected to the Shelly Devices, it's connected to home assistant via mqtt.  
This switch as two buttons (up and down). It's working great with one exception.

The switch toggels a variable named sh1. It can reach 3 states (open, stop and close)

I want it to change the state form open/close to stop, if the shutter reaches the endpostion. I tried to do this by using the powermeter from the Shelly. In my case it is not important to know either the shutter is opened or closed, I only need to know if it reached the endpoint (powerconsuption = 0)

I'm sorry to bother you, I'm sure if I search for days I will find a solution. But I don't have enough time to do so and my skills with the function node are very low. I think my code is not elegant but my error is (hopefully) simple to correct.

Thanks

```auto
> var power = msg.payload[0].power;
> 
> if(msg.payload === "start") 
> {                       
> sh1 = "stop";
> power = "0";
> }
> 
> if(msg.payload === "open")  
> 
> { if(sh1 === "stop")
> {msg.payload = {
> roller : 0,
> go : "open"}
> sh1 = "open";
> }
> 
> else if(sh1 === "close") 
> {msg.payload = {        
> roller : 0,         
> go : "stop"}
> sh1 = "stop";
> }
> else if(sh1 === "open")  
> {msg.payload = {
> roller : 0,
> go : "stop"}
> sh1 = "stop";
> }
> }
> 
> if(msg.payload === "close") 
> 
> { if(sh1 === "stop")
> {msg.payload = {
> roller : 0,
> go : "close"}
> sh1 = "close";
> }
>     
> else if(sh1 === "close")
> {msg.payload = {
> roller : 0,
> go : "stop"}
> sh1 = "stop";
> }
>      
> else if(sh1 === "open")
> {msg.payload = {
> roller : 0,
> go : "stop"}
> sh1 = "stop";
> }
> }
>  
> 
> if (power === "0"){    
> sh1 = "stop" ;         
> }                   
>                        
>                        
> return msg;

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 November 2020 18:59 UTC](https://discourse.nodered.org/t/shutters-with-shelly-2-5-opened-closed-dectection-via-powerdrae/36388/2 "2020-11-23T18:59:05Z")

</div>

The shelly 2.5 can be configured to send http request when open and closed. So why not have them configured to a http in node. So when open shelly sends request to node-red.

---

<div class="post-metadata">

**Author:** ![AnScherf](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@AnScherf](https://discourse.nodered.org/u/AnScherf)\
**Post date:** [24 November 2020 09:04 UTC](https://discourse.nodered.org/t/shutters-with-shelly-2-5-opened-closed-dectection-via-powerdrae/36388/3 "2020-11-24T09:04:24Z")

</div>

Thank you for your reply.  
I know this method and I think I have to go this way. But I wanted to make everything straight forward in one function, but I'm clearly not able to do it.

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [24 November 2020 11:10 UTC](https://discourse.nodered.org/t/shutters-with-shelly-2-5-opened-closed-dectection-via-powerdrae/36388/4 "2020-11-24T11:10:55Z")

</div>

@AnScherf, I use mqtt without the node-red-contrib-shelly. See shelly `ADVANCED - DEVELOPER SETTINGS` and the node-red core mqtt nodes.

The shelly reports the states: open, close and stop, e.g. for my bathroomBlind I use a mqtt-in node with the topic `shellies/bathroomBlind/roller/0` and for the command a mqtt-out node with the topic `shellies/bathroomBlind/roller/0/command`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 January 2021 11:10 UTC](https://discourse.nodered.org/t/shutters-with-shelly-2-5-opened-closed-dectection-via-powerdrae/36388/5 "2021-01-23T11:10:56Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
