What's wrong with this file sensor?

File Sensor seems too simple to get wrong, but mine won’t work right. Here’s the details - can someone help me figure out what’s wrong?

In sensors.yaml:

- platform: file
  file_path: /backup/syncstamp.txt
  name: last_online

ui-lovelace.yaml:

 - entity: sensor.last_online
   name: Last Online Sync
   icon: mdi:google-drive

The path /backup is whitelisted in my config file. I also tried it with the file in my /home/homeassistant folder. I kept tweaking the permissions until I got to 777, but I still get a yellow

entity not available: sensor.last_online

syncstamp.txt is a one-line text file written out by a shell script when my online backup finishes. It contains something like

Dec 09 2018 11:00:20 AM

And that’s it. That’s what I see when I look at it with “more” or run tail -n 1 syncstamp.txt like it says in the docs.

There’s nothing in the error log.

Anyone have a guess?

What type of HA are you running? HA may not have access to the local host path /backup if you run HA in a docker container.

As a solution, you could mount /backupinto your container by adding a volume mount option to yourdocker run` command:

-v /backup:/backup

I hope this is useful for you.

It’s Hassbian. I’ve got a command_line sensor just above this one that works fine. It ls''s my backup directory and trims the most-recent entry for the timestamp. - trying to show most recent local backup along with most recent online sync.

The cron entry is running - the timestamp is updating, if that means anything.

I’m logged in as the “homeassistant” user and can read the file. The file is owned by homeassistant:homeassistant.

Like I said - it seems to simple to fail, yet it’s failing.

I even went as far as trying to make a second command_line sensor that just called more syncstamp.txt, but the log filled with “duplicate key” errors. That’s a separate problem, though…

Did you restart Home Assistant after creating the file sensor?
Does it show up in your state overview? (https://[your-ha-url]/dev-state or the < > icon at the bottom left)

Only a zillion times.

The only thing I hadn’t done is reboot my Raspberry Pi, which I just did.

And now it works.

Life is weird. Life with HA is a little bit weirder.

2 Likes

Glad to help. Had many of those quirks before, hence my question :slight_smile:

Yeah I am trying to figure this one out as well. I am trying to read the output from my Acurite weather station. It creates the sensor but for instance it only ever reads 0°F. I dont see anything in the logs indicating that it even tries to read the file.

Multiple HA restart and Host restarts. I am running using the Official HASS.io Hyper-V image. As I have had issues with Raspberry and it nuking SDCards.

I have this problem too, can’t read a file sensor.

YAML

homeassistant:
  whitelist_external_dirs:
    - /config/smartctl

sensor:
  - platform: file
    name: testone
    file_path: "/config/smartctl/test.json"
    value_template: '{{ value_json }}'
  - platform: file
    name: testtwo
    file_path: "/config/smartctl/test.json"
    value_template: "{{ value_json.test }}"

/config/smartctl/test.json

{
  "test": "hello world"
}

Proof that home assistant can read the test.json file

mike@server:~$ docker exec -it homeassistant bash
bash-5.0# cat /config/smartctl/test.json
{
  "test": "hello world"
}bash-5.0#

Unfortunately both the sensors are empty