Need help converting a WebAPI command to YAML

I’m trying to get my Klipsch Flexus 300 soundbar working. I’ve managed to get the commands that the Klipsch app sends to the soundbar through Wireshark; they’re simple URLs. I can parse them to see what the app is sending, but I’m new at this and I don’t know how to make the commands into HA code.

Example:
To power on the bar, the app is sending the following:
http://192.168.1.92/api/setDatapath=powermanager:targetRequest&roles=activate&value={"target":"online","reason":"userActivity"} HTTP/1.1

This is parsing to:
path=powermanager:targetRequest
roles=activate
value={“target”:“online”,“reason”:“userActivity”}

I imagine that it’s pretty easy to use this to make a command in YAML that I can add to automations, but I’m clueless as to how. Can anyone help?

EDIT: weirdly, the HA boards software is translating URL encoding into plain text - the actual URL that the app is sending is using % 22 without the space where quotes are appearing in the URL in this post, for example

There’s no integration/blueprint for that device? I’d look very hard for an existing integration or blueprint and save the api scraping and coordinating the conversation.

If not, something like this:

rest_command:
  my_device_on:
    url: "http://192.168.1.100/on"
    method: GET

Or this

rest_command:
  set_value:
    url: "http://192.168.1.100/set"
    method: POST
    payload: '{"brightness": 100}'
    content_type: "application/json"

I’d probably put it in a script but whatever works for your app

For the response, create a sensor:
sensor:


sensor:
  - platform: rest
    name: "My Device"
    resource: "http://192.168.1.100/status"
    value_template: "{{ value_json.temperature }}"
    scan_interval: 30

Those are examples but point in the right direction

If you can positively use this to the Klipsch from the cli using ‘curl’ then you could use the command_line integration

Command line - Home Assistant

Sadly there’s no integration! There’s one for Control4, but that won’t be happening any time soon :sweat_smile:

I’ll read into creating sensors in YAML. It’s a little confusing because the URL sent by the Klipsch app has three different commands in it, and everything I’ve seen in YAML (including the sensor ideas posted here) only have one place for payload. Any idea what the syntax would be if I use several commands?

I haven’t actually tried using curl yet. Checking to see if it works just went on today’s to-do list!

Okay, curl is working for me. I made Shell Commands for curl for each of the URLs, then made automations to call those Shell Commands. I can turn the bar on and off, mute and unmute it, and change between the inputs. For some reason the Media Player entry for the bar explicitly can’t do any of those things. But now I can!

… also now that I can control the bar I can turn off HDMI-CEC for power control in my system. A huge win (as long as I can keep eARC working… but that’ll be another thread :rofl:)

Keep it in this thread for completeness and a guide for others that may be following the same path of reverse engineering protocols.
Put all your commands in a spreadsheet, a column for each word, and then sort each column to see the patterns. They should become obvious, and guide you towards passing parameters to your CLI commands, and examining the responses.
Search widely - often you may stumble on a full list of commands from the vendor or their support forums, which will make your job far easier.
You could also just call their support line and ask - some vendors are quite happy to have their product become more popular and sell more and make more profits, and some think that information is the keys to their kingdom and should be closely protected.
Check if the DIRAC protocol is decoded.

Update: Found this with a two minute Google search, that you may wish to use with a simple Infrared controller:

Happy coding - all the hard work has already been done for you.

Oh, I’m aware that the IR codes are available. Not as sure that they work for IP control. As of now I have curl commands that do most of what I want to do. The downside is that each one is a direct command (eg mute or unmute), so I’m working on making scripts that make toggles.

Should be easy-ish for Mute or Night Mode, which are each just on/off. However, “volume up” and “volume down” commands don’t seem to exist - the commands are only setting the volume to specific values. So I’m going to have to make scripts that get the current volume value and call the command for a value either 1 higher or 1 lower. I’m new at scripting and have an ungodly amount of patience, so I might just make a series of if-then-else statements to call each command individually. If it all works out, I’ll post the code