OSC Client/(Server?) with AppDaemon

I’ve been in the process of porting my Automation platform to HomeAssistant and have been tackling some of the more advanced things I could do on my previous system lately. Most recently, I’ve implemented a solution to send OSC (Open Sound Control) messages to various components in my setup (e.g. MadMapper, Behringer X32 Mixer, QLC+). I was pleasantly surprised to find that it was pretty easy to do this using AppDaemon. In case it is helpful for others, here is a basic walkthrough of what I did.

  1. Installed the python-osc library using AppDaemon’s “install additional libraries” configuration option

  2. Wrote a simple AppDaemon app to handle OSC requests which is as follows:

import hassapi as hass
from pythonosc.udp_client import SimpleUDPClient

class OSCSend(hass.Hass):

    def initialize(self):
        self.destination = self.args["param1"]
        self.ip = self.args["param2"]
        self.port = self.args["param3"]
        self.client = SimpleUDPClient(self.ip, self.port)
        self.log(f"OSC Client connected to {self.destination}: {self.ip} on Port: {self.port}")

        self.listen_event(self.send_osc_message, self.destination)
    def send_osc_message(self, event_name, data, kwargs):
        address = data.get('address')
        message = data.get('message')
        if not address:
            self.log("OSC address is empty, message not sent.")
        self.client.send_message(address, message)
        self.log(f"OSC Message Sent to {address} with message: {message}")
  1. Setup a couple of apps in my apps.yaml (AppDaemon config file) like this:
  module: osc
  class: OSCSend
  param1: osc-madmapper
  param3: 8000

  module: osc
  class: OSCSend
  param1: osc-x32
  param3: 10023
  1. Setup some scripts to send the actual commands to the AppDaemon apps like this:
alias: MadMapper - Cue - Open
  - event: osc-madmapper
      address: /cue/open
      message: 1
mode: single

Pretty straightforward, flexible, easy to edit, and works great!

Now the next step (and my reason for posting here) is because I can’t figure out if there is any way to handle OSC feedback inside of AppDaemon. I understand that it’s possible to send things to AppDaemon with the REST API, but given that this is OSC, I really don’t have that option. I really need to be able to bind to a port (ideally the same port that I’m sending data out of) and listen for responses on that port. I believe I have the code for that, but I can’t seem to find any good info on how (or if it is even possible) to bind to a port and expose it in HAAS. it would be much appreciated if someone more knowledgable than me could shine some light on this.