Shutters with Shelly 2.5 opened/closed dectection via powerdrae

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

> 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;

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.

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.

@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

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