Advice for homebrew multi-room audio solution

Discussion in 'C-Bus Automation Controllers' started by shimms, Aug 12, 2023.

  1. shimms

    shimms

    Joined:
    Aug 12, 2023
    Messages:
    9
    Likes Received:
    1
    Location:
    Brisbane
    Hi all,

    After a quick bit of advice about creating a MRA replacement out of third party equipment and doing some scripting to get it all working together. Ideally I'd just chuck a native C-Bus MRA matrix switcher and remote amps in, but they're a bit hard to come by now, and the lack any support/warranty etc is a bit of a concern.

    So instead, I'm looking at purchasing a matrix switcher that supports RS-232 control, and programming eDLT actions to select inputs, control volume etc. The switcher would have 4 Sonos Ports as its inputs, one for each member of the family.

    We'd like to walk into any room, and from the eDLT select the desired input (the family member's Port), which would start that input playing on the room's mapped zone.

    We'd still use the native Sonos app to select whatever is playing on the individual Port, but use the eDLTs to easily start or stop that Port playing in a given room.

    Since the inputs are Sonos, I was thinking of using the Sonos API to get current track information, and ideally display that on the eDLT when a room is active.

    Just wanted to validate with people who know a bit more about this than me whether what I'm describing above is doable with an AC2 and a bit of custom LUA code.

    Cheers!
     
    shimms, Aug 12, 2023
    #1
  2. shimms

    Ks04

    Joined:
    Dec 28, 2019
    Messages:
    111
    Likes Received:
    9
    Ks04, Aug 13, 2023
    #2
  3. shimms

    shimms

    Joined:
    Aug 12, 2023
    Messages:
    9
    Likes Received:
    1
    Location:
    Brisbane
    Thanks - I hadn't seen that one, looks very useful.

    I had previously thought (incorrectly it seems from that linked post) that the MRA widgets could only control a real MRA matrix switcher. I didn't connect the dots that you could create a "virtual" MRA matrix as an application on the SHAC and have it receive the commands. Makes a lot of sense though now that I've seen it, and reduces the amount of coding I was thinking would be needed. Love that I could configure the eDLT using built in MRA goodness.

    The matrix switcher rather than Sonos groups is a bit unusual, I agree - essentially boils down to wanting to have a single Sonos for each person, rather than a Sonos for each room. It's a pretty subtle difference, and probably not a massive issue for most people, but we have a few annoyances with the room's speaker essentially being "shared" by each person in the house, and having to re-select what you were listening to last time you were in the room if someone has used it since and listened to their own thing.

    Also want to be able to use the eDLT to join the room to an existing stream (grouping speakers in Sonos speak, selecting a source in MRA speak). Source selection on the eDLT is a solved problem, managing Sonos groups via an eDLT is probably infeasible, and would require pulling your phone out to add the room to a Sonos group, rather than just hitting a couple of buttons on the wall panel on your way through.

    The linked post though gives me a heap of confidence that both solutions could work - either controlling Sonos speakers per room via the API, or controlling a third party matrix switcher via RS-232, thanks for sharing it.
     
    shimms, Aug 13, 2023
    #3
  4. shimms

    gte242

    Joined:
    Apr 7, 2017
    Messages:
    31
    Likes Received:
    5
    Location:
    Poland
    Curious did you every implement this and what did you choose in the end? Author of the link post above
    Gareth
     
    gte242, Oct 8, 2023
    #4
  5. shimms

    shimms

    Joined:
    Aug 12, 2023
    Messages:
    9
    Likes Received:
    1
    Location:
    Brisbane
    Haven't played with it at all yet sorry - a few higher priority things ahead of it still. Will post an update when I make some progress though if you're interested in how it goes.
     
    shimms, Oct 9, 2023
    #5
  6. shimms

    oracle

    Joined:
    Jan 18, 2010
    Messages:
    75
    Likes Received:
    2
    Location:
    NSW
    get home assistant running on low power PC and add node red to it and cbustomqtt - make a flow from in node red to look for cbus groups (state - on off) and another for level volume control add the sonos pallete to node red and make some links - this will work for the room speaker not person
    upload_2023-10-18_13-20-8.png see a test flow i made in node red monitoring 2 cbus group addresses (DLT) volume and an on/off - the volume is just a cbus level 0-255 then I made a function block to convert the 0-255 to sonos 0-100% plus some extra bits
    see below for function block in node red for volume conversion

    Code:
    // Define the lighting level range (input range)
    const lightingLevelMin = 0;   // Minimum lighting level value
    const lightingLevelMax = 255; // Maximum lighting level value
    
    // Define the Sonos volume range (output range)
    const volumeMin = 15;          // Minimum volume value
    const volumeMax = 50;        // Maximum volume value
    
    // Read the lighting level value from the object payload
    const lightingLevel = msg.payload.brightness;
    
    // Check if the lighting level is a valid number
    if (isNaN(lightingLevel)) {
        node.error('Invalid lighting level value');
        return null; // Abort further processing
    }
    
    // Map the lighting level value to the volume range
    let volume = Math.round((lightingLevel - lightingLevelMin) * (volumeMax - volumeMin) / (lightingLevelMax - lightingLevelMin) + volumeMin);
    
    // Make sure the volume is within the valid range
    volume = Math.max(volumeMin, Math.min(volumeMax, volume));
    
    // Convert the volume to a string or number explicitly
    volume = String(volume); // or volume = Number(volume);
    
    // Set the volume of the Sonos speaker
    
    msg.topic = 'group.set.volume';
    msg.payload = volume;
    
    // Return the modified message
    return msg;
    then in on off message functions search for state OFF and on and pass on to sonos
    OFF
    Code:
    // Check if the payload is "OFF"
    if (msg.payload === "OFF") {
        // Delete the existing payload and topic
        delete msg.payload;
        delete msg.topic;
    
        // Create a new payload and topic
        msg.payload = "group.stop";
        msg.topic = "group.stop";
    }
    
    // Return the modified message
    return msg;
    On
    Code:
    // Check if the payload is "ON"
    if (msg.payload === "ON") {
        // Delete the existing payload and topic
        delete msg.payload;
        delete msg.topic;
    
        // Create a new payload and topic
        msg.payload = "group.play";
        msg.topic = "group.play";
    }
    
    // Return the modified message
    return msg;
     
    Last edited: Oct 18, 2023
    oracle, Oct 18, 2023
    #6
  7. shimms

    shimms

    Joined:
    Aug 12, 2023
    Messages:
    9
    Likes Received:
    1
    Location:
    Brisbane
    That's awesome - I haven't dived into home assistant yet, but looks like something I probably should play with. Would much prefer to write this in javascript than lua too, so another plus. Thanks for the advice, will add this to the todo list.
     
    shimms, Oct 18, 2023
    #7
  8. shimms

    oracle

    Joined:
    Jan 18, 2010
    Messages:
    75
    Likes Received:
    2
    Location:
    NSW
    In your first post I noticed you said you had an AC2 if so you should be able to expose all cbus to an MQTT broker
    if so run a couple of docker containers in a NAS/small pc or something 1 container with mosquitto and 1 with node red. then you will have more than enough to link c-bus to sonos - my above code works but could do with polish around sonos ramp rate etc.
    if you haven't used node red I highly suggest having a play with it.
     
    oracle, Oct 18, 2023
    #8
    Mr Mark likes this.
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.