Semaphore status

I'm using a semaphore take and semaphore leave to send a multiple commands to main unit. Problem is, that at this moment I can't see if all commands are already sent. Is it any possibilty how to implement any status LED if semaphor is still running or if it's done ?

Assuming that you are using node-red-contrib-semaphore then the status is shown below the node. You should be able to pick that up in a Status node if you need to.

Thank you. I tried to look on the guide video for status node, but really not cler for me how to implement such simple function like switch LED on/off depends on semaphore status.

The first part is to get the status, then you can worry about how to drive the LED.

Have you added a status node linked to the semaphore node and fed that into a debug node to see what it gives? Make sure you understand what it shows.

Yes, status node is working only with semaphore take, for leave there isn't a status. I will check step by step all texts which I'm receving, but problem is, that last staus I will receive when last command is sent, but semaphore isn't finished (finished is when last answer from main unit is received).

What are you seeing from the status node?

Try this example to see how the status works

[{"id":"48c6037f61a92b41","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":2300,"wires":[["4fc2999c7fa9fd88"]]},{"id":"4fc2999c7fa9fd88","type":"semaphore-take","z":"bdd7be38.d3b55","config":"988e46c04a575685","name":"","x":380,"y":2300,"wires":[["a24cfa5d45f991b6"]]},{"id":"f6026b9ce35a29c4","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":2300,"wires":[]},{"id":"a24cfa5d45f991b6","type":"change","z":"bdd7be38.d3b55","name":"Starting","rules":[{"t":"set","p":"payload","pt":"msg","to":"Starting","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":2300,"wires":[["f6026b9ce35a29c4","0dd211fec225201c"]]},{"id":"0dd211fec225201c","type":"delay","z":"bdd7be38.d3b55","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":220,"y":2380,"wires":[["3ab29f0ac7b4babb"]]},{"id":"3ab29f0ac7b4babb","type":"semaphore-leave","z":"bdd7be38.d3b55","config":"988e46c04a575685","name":"","x":390,"y":2380,"wires":[["3fca666f89f73061"]]},{"id":"3fca666f89f73061","type":"change","z":"bdd7be38.d3b55","name":"Done","rules":[{"t":"set","p":"payload","pt":"msg","to":"Done","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":2380,"wires":[["f6bc2ab85ce92070"]]},{"id":"f6bc2ab85ce92070","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":2380,"wires":[]},{"id":"93f8063e2f68aab3","type":"status","z":"bdd7be38.d3b55","name":"","scope":["4fc2999c7fa9fd88"],"x":360,"y":2260,"wires":[["ed86577f04cbfd47"]]},{"id":"ed86577f04cbfd47","type":"debug","z":"bdd7be38.d3b55","name":"msg.status.text","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"status.text","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":2260,"wires":[]},{"id":"988e46c04a575685","type":"semaphore-config","name":"Test","capacity":"1"}]

thanks, it's clear how it works, but I'm not able modify a msg content because message is used as command for main unit. So I must work with status text and make a function which will read a staus and depend on status text will switch on a LED on the start and OFF on the end.

Put this function, or something similar on the output of the Status node, it sends true or false in msg.payload dependent on whether there is something in the queue. You should be able to use that to control the led.

// return true if some in queue, false if all done
let numberTaken
if (msg.status.text) {
    numberTaken = Number(msg.status.text.split(/[:\/]/)[1])
    if (numberTaken === 0) {
        msg.payload = false // all done
    } else {
        msg.payload = true  // still some in queue
    }
} else {
    // no status so ignore it
    msg = null
}
return msg;

ok, thanks. I will do this way

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