Returning additional info from a command_line sensor

Because of the way the command_line sensor works, this is kind of two questions in one and I’m not sure it can be achieved.

I am looking to add an entity that shows “wanted” movie information from Radarr. This is above and beyond what the standard Radarr integration will show. Essentially I am going to parse and re-format the results of a Radarr API call, and because of this is not a straight-forward JSON result I believe I need to use a shell script to achieve what I need. I have a working script and am no stranger to JSON and jq, so my question is regarding what the end result format needs to look like in order to achieve what I want.

I am looking to return several pieces of information in the one sensor, similar to what the standard Radarr ‘Upcoming’ entity has, presumably as attributes but I’m not 100% sure. The movie “detail” I am trying to add to my sensor appears to be in the standard entity as attributes in the format "title (year)": "date_available". See screenshot for example of the built-in radarr entity attributes:

The movie name keys in the screenshot are central to my question of how I do something very similar with a command_line sensor, as the title/year is actually the data I want but is variable and therefore I can’t define it as an attribute key to retrieve in a json result. I can format the json exactly in whatever way I want in order to achieve this, but when defining the command_line sensor in HA I appear to need to specify the exact json key values to retrieve as attributes, and do not have the ability to just retrieve “all” additional attributes in the response data.

So, is there a way to retrieve “all” attributes, in json format, when using a command_line sensor?

my current sensor definition is:

  - platform: command_line
    name: Radarr Overdue
    command: /config/scripts/radarr_overdue.sh
    unit_of_measurement: 'Movies'
    value_template: "{{ value_json.records }}"
    json_attributes:
      - *
    scan_interval: 900

and the sort of json response I want to injest is:

{
  "records": 4,
  "Movie Title 1 (2019)": "released",
  "Movie Title 2 (2020)": "inCinemas",
  "Movie Title 3 (2020)": "released"
}

Is there a way to return “all” attribute data without defining it in the sensor definition? If I can’t do it with a command_line sensor, is it possible to do with something else (a rest sensor maybe)?

Cheers from Down Under,
Jay

Edits: formatting, updated json to reflect my desired end-state instead of work-in-progress

I’m not sure if this is of help but you might try create a template sensor which loops through all attributes of a radarr sensor

I searched the forum for ‘loop attributes’ an this was the first hit.

It’s not ideal but it may well be a useful workaround if I can’t do what I need to “natively”. Also a generally useful tool for solving other problems. Thanks for taking a look!

This is a guess, not sure if it will work:

    json_attributes: $

Thanks, worth a try. I’m currently getting an error regarding my JSON formatting (“Unable to parse output as JSON”) so it might take me a while to test. Cheers

No, that produced no attributes.