Create "Smart App" that can switch inputSource on my Samsung soundbar (HW-N950/N960)

Add your computer as a device to an activity. I added my Mac Mini. I choose one of the OSX shortcuts as button press trigger, and then in OSX I mapped that shortcut (CMD-X for example) to run a script which in turn triggers the URL.

I was able to get this working. Used the URLs and then used virtual buttons to launch each of the urls. I then authorized the devices through the Harmony/Smarthings connect. Through a button press, I can switch to the correct input and I can add them into the activities. It now works perfectly.

For anyone wanting to use the virtual buttons here is the link:

Hey,

Do you need a SmartThings hub for this to work with an internal IP?

Thanks.

I believe you do. I couldn’t find any other way for Harmony to launch a web command.

Hi Daniel,

Does this still work for you? I recently bought a HW-Q90R soundbar and want to switch HDMI input by firing the right url at it. Unfortunately, this only works very unreliably. Sometimes it responds correctly and sometimes it just doesn’t do anything at all. It doesn’t make a difference whether I run the url from a webbrowser or through a script, so I hope to get some assistance here in getting things fixed.

The url to switch to HDMI2 for example is:
http://192.168.178.43:56001/UIC?cmd=<name>SetFunc</name><p%20type="str"%20name="function"%20val="hdmi2"/>

The soundbar is running the latest firmware (1008.0 126R).

EDIT: The soundbar responds to other commands without any delay, for example to put it on mute or change the volume level. Also, retrieving information with one of the Get commands works just fine.

Yes, it still works very reliably for me. Use it every day.
Are you sure you are not already on hdmi2 when you trigger the hdmi2 command? Because that will cause your issue. Nothing will happen.

Yes, 100% sure.

It seems to happen especially after the soundbar has been powered off for at least a few hours. You would think it’s in some sort of sleeping mode, but despite that it still reacts to volume changes via url instantly.

I would love to use these URLs to change the input on my HW-Q90R, but it doesnt have an IP-adress. Do I need this Hub thing for that to work? Can I use the Phillips Hue Hub or IKEA hub instead? Or a Logitech Harmony Hub?

Daniel, How du you trigger the url from your Harmony? I have a Harmony Hub, but I can’t figure out how to get the Harmony, to fire the url against my soundbar. Do you use a SmartThings hub, og another piece of equipment?

/Kristian.

It does have an ip address, but you won’t find it in the app, so you should check your router for that.

You can fire a url at it from, for example, Domoticz or Home Assistant. I myself have the Harmony Hub connected to Domoticz. Each Harmony ‘activity’ is shown as a switch in Domoticz. Upon activation of an activity, it switches on or off in Domoticz. You can configure Domoticz to run a script or url upon activation of that switch.

I did it with Home-Assistant. Installing home-assistant was straight forward, i had a pre-existing media server running Ubuntu Server 20.04. Created groups and users, create the directory for the application and configuration then install the docker container.

~$ sudo groupadd -g 1002 homeassistant
~$ sudo useradd -s /usr/bin/bash -m -d /opt/homeassistant homeassistant
~$ sudo su - homeassistant
bash-5.0# mkdir /opt/homeassistant/config
bash-5.0# exit

~$ sudo docker create
–name=“home-assistant”
–net=host
-e PUID=1002
-e PGID=1002
-e “TZ=Australia/Melbourne”
-v /opt/homeassistant/config:/config
homeassistant/home-assistant:stable

After installing Home Assistant and importing the devices it found for home-automation on my network, most importantly the Harmony Hub, i created/edited these files to build my configuration and automations:

 

/config/soundbar/curlhdmi1

/config/soundbar/curlhdmi1

/config/soundbar/curlarc

/config/shell_commands.yaml

/config/automations.yaml - this already existed but was empty.

/config/configuration.yaml - this already existed but added configuration to it.

 

/config/soundbar/* contains a file each for each of the Web URL calls require to change to that input that I want, which is (based on your submission):

bash-5.0# pwd
/config/soundbar
bash-5.0# cat curlhdmi1
http://SamsungN950:56001/UIC?cmd=<name>SetFunc</name><p%20type="str"%20name="function"%20val="hdmi1"/>
bash-5.0# cat curlhdmi2
http://SamsungN950:56001/UIC?cmd=<name>SetFunc</name><p%20type="str"%20name="function"%20val="hdmi2"/>
bash-5.0# cat curlarc
http://SamsungN950:56001/UIC?cmd=<name>SetFunc</name><p%20type="str"%20name="function"%20val="arc"/>

From there I can show the calls made using the CLI command 'curl' to make a http call to change the input from the /config/shell_commands.yaml file:

bash-5.0# pwd
/config
bash-5.0# cat shell_commands.yaml
set_soundbar_hdmi1: 'curl --connect-timeout 2 $(cat /config/soundbar/curlhdmi1)'
set_soundbar_hdmi2: 'curl --connect-timeout 2 $(cat /config/soundbar/curlhdmi2)'
set_soundbar_arc: 'curl --connect-timeout 2 $(cat /config/soundbar/curlarc)'

I then used an example from the home-assistant website about using triggers from harmony_hub to then run an action. This is what i've got in /config/automations.yaml (i don't have an ARC input configured yet, but I have the shell command built to use it in the future).

bash-5.0# pwd
/config
bash-5.0# cat automations.yaml
- alias: "Watch PayTV started from harmony hub"
  trigger:
    platform: state
    entity_id: remote.harmony_hub
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "Watch PayTV" }}'
  action:
    service: shell_command.set_soundbar_hdmi1
- alias: "Switch to SHIELD TV started from harmony hub"
  trigger:
    platform: state
    entity_id: remote.harmony_hub
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "SHIELD TV" }}'
  action:
    service: shell_command.set_soundbar_hdmi2
- alias: "PowerOff started from harmony hub"
  trigger:
    platform: state
    entity_id: remote.harmony_hub
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "PowerOff" }}'
  action:
    service: input_boolean.turn_off
    entity_id: input_boolean.notify

The names for the 'variables' in the value_template trigger.to_state.attributes.current_activity are from the harmony_DEVICENAME.conf which comes down from the harmony hub discovery. This is in the /conf directory.

bash-5.0# pwd
/config
bash-5.0# head harmony_13095281.conf
{
    "Activities": {
        "-1": "PowerOff",
        "34322322": "Watch PayTV",
        "34322331": "SHIELD TV",
    },
...

The final configuration is to update the /config/configuration.yaml to be sure it can inherit the shell_commands.yaml file:

bash-5.0# pwd
/config
bash-5.0# cat configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
- platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
shell_command: !include shell_commands.yaml

As a result when Logitech fires a change of activity which requires a change in input on the Samsung N950 soundbar, it fires the line:

action: service: shell_command.set_soundbar_hdmi2

which essentially runs the commandline equivalent (with http return data):

bash-5.0# curl --connect-timeout 2 'http://SamsungN950:56001/UIC?cmd=<name>SetFunc</name><p%20type="str"%20name="function"%20val="hdmi2"/>'

<?xml version=“1.0” encoding=“UTF-8”?><UIC><method>PowerStatus</method><version>1.0</version><speakerip>10.0.0.61</speakerip><user_identifier>public</user_identifier><response result=“ok”><powerStatus>1</powerStatus></response></UIC>

This also turns on the soundbar if it is off which is a benefit.

 

Now if only the Harmony could embed Web Calls like this, i wouldn't have to do this and it would be IMMENSELY easier out of the box for direct input change rather than input cycling. Hopefully a FW update in the future for the N950 doesn't break this access.

 

With all this information, and an existing media center that is docker enabled, I could get this up and running in under 10 minutes now.

 

HI Daniel,
can i use this URL to turn ON or OFF the sondbar?
thx

Is there a path to set the Sound Mode?

I can use UIC?cmd=GetSoundMode
and that returns with the correct sound mode Surround, Game, ect


but UIC?cmd=SetSoundMode<val=“standard”/> times out :frowning:

Hej Daniel, when you trigger from Harmony what solutions are involved. I get the URL to work from my browser so that’s fine but how to get this to work from an activity on my Harmony Hub remote? I saw some IFFT solutions but don’t want that. What I do have is Home Assistant and maybe that is a way forward?
Thanks

Does this still work? Trying to utilize it with a HW-Q800B if possible?

I’d love to know how to use this on HW-Q950A Soundbar or similar. Local control of the soundbar would be amazing. Hate having to rely on an external SmartThings API.

Anyone figure it out? I tried firing off those test commands on ports 55001 or 56001 or 55000 against my Soundbar IP address but nothing happens. I also tried running nmap on the Soundbar to determine any other open ports. Then I tried the test commands on those open ports as well
but nothing happens :frowning:

I use a combination of Todd Austin’s edge bridge and web requestor to achieve this.

I then link various SmartThings API calls to automations, using Aqara cube.

Double tap it to toggle HDMI 1 and 2, Rotate to volume up and down. Flip it mute, and a few other things I don’t remember.

Could you give me a link to the"web requester" you’re referring to. I found the Edge Edge. Thanks!

Web requestor example entry to set HDMI 1 


Web Request1:

post:http://[enter your edge bridge up address here]:8088/api/forward?url=https://api.smartthings.com/v1/devices/[long alphanumeric string for your device id of the soundbar]/commands]

Web Request 1 body:

{“commands”:[{“component”:“main”,“capability”:“mediaInputSource”,“command”:“setInputSource”,“arguments”:[“HDMI1”]}]}