#Reading a whole file into a sensor (File integration)

1 messages · Page 1 of 1 (latest)

upbeat ridge
#

I want to read a whole file into a sensor like the File Integration https://www.home-assistant.io/integrations/file/ does it from the homeasssitant file system. My issue with the File integration is that it only reads the last line into the sensor. But my file I want to read is human readable formatted JSON file so its got a few line breaks. I really haven't found any answer to this pretty simple problem as many threads seem outdated.
My current configuration.yaml is

homeassistant:
  allowlist_external_dirs:
    - "/config/www"
file:
  - action: file.read_file
    data:
      file_name: config/www/myfile2.json
      file_encoding: JSON
    response_variable: file_content

And the integration is properly setup via the UI File integration as it displays the last single line.

With reading a file I want to achieve reading the config/.storage/lovelace.dashboard.json file. I want to use it for the auto-entities HACS card to only display entities of a certain device which is currently not configured anywhere else in the dashboard

Home Assistant

Instructions on how to integrate sensors which read from files into Home Assistant.

urban sparrow
#

Entities can only have 255 characters, so this might be a problem.

upbeat ridge
#

Yeah, I just found that out too when trying to setup a helper text and using an automation to set the value.