End Goal: Automatically create or delete folders in the /media/sounds/ share when a new entity is created that qualifies.
To verify if an entity qualifies, I simply add “audio_enabled: true” as an attribute to the entity using the customize.yaml file.
Periodically, NodeRED runs an inject through a flow that assembles various lists of information.
List 1: An array of all entities that are sound enabled. (i.e. audio_enabled: true")
List 2: An array of top level folders found inside of /media/sounds/
List 3: this is the list I’m trying to figure out how to make. It needs to be a list of items from list 1 that are NOT matching anything in list 2.
I have a flow that produces the following msg in NodeRED:
object:
payload: array[2]
topic: ""
audio_enabled: array [2]
0: object
entity_id: "input_button.whatever"
1: object
entity_id: "whatever"
top_level: array[12]
[0 ... 9]
0: "camera"
1: "grandfather_clock"
2: etc.
I need to compare “audio_enabled” to “top_level”. If there’s something in “audio_enabled” that isn’t in “top_level”, push that missing value into a new list. With that list I can then use another node to create that new folder.
I’m imagining something like “for every item in audio_enabled.[i].entity_id
, check all items in top_level, and if there’s no match, add that item to a third array. If there is a match, move on.”
Any javascript wizards out there that can help me with this? I can work on splitting up the domain from the entity so we end up with “input_button” as a string, but the rest I’m a bit fuzzy on.