How to (re)name json_attributes (name, not content) in REST sensor?

Heyhey,

not sure if this is possible at all, but worth a try. So the situation is this: I’m using a REST sensor to query a public endpoint that amongst other fields provides this as part of the resultset:

        "ersteZiehung": {
            "ziehungsarten": [
                0
            ],
            "ziehungsdatum": "2022-12-25T00:00:00"
        },
        "letzteZiehung": {
            "ziehungsarten": [
                1
            ],
            "ziehungsdatum": "2024-01-07T00:00:00"
        },
        "naechsteZiehung": {
            "ziehungsarten": [
                1
            ],
            "ziehungsdatum": "2023-10-29T00:00:00+02:00"
        },

With the following combination I’m able to pull the actual date from the “naechsteZiehung” section as an attribute for the sensor:

    json_attributes_path: "$.displayData.naechsteZiehung"
    json_attributes:
      - ziehungsdatum

My problem: “ziehungsdatum” is too generic of a naming. It makes sense in the original context of the resultset, but in my sensor I’m losing the context.

Is there a way to manually override the attribute name that is given to the actual sensor attribute? From reading the documentation I only got that it gets derived directly from the JSON without “interception” option.

I know I could technically create a SECOND (template) sensor that uses the values from the original REST sensor, or I could create multiple sensors from the one REST call and store the attributes individually as dedicated sensor values, but both is overhead and “hacky” for my purposes.

Greatful for any hints, thanks in advance :slight_smile:

I only know to do this via jq so if no-one else has a good idea…
The other option is to load this and the create a new one based on that with templated attributes…

jq? like in jQuery? Curious to see how that would work

Yep… you can do something like this (you paste data which is impossible to guess)

cat file | jq '{attributes: [.displayData.naechsteZiehung[] | { newname : .ziehungsdatum } ]}'

and then use “attributes” when creating the sensor/template

sample from my aviationstack integration

ah, okay, completely outside the usual REST sensor “realm”, got it :slight_smile: It’s a bit beyond the level I would want to go for this case, but I learnt something new again. Thanks :slight_smile:

NP…if you have questions you can ask, I am not (!) a specialist, just a hacker :slight_smile: