Nested json to rest sensor attribute Mealie

I am trying to reach a nested json to add as an attribute to my rest sensor for my mealie mealplan.
I have added an extra API key called “message” but it is placed under a key called “extras”. Below is the full json for my dummy meal

{
  "id": "8e6d2195-abc1-4b65-bd2a-74ab25bf6297",
  "userId": "c8995dd2-b378-4cfa-bf04-32c157bed7ed",
  "groupId": "7a44e651-2f9e-4d51-ad11-88b32bae04bc",
  "name": "Burger med Oksekød",
  "slug": "burger-med-oksekod",
  "image": null,
  "recipeYield": null,
  "totalTime": null,
  "prepTime": null,
  "cookTime": null,
  "performTime": null,
  "description": "",
  "recipeCategory": [],
  "tags": [],
  "tools": [],
  "rating": null,
  "orgURL": null,
  "dateAdded": "2025-01-08",
  "dateUpdated": "2025-01-08T11:33:42.066923Z",
  "createdAt": "2025-01-08T10:20:15.742494Z",
  "updateAt": "2025-01-08T10:20:15.742495Z",
  "lastMade": null,
  "recipeIngredient": [],
  "recipeInstructions": [
    {
      "id": "b63e4d95-2529-43a2-a7a4-fc6c9c6cb3c6",
      "title": "",
      "text": "Du kan bruge markdown kode i beskrivelser og andre felter i opskrifter.\n\n**Tilføj et link**\n\n[Mit link](https://demo.mealie.io)\n",
      "ingredientReferences": []
    }
  ],
  "nutrition": {
    "calories": null,
    "fatContent": null,
    "proteinContent": null,
    "carbohydrateContent": null,
    "fiberContent": null,
    "sodiumContent": null,
    "sugarContent": null
  },
  "settings": {
    "public": true,
    "showNutrition": false,
    "showAssets": true,
    "landscapeView": false,
    "disableComments": false,
    "disableAmount": true,
    "locked": false
  },
  "assets": [],
  "notes": [],
  "extras": {
    "message": "Husk at tage kød op af fryseren"
  },
  "comments": []
}

My sensor is created like this:

- platform: rest
  name: mealie_mealplan_day1
  resource: myIP/api/groups/mealplans
  scan_interval: 3600
  headers:
    Authorization: Bearer myToken
  params:
    start_date: >
      {{ (now() + timedelta(days = 1)).strftime('%Y-%m-%d') }}
    end_date: >
      {{ (now() + timedelta(days = 1)).strftime('%Y-%m-%d') }}
  json_attributes_path: "$.[0].recipe"
  json_attributes:
    - id
    - name
    - slug
    - image
    - dateAdded
  value_template: "{{ value_json.date }}"

I can add stuff like dateAdded without any problems, but how do I reach the “message” under “extras” ?

I think you’ll just have to add extras as a structure, then the message will be available as:

{{ state_attr('sensor.mealie_mealplan_day1','extras')['message'] }}

So you mean adding it like this:

  json_attributes:
    - id
    - name
    - slug
    - image
    - extras

Because I tried that and it does not show in the attributes list.
Sorry if I misunderstand your suggestion. I am not THAT strong in this field :slight_smile:

That’s exactly my suggestion, and if you’re sure your JSON is as your original post, it absolutely should show up. Did you reload REST entities? (Developer Tools / YAML)

Yes i am sure about the JSON and also did try to reload :frowning:

Just updating this.

The JSON on my mealie instance showed the extra as in my first post, so I expected, that i would be exposed to Home Assistant also. However, looking into the documentation, the API only exposes these fields:

Copy
Expand allCollapse all
{
"date": "2019-08-24",
"entryType": "breakfast",
"title": "",
"text": "",
"recipeId": "31545f76-b27f-4c7c-9faf-229771396df1",
"id": 0,
"groupId": "eb54e96e-21b8-4f54-9cd4-80fccbd06f55",
"userId": "2c4a230c-5085-4924-a3e1-25fb4fc5965b",
"householdId": "b5d33c47-da83-44b4-b7bf-7ab3c5485f36",
"recipe": {
"id": "string",
"userId": "string",
"householdId": "string",
"groupId": "string",
"name": "string",
"slug": "",
"image": { },
"recipeServings": 0,
"recipeYieldQuantity": 0,
"recipeYield": "string",
"totalTime": "string",
"prepTime": "string",
"cookTime": "string",
"performTime": "string",
"description": "",
"recipeCategory": [ ],
"tags": [ ],
"tools": [ ],
"rating": 0,
"orgURL": "string",
"dateAdded": "2019-08-24",
"dateUpdated": "2019-08-24T14:15:22Z",
"createdAt": "2019-08-24T14:15:22Z",
"updatedAt": "2019-08-24T14:15:22Z",
"lastMade": "2019-08-24T14:15:22Z"
}
}

I tried adding the tags, and they do show by adding - tags to my json_attributes, so your method works. My problem is, that the extras are not exposed to Home Assistant, as far as I understand.

Thanks for helping out :slight_smile:

1 Like