Assistance with the Command line integration with attributes

I’m attempting to use the command_line integration to create a entity with metadata attributes. Here’s what the response from the API looks like:

{ "metaData": { "album": "unknow", "title": "Radio Paradise", "subtitle": "Editors - The Weight of the World", "artist": "unknow", "albumArtURI": "http://cdn-albums.tunein.com/gn/101008JL6Wg.jpg", "sampleRate": "44100", "bitDepth": "32", "bitRate": "128", "trackId": "s13606" } }#

Here’s what I’ve been struggling with. Consider it a superset of frustration.

command_line:
  sensor:
    name: WiiM Ultra Track MetaData
    json_attributes_path: "$.*.metaData."
    command: 'curl -k "https://192.168.60.99/httpapi.asp?command=getMetaInfo"'
    value_template: "{{ value_json.metadata }}"
    json_attributes:
      - "album"
      - "title"
      - "subtitle"
      - "artist"
      - "albumArtURI"
      - "sampleRate"
      - "bitDepth"
      - "bitRate"
      - "trackId"
    scan_interval: 5

Thanks in advance

Remove all the attributes and just add metaData

I’ve attempted your suggestion with and without the commented lines and I only get an entity with unknown entity state and no attributes. Am I misinterpreting your suggestion?

command_line:
  sensor:
    name: WiiM Ultra Track MetaData
    #    json_attributes_path: "$.*.metaData."
    command: 'curl -k "https://192.168.60.99/httpapi.asp?command=getMetaInfo"'
    #    value_template: "{{ value_json.metadata }}"
    json_attributes:
      - "metaData"
    scan_interval: 5

If you fix your json_attributes_path it will probably work.

json_attributes_path: "$.metaData"

Not sure what your value_template is supposed to accomplish. A state can only be 255 characters, depending on the length of the track metadata this may overflow and completely break the sensor. Better to replace it with say a timestamp for when the sensor was last updated.

value_template: "{{ now() }}"
device_class: timestamp

Thanks, but no progress to report. I’ve tried the following, again with and without the commented lines. Let me know if you see anything I need to fix or try.

command_line:
  sensor:
    name: WiiM Ultra Track MetaData
    json_attributes_path: "$.metaData"
    command: 'curl -k "https://192.168.60.99/httpapi.asp?command=getMetaInfo"'
    value_template: "{{ now() }}"
    device_class: timestamp
#    json_attributes:
#      - "metaData"
    scan_interval: 5

As for the value_template, it wasn’t clear to me how it would behave in this application. The examples I’ve seen only show numerical objects. That said, I like your suggestion. Also, I’ve tried the jason_attribute_path you suggested already, but other things might’ve been misconfigured.

Edit: This is the current entity state:

Well all I did was take your sample API response and paste it into a JSONPath online evaluator and make sure the path worked. Your sample response does have an erroneous # at the very end though, I assume that was snuck in during copy-paste and is not actually included in the responses from the player?

Anyway… I have no experience with command line sensors so hard for me to say what isn’t correct. But that being said, why exactly are you using a command line sensor in the first place? Considering all you are doing is quering a REST API, the logical thing to do would surely be to use an actual RESTful Sensor.

Something like this:

rest:
  - resource: https://192.168.60.99/httpapi.asp?command=getMetaInfo
    scan_interval: 5
    sensor:
      - unique_id: e3910c11-42ae-4f4c-b192-4b309f0e671d
        name: WiiM Ultra Track MetaData
        device_class: timestamp
        value_template: "{{ now() }}"
        json_attributes_path: "$.metaData"
        json_attributes:
          - "album"
          - "title"
          - "subtitle"
          - "artist"
          - "albumArtURI"
          - "sampleRate"
          - "bitDepth"
          - "bitRate"
          - "trackId"

Unfortunately, the # is baked in. I see it on another command with a JSON response as well. If it’s unusual, I can contact the support folks for the product.

I’m using the command line sensor because it appeared appropriate to the application. I’ll try your recommendation and see how far I get. Hopefully, it can work with the uninvited guest. Otherwise I might try to pipe it through a sed command. I think I’ve seen examples somewhere.

I’ll report back.

Then I would guess that is the problem, as it is not valid JSON. Seems like a bug the WiiM developers ought to fix.

Edit: Sure you didn’t get the # from say the shell prompt when copying from a terminal? Surely the WiiM developers would use preexisting libraries for the JSON output etc. so seems like a really weird thing for them to mess up…

1 Like

Damn if you’re not right. I just used a browser and it came up clean.

I had to add verify_ssl: false to the YAML. It’s working now.

Thanks a million.