How to open the file

Good day!

I have a file, for ease of understanding its structure is similar to .shopping_list.json how can I read data from it and put it in a sensor or any other place so that I can easily access it? They do not fit into the status of the sensor (since the status is limited to 255 characters).

what i tried:

  • via sensor status (lacks size)
  • through the attributes of the sensor (I did not find a suitable example and code, it did not work out by typing or trial or error)
  • through the services 1 time did not work because import does not work, I wrote a script without import, f.open does not work …

thanks for any hints!

P.S. Sorry for my bad english

I have no idea what this is can you give an example?

Exactly what data do you want?

.shopping_list.json:

[
    {
        "complete": false,
        "id": "eadac2fa5f1143268574daf8d57ed8d5",
        "name": "12332131"
    },
    {
        "complete": false,
        "id": "0e2eaa8f587b4433b34195b64d8b5d70",
        "name": "5464564"
    }
]

names separated by commas, but there are a lot of them

solved with json_attributes and python_scripts!

py:

#!/usr/local/bin/python
# coding: utf8
import datetime
import json
    
now = datetime.datetime.now()
with open('.shopping_list.json') as data_file:
    ShoppingListtData = json.load(data_file)
 
content_name = u""
for entry in ShoppingListtData:
    if not entry['complete']:
        content_name += u"%s, " % (entry['name'])
print (json.dumps({"upd_time": now.strftime('%H:%M:%S %d-%m-%Y'), "content_name": content_name[:len(content_name)-2]}))

yaml:

sensor:
  - platform: command_line
    name: ShoppingListtData 
    json_attributes:
      - upd_time
      - content_name
    command: python3 "/home/homeassistant/.homeassistant/python_scripts/123.py"
    value_template: "{{ value_json['upd_time'] }}"