Right that doesn’t work, hard-coded file path only.
A command line sensor accepts templates in the command. So you could read all or part of the file into a sensor that way after sticking the name in an input text.
Out of curiosity, what are you trying to do though? Where do these files come from and why does the source of data for the sensor keep changing?
The text input_text.last_added_file is just that text. HA does not replace all strings that happen to look like an entity ID with their state in random things, you have to actually use a template.
I’m not aware of any way to tail a file on disk and get that data into HA that way. The command line and file integrations are both polling. You can speed up that polling by using homeassistant.update_entity but that’s about it.
Again what are you actually trying to do? Where are these files coming from and what is updating them? There might be a better way to do this but I don’t have all the information.
coming from my bluelab connect data being save to home assistant
i used to have node red running a crazy auto dosing program until the recent update crippled it… i didnt see it in time to use a backup so here i am no node red to scrap data from one csv file to the next and im trying to work around the issue
so idea was use same method on home assistant itself
bluelabs wont allow saving to direct file name for whatever reason, so that changes but in same folder.
i need that data to display into home assistant then i can use those values to control doser in automations
Hm. So if the only way HA can see that data is files you’re going to have a difficult time I think. Like I said there’s really no way to live tail a file into HA and I don’t see anything in HACS either. Which leaves you with a few options:
Write your own custom integration that tails a file and updates the state of a sensor whenever it changes. I’m not aware of any particular reason such an integration couldn’t exist I just don’t know any that do that. It’s also possible there is a custom integration for that and its just not in HACS or Core currently, might find something searching around the forum or Google.
Modify the external service to fire events at HA instead of writing out files via the REST API
If #2 is impossible, create an intermediary service which tails the file and fires events at HA via the REST API. This service could be an add-on if you want it to run alongside HA or just host it somewhere else.
Use the Node RED or AppDaemon addons to tail the file and send events to HA when it updates. This is really just a variation of #3, NR or AD are acting as the intermediary services in this case. If you find it easier to use them then writing something yourself. pyscript might also work here even though its technically an integration rather then a separate service, not sure.
Basically if you can’t make/find #1 then you want the data to come to HA in the form of events rather then files. If you have events then you can make automations from those events or turn that data into a live-updating sensor using a trigger template sensor. But there’s not really a good way to handle live updating files OOTB.
Sorry tell what to save to a file? And it really depends on how often you’re writing data. The file integration is type local polling so its not live tailing anything. The sensor also simply shows you the last line in the file as it says.
So if you’re adding lines to the file occaisionally on a predictable schedule then sure that’s fine. If you’re going to be streaming data into it very quickly all or most of the time then that won’t work well.
thats how it was being used before. it updates once a minute and would allow me to get data needed
it just happened to use node red to complete the process then i could use a file sensor and pull data from last line which is all i need final line…which would watch folder for changes then save that to file of my choosing.
- platform: file
name: Water Temp
file_path: /config/BlueLog/2023-01-20 112500.csv
value_template: '{{ value.split(",")[5] }}'
unit_of_measurement: F
- platform: file
name: Water ph
file_path: /config/BlueLog/2023-01-20 112500.csv
value_template: '{{ value.split(",")[4] }}'
unit_of_measurement: Ph
- platform: file
name: Water Ppm
file_path: /config/BlueLog/2023-01-20 112500.csv
value_template: '{{ value.split(",")[3] }}'
unit_of_measurement: Ppm
- platform: file
name: Water Time
file_path: /config/BlueLog/2023-01-20 112500.csv
value_template: '{{ value.split(",")[0] }}'
If these are your file paths then its not going to be possible to use a file sensor since its got a date on it. A file sensor needs a hard-coded file path and that file path is clearly changing regularly. The command line sensor is a better bet.
I guess I’m confused why HA is looking at files at all if Node RED is involved. Node RED can simply fire events at HA. One event per data update with all the data in it. Then an automation listening for that event and processing it however you wish. Seems a lot easier then having NR write to a file and HA trying to read that back in via 4 different file sensors but that’s just me.
If you want it in sensors for example that’s easy too. Have NR fire an event at HA with data like this per data update:
mainly because i havent a clue what im doing its a cross fingers and hope it works method.
didnt know you could make sensors that way, i take the long way around because of my limitaions/knowledge of computers . half the stuff ive done is a frankenstein project of bits of de from various sources made to work together…
node red made things easy to do and i read on fourm someone using sensor file to do something similar so i used their code to get there
when i lost ability to use node red it really hurt the system. just trying to maintain at this point and i felt if i could get monitoring systems back online it would help with progress.
pumps are up and running, just gotta figure out how to make these things function… without node red …