Pick new .csv file for file.sensor

Hello,

I’m in need of some help. Been searching for a while now, but have not yet found the perfect solution.
I have the following sensors added in my config.yaml:

#GamePC sensoren
  - platform: file
    name: 'gamepc.CPU Temp'
    file_path: /config/GamePC/corsair_cue_20220102_18_17_33.csv
    value_template: '{{ value.split(",")[1] }}'
    unit_of_measurement: "°C"
  - platform: file
    name: 'gamepc.CPU load'
    file_path: /config/GamePC/corsair_cue_20220102_18_17_33.csv
    value_template: '{{ value.split(",")[2] }}'
    unit_of_measurement: "%"
  - platform: file
    name: 'gamepc.GPU Temp'
    file_path: /config/GamePC/corsair_cue_20220102_18_17_33.csv
    value_template: '{{ value.split(",")[3] }}'
    unit_of_measurement: "°C"
  - platform: file
    name: 'gamepc.Exhaust Temp'
    file_path: /config/GamePC/corsair_cue_20220102_18_17_33.csv
    value_template: '{{ value.split(",")[4] }}'
    unit_of_measurement: "°C"
  - platform: file
    name: 'gamepc.Water Temp'
    file_path: /config/GamePC/corsair_cue_20220102_18_17_33.csv
    value_template: '{{ value.split(",")[5] }}'
    unit_of_measurement: "°C"
  - platform: file
    name: 'gamepc.Intake Temp'
    file_path: /config/GamePC/corsair_cue_20220102_18_17_33.csv
    value_template: '{{ value.split(",")[6] }}'
    unit_of_measurement: "°C"

These come from a .csv file uploaded from my GamePC’s icue software. It has a log function and via Sambashare I upload this file to the Homeassistant folder. This works and gives me some nice visual feedback of my current temps and stuff.

image

Only problem is, when my PC reboots icue creates a new .csv file so the sensors no longer work. I have to manually rename the files in my config to make them work again. Not very user friendly.

I found some other sollutions here, like the IoT one with the use of Aida 64, but I don’t want to run extra software to make this work. Icue gives me lots of data I want to use.

My question:
Is there a automatic way to, for example, delete all the files in the given folder so that iCue makes a new one and then a way to let the sensor use the only available .csv file in that folder to get the data? Any other wat, with for example Node-Red is also possible, I just realy want to use the iCue software on the PC site.

Alright, step closer.

I think using the Folder Watchdog (Folder Watcher - Home Assistant) is a way to get the new file name.

With the use of the plugin (Delete files service) I can delete old files in said folder. Gonna have a look at this tonight.

Ok, went a totaly different route. Now have it all implemented in Node-Red and it works.

just reading this… node red took a … on me recently and trying to figure out a work around… difficult to get the file sensor to accept last file added sensor as an acceptable file path…

Node red still running for you?

you were on the right track!

so using folder watcher you create input_text to add the path like this , in config.yaml

input_text:

  last_added_file:
    name: Last added file
    initial: None

this automation supplies last added file sensor

alias: fwa
description: ""
trigger:
  - platform: event
    event_type: folder_watcher
    event_data:
      event_type: created
    id: created
  - platform: event
    event_type: folder_watcher
    event_data:
      event_type: modified
    id: modified
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: modified
        sequence:
          - service: input_text.set_value
            data:
              value: " {{ trigger.event.data.path }} "
            target:
              entity_id: input_text.last_added_file
mode: single

then connect it using a commandlinesensor

sensor:

platform: command_line
name: cheese
command: “tail -n 1 ‘{{ states(“input_text.last_added_file”) }}’ > /config/GamePc/corsair_cue.csv”

last change each platform file path to match the one being saved to above

#GamePC sensoren
  - platform: file
    name: 'gamepc.CPU Temp'
    file_path: /config/GamePC/corsair_cue.csv
    value_template: '{{ value.split(",")[1] }}'
    unit_of_measurement: "°C"

this will find the file being written to
take the last line
write a new file using that line
then you use that stable file to draw information from