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;