Sending simple tcp packets

Hi

So, I’m trying to see if this is solvable without going the development route. I’ve been searching the forums, without really getting the answers I’m looking for.

So, I have a soundbar from LG (LAS950M), and I’m trying to control the sound effect (music, movie etc) from Home Assistant. After much wiresharking and packet traces, I’ve finally found the tcp packets being sent from the LG app (MusicFlow) to the soundbar, and I’m able to manipulate this from my pc and change sound effect on soundbar.

Now, I want to automate this in HA. I don’t really need to have some fance UI for this, as it will be automated f.ex “if Spotify, change effect to music. if Netflix, change effect to movie”.

Any tips on how I can achieve this?

Hi

So I was able to solve this myself. Solution was to use netcat, and pass the hex like this:

echo -n -e "\x00\x00\x00\x00\x30\x7b\x22\x64\x61\x74\x61\x22\x3a\x7b\x22\x74\x79\x70\x65\x22\x3a\x30\x2c\x22\x76\x61\x6c\x75\x65\x22\x3a\x37\x7d\x2c\x22\x6d\x73\x67\x22\x3a\x22\x45\x51\x5f\x53\x45\x54\x54\x49\x4e\x47\x22\x7d" | nc <ip> <port>

To be able to pass different hex’es into this, I created this as a bash script:

#!/bin/bash

echo -n -e "$1" | nc <ip> <port>

Next, I created a script like this:

lgsoundbar:
    alias: LG SoundBar EQ
    sequence:
      - service_template: >
          {% if is_state ('input_select.soundbar_eq' , 'Cinema') %}
          shell_command.eq_cinema
          {% elif is_state ('input_select.soundbar_eq' , 'Music') %}
          shell_command.eq_music
          {% else %}
          {% endif %}

which based on a selected input_select runs a shell_command. The shell_commands are defined like this in configuration.yaml:

shell_command:
   eq_cinema: sh /config/scripts/lg_las950m/soundbar_sound_effect.sh "\x00\x00\x00\x00\x30\x7b\x22\x64\x61\x74\x61\x22\x3a\x7b\x22\x74\x79\x70\x65\x22\x3a\x30\x2c\x22\x76\x61\x6c\x75\x65\x22\x3a\x37\x7d\x2c\x22\x6d\x73\x67\x22\x3a\x22\x45\x51\x5f\x53\x45\x54\x54\x49\x4e\x47\x22\x7d"
   eq_music: sh /config/scripts/lg_las950m/soundbar_sound_effect.sh "\x00\x00\x00\x00\x30\x7b\x22\x64\x61\x74\x61\x22\x3a\x7b\x22\x74\x79\x70\x65\x22\x3a\x30\x2c\x22\x76\x61\x6c\x75\x65\x22\x3a\x36\x7d\x2c\x22\x6d\x73\x67\x22\x3a\x22\x45\x51\x5f\x53\x45\x54\x54\x49\x4e\x47\x22\x7d"

The input_select:
input_select:
soundbar_eq:
options:
- Cinema
- Music

And last an automation:
- id: ‘1525245792589’
alias: Change LG Soundbar Sound Effect
trigger:
- entity_id: input_select.soundbar_eq
platform: state
condition: []
action:
- entity_id: script.lgsoundbar
service: script.lgsoundbar

Next step is to automate functionality to change this automatically when something is playing on the soundbar.

3 Likes

Very nice. Thanks for sharing.