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.")
            return
    
        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:
osc_send_madmapper:
  module: osc
  class: OSCSend
  param1: osc-madmapper
  param2: 10.0.1.5
  param3: 8000

osc_send_x32:
  module: osc
  class: OSCSend
  param1: osc-x32
  param2: 10.0.1.100
  param3: 10023
  1. Setup some scripts to send the actual commands to the AppDaemon apps like this:
alias: MadMapper - Cue - Open
sequence:
  - event: osc-madmapper
    event_data:
      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.

4 Likes

Nice Progress! This gets me started, Thank you.

Any updates over the last year?

Well yes and no. I’ve never gotten OSC Feedback working. In my environment it was really more of a want than a need since I’m pretty much only using HA to control everything anyways so the state of devices stays more or less consistent. I don’t know if it’s possible to do at all given the architecture of AppDaemon.

I tried to do a direct HA integration but the people that manage the Home Assistant project turned out to be real *ssholes so I quit that route. Basically I just decided that what I had was working pretty well.

The one thing that I figured out was that it’s super easy to setup new commands using something like a pulldown menu doing something like this:

address: /scene/{{ states('input_select.qlc_scene') }}
message:
  - 1

With this approach I can basically just dynamically create OSC commands without ever touching the underlying script. If that doesn’t make sense, I can try to explain it better.

that totally makes sense.
Glad I checked in. I was just going to try my hand at making an OSC_Client integration.
basically, pre-populating the IP:PORT that could receive an OSC address and value from an action.
Being a total HA noob, I think I’m overthinking things and a script will do the job. :smiley:

If you decide to go down that road, definitely feel free to send me a message and maybe we can work on it together. I have a little knowledge about a lot of things including programming. I can write a little code in a few different languages but I’m by no means what you might call a “programmer.”

I’m honestly surprised that this doesn’t exist yet given the amount of Home Assistant integrations. It really doesn’t seem like it should be that hard for someone who knows what they’re doing but when I was trying to get help on this, it seemed like I was speaking freaking Greek when I was trying to explain what I was trying to accomplish.