I am attempting to set up a file sensor to display a value that is retrieved by date. So far, I have managed to set up and read from the file to get a value for the sensor, but now I’m getting tripped up when I try to make it dynamic for the current date.
Here are some sample contents of the file this sensor reads from (I will set these values up manually, one value for each date):
{"date1": "Library"}
{"date2": "Gym"}
{"date3": "Music"}
Here is my sensor entry in configuration.yaml:
- platform: file
name: Test
file_path: specials_data.txt
value_template: '{{ value_json.date2 }}'
unit_of_measurement: 'Ugh'
And here is what I get in the UI:
So far, so good! The problem is that “date1”, “date2”, etc. are just placeholders for actual dates. I need to end up with something more like this:
{"2017-12-11": "Library"}
{"2017-12-12": "Gym"}
{"2017-12-13": "Music"}
I want to fill up the file with real dates and values, and configure the sensor to dynamically determine the current date and look up the corresponding entry in the file. This is where I’ve gotten in over my head. I tried setting up the time_date sensor and then referencing that sensor’s date value in place of my “date2” above, but I couldn’t figure out any syntax to make it work. Any pointers for how to I need to set up the content in my file and the configuration of my sensor?
Thanks!