Filter array with out index

I am building a Alarm that monitors all the doors on my property and would like to get a notification at 18H00 to inform me if any of them was left open.
I created a function that monitors the topic's and then sets their status in an array (Using collector)
This is what the Array looks like

{
Back Door : "OPEN",
Front Door : "CLOSED",
Garage Door : "OPEN"
}

How do I create a filter that will list all the Objects in the array that has the value "OPEN"?

Hi,

That is not an Array .. its an Object .. but you can convert its values into an Array with Object.values()

and then check if the newly created Array of values includes "OPEN" with includes()

Array.includes()

You can also use the for ... in method to iterate through an object directly and return if the value is open.

you could return the an array of keys that have the value "OPEN".

[{"id":"83c682b8.032bc","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"Back Door\":\"OPEN\",\"Front Door\":\"CLOSED\",\"Garage Door\":\"OPEN\"}","payloadType":"json","x":180,"y":2580,"wires":[["467a3774.0b20f8"]]},{"id":"467a3774.0b20f8","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\t$keys(payload.$sift(function($v, $k) {$v = \"OPEN\"}))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":2580,"wires":[["6d57c0db.f2671"]]},{"id":"6d57c0db.f2671","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":2480,"wires":[]}]
1 Like

Super thank you so much!! Now I need to go and study the code to understand what it is doing.

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