Help simplifying flow

@jeff65 per your post 4 where you say the combined switch doesn't work, can you post a copy of that node? Not seeing the actual code makes it dificult to tell if you made an error in coding it.

Still not sure of the reason for function-node-avoidence. You could replace at least 6 nodes with 1 function node.

I do something similar, but basically query my routers' arp table, if mac's not in the list > away.

All a matter of personal preference.

1 Like

I'm pretty sure you could avoid all nodes with simply one function :slight_smile:

But then, why would you use flow based node-red, where one of the advantages is, to see whats happening in an instant (or 2...) and not to have to dig into some(one else's) code?

Thanks for the replies!

I've since replaced the node, but it was this:
Output 1 where input msg.payload contains <Tracey's MAC address>
Output 2 where input msg.payload contains <Jeff's MAC address>
Output 3 otherwise
Check all rules is selected

As I mentioned later, I don't think this was a coding mistake - it just doesn't handle all of the conditions and I didn't remember all of them.

For example, where the input message comes from the probe request sniffer and contains an unknown MAC address I don't want to initiate an active scan, but I do need to initiate another scan with a 1 min delay if the input from the active scan node is missing one or both phones. I have to keep the scan alive in this loop because after the triggers have fired once for one of the phones they won't fire again until the phone is seen.

If I can find a way to switch the output based on the input message NOT containing a string, or if I can combine two expressions with an AND for one output, then I can reduce it to two switch nodes.

Edit: I managed to reduce the three switch nodes to two switch nodes. See subsequent post.

It's already written in python - this is a port! I find it much easier to come back to node-red after not looking at it for a long time. I might replace those switch nodes with a single function node, however.

I think the arp-scan actually pings the phones which will wake them up if they get sleepy, and the phones send probe requests well before they connect to the wifi. The latter saves false alarms when we first come in the door and my wife's nerves from preventing the alarm going off.

I have very few false alarms with both the scan and the sniffer. With only one or the other I have many more. Without the sniffer we have false alarms arriving home. Without the scan we have false alarms while we are at home because the phones don't send probe requests often enough for the sniffer to pick up.

I managed to reduce the switch nodes from three to two:

I'm not sure it's more readable but I'm confident this will behave as I wish. The first output of each of the switch node is where the input message contains the phone's MAC address as per the name of the node. The second output matches the text "arp-scan" which is part of the active scan output, but not the probe request sniffer (the mqtt input node). I have the nodes to stop checking after the first match.

I had forgotten that the sniffer's filter is set to exclude MAC addresses other than the two I'm interested in, so the probe request will always contain one or the other. As mentioned above, the sniffer message will never contain the text "arp-scan" which is matched to the second output.

The active scan node's output, however, will always contain the text "arp-scan", meaning that it will always trigger if the phone's MAC address is not present in the input.

@jeff65

Hi
please could you tell me how you did the scan? have you used raspberry pi ?