Get Entities By Manufacturer

One of my subflows has a node that searches for then creates an array based on the entity_id of some of my Sonos speakers. Search criteria is filtered on the naming convention of the Sonos devices in HA.

I have a need to create a similar subflow but in this case, the Sonos entitiy_id names don’t contain a common element that can be searched on. Is it possible to search using the Manufacture name rather than entity_id? I tried the following but the node reports no entities found, regardless of the spelling of manufacturer.

Following is my working subflow;

[{"id":"88f64612ee252d1a","type":"ha-get-entities","z":"4ed4def360353223","name":"ID Sonos Speakers","server":"fcf9b76b.256a88","version":0,"rules":[{"property":"entity_id","logic":"is","value":"(?<=media_player)(.*)(?=_sonos$)","valueType":"re"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"sonos_speaker_list","output_results_count":1,"x":250,"y":140,"wires":[["bb2022cfc987684f"]],"info":"The name of all Sonos speakers installed in the house ends with _sonos. Use a filter to identify and build an array of all active speakes."},{"id":"bb2022cfc987684f","type":"function","z":"4ed4def360353223","name":"Create Listing","func":"msg.sonos_speaker_list_entity_id = []\nfor (var i = 0; i < msg.sonos_speaker_list.length; i++) {\n        msg.sonos_speaker_list_entity_id[i] = msg.sonos_speaker_list[i].entity_id;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":140,"wires":[["993c9e14ec182896"]]},{"id":"993c9e14ec182896","type":"api-call-service","z":"4ed4def360353223","name":"Ungroup Sonos Speakers","server":"fcf9b76b.256a88","version":5,"debugenabled":true,"domain":"sonos","service":"unjoin","areaId":[],"deviceId":[],"entityId":[],"data":"{\"entity_id\":\"{{sonos_speaker_list_entity_id}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":140,"wires":[[]]},{"id":"fcf9b76b.256a88","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

I don’t have a sonos, so I can’t say what information is sent with the event. When you look at the debug output from the sonos find the value “sonos” and note the path.

When filling out the property box the auto fill will show available paths. Choose the one that matches, then use the regex filter.

I’m not sure how to convert this for use in Node-Red but this template lists all Sonos media_players:

{{ integration_entities('sonos') | select('search', '^media_player') | list }}

Slight problem… there’s no output from the node! Zero’s entities found!

How should the node be configured in order to return a list of informaiton?

Thank you, I also found a template which returns a list by manufacturer;

{% set ns = namespace(player=[]) %}
{% for state in states.media_player if is_device_attr(state.entity_id, 'manufacturer', 'Sonos') %}
  {% set ns.player = ns.player + [state.entity_id] %}
{%- endfor %}
{{ ns.player }}

Now, if I could only figure out how to convert either your contribution or this template into a Node-Red node!

manufacturer != Manufacturer

If the loop returns a valid response then I would say you need to check the M in node red.
And I believe you should write attributes.manufacturer

I recognize the second example you found. It’s a longer way to get the same result.

1 Like

Yes, I should have mentioned that I’ve tried both spellings.

I don’t see attributes.manufacturer in the nodes drop-down property list. Adding it manually still results in an empty array. I also don’t see the term ‘manufacturer’ in the nodes drop-down property list. If the attribute is not in the list, can it be added manually?

If it’s not there then I don’t think you can search on it.
But this is what I see:

That’s very interesting, I don’t see that attributed listed!

Are you running Node-Red from the HA add-on or stand-alone? Which version of NR are you using?

Yes add-on. 11.0.1

I’m using the Add-On as well. The version number is 11.0.3. I wonder if there was a change that removed the attribute? I’ll check the change log to see. Will report back later today.

Check your HA nodes are up to date. Right side menu, manage palette, search home assistant. If there is an update button in the lower right corner press it. It may need to be pressed multiple times, then follow restart instructions.

To find attribute paths, you look at the debug by setting a current state to the entity. Do not set any state. Set the debug node to complete message object.

Then the message you will get in the debug

Here you will see an entity’s property paths and values.

I figured this part out! There’s a node named “render template”. I added this node with the template code and it works perfectly.

Doing so doesn’t reveal a path to the manufacture name. There’s no attribute named manufacturer. I believe the Get Entities node is the approach I need to follow. Just need to figure out why the manufacturer attribute isn’t showing up.

Shortly after you posted this replay, an HA update was made available. I applied that, restarted Node Red then checked for and updated all Home Assistant nodes. Neither restarting Node Red or Home Assistant made a difference to the missing attribute. I even restarted the HA server, still no appearance of the attributes.manufacturer in the “get entities” node.

More research required!

@rcblackwell ever figure this out?

Not really. In the end I concluded that manufacturer name is not one of the attributes available on a Sonos speaker. As luck would have it, when I named my speakers I included the suffix “_sonos” in their name. I ended up using the get entities node to search for that information. Here’s the code for the node that builds an array of devices;

[{"id":"8fa424986cca3c5d","type":"ha-get-entities","z":"2daf88a8cb1e7dfd","name":"ID Sonos Speakers","server":"fcf9b76b.256a88","version":0,"rules":[{"property":"entity_id","logic":"is","value":"(?<=media_player)(.*)(?=_sonos$)","valueType":"re"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":550,"y":140,"wires":[["3a09b06de6d403e8"]],"info":"The name of all Sonos speakers installed in the house ends with _sonos. Use a filter to identify and build an array of all active speakes."},{"id":"fcf9b76b.256a88","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

@rcblackwell here ya go, answer here:

@jaaasshh, wonderful find! I see the output includes all Sonos devices; controls as well as media players. Did you figure out how to how to filter controls from the speakers?