JsonPath - REST - Template - how to get the minimum value with condition

Hi folks,

I’ve used https://jsonpath.herokuapp.com/ to get working filter:


It gets the right JSON for me. But how to implement this JSONPath expression? Using a rest sensor with a value_template should do the trick. But I keep running into a configuration error for the filter character ‘$’

Invalid config for [sensor.rest]: invalid template (TemplateSyntaxError: unexpected char '$' at 15) for dictionary value @ data['value_template']. Got '{{ value_json.[$.[?(@.ModeloID=="ABC123)].Price]] }}'. (See ?, line ?).

below the JSON output of the API:

      "Model1":"Product1 XXX with descriptions ASD",
      "Model1":"Product1 YYY with descriptions",
      "Model1":"Product2 XXX with descriptions ",

I need to get the minimum value price from each model ID, example:

So I found a way, from @petro in another topic and it works nicely! In his suggestion he gets the first number found in his list, and for my luck, my data set is ordered by asc, so the first price is the lowest price.

Below my rest code:

  - platform: rest
    name: pricestore_abc_price
    resource: https://www.example.com/mylist.json
    scan_interval: 30
    timeout: 60
    force_update: true
    verify_ssl: false
    value_template:  >
      {% set items = value_json | selectattr('ModelID','eq','ABC123') | list | first %}
      {{ items['Price'] }}
    unit_of_measurement: $

But it only return the price, i cant get the respective attributes from that price:

      - Model1
      - Price
      - Price2
      - Store
      - Link
      - ModelID

How can I put this attributes to show in the same entity?

I tried the suggestion that @petro said in another topic, to use:

#       {{ items.items() | selectattr(0, 'in', attributes) | sort(attribute=0) | map(attribute=1) | join(',') }}

and create a platform template to show… but i received a error saying there is more than 255 characters which is the limit.

anyway, I really would like to have my entity from pricestore_abc_price with the price and its respective attributes.

would it be possible?

Hi folks, no one has a clue?

use json_attributes_path in combination with json_attributes

How to use it in combination? I tried with no success. Could you give me a generic example?

The examples in the documentation show a basic use of json_attributes_path. What you have is probably not basic, so how about you post what you’ve tried.