How to get only one value from a text file, non-json?

I have a "realtime.txt’ text file which is regularly generated and stored at my website root directory (www.mywebsite.com/realtime.txt). The text file contains only one line (58 values separated by blank) and is replaced every 5 minute. Each value in the text file is separated by one blank space. If I want to regularly, say every 5 minute, extract the value which appears at the 53rd position in the file (value 1358 in the sample file). How could it be done in my configuration.yaml?
Thank you

1 Like

"{{ value.split(' ')[52] }}"

I believe the challenge here is the 254 character limit.
You can try and make HA accept it as an attribute like here:

But since it’s not json then it could be hard.
If this is on your website, can’t you make it store it as json? Or just this value alone in a different file?

1 Like

Thanks. Could you give an example how to define the location of the file in configuration.yaml before using your sample command here?
Thanks

You use a file sensor. But listen to Hellis81’s advice above.

Thank you for your warning. I may have to write a script (if I can :slight_smile: ) to extract just that value. It is possible the length could exceed 254.

what kind of website is it? Can it run php?
If so then you can have a php page that extracts the value you need and return it.

- platform: command_line
  name: My 53rd number
  command: "curl \"http://www.mywebsite.com/realtime.txt\" | cut -d\  -f 53"
  scan_interval: 300

(note the two spaces in the cut command)

1 Like

Thanks. It’s strange. I can get the value from this command line if I run it directly on terminal window.
curl https://mydomain.com/realtime.txt | cut -d\ -f 53
But when putting it in configuration.yaml and reload command line entities, it still returns “unknown” value
command: "curl https://mydomain.com/realtime.txt | cut -d\ -f 53"

Should be two spaces in -d\ -f. Are there any errors in the log, and how are you running HA?

I have to replace " with ', then it works now. Thank you very much.

  - platform: command_line
    name: Cloud Base
    command: 'curl https://mydomain.com/realtime.txt |  cut  -d\  -f 53'
    unit_of_measurement: "m"

I run HA supervised.

is there a way to parse a .yaml file and add the values to a sensor? or make a sensor with the files more appropriately?