Binary sensor & command_line integration: sensor remains unknown :(

Hi everybody,
I’m trying to check for the existence of a file in the HA config folder and have defined a binary sensor to this end. Unfortunately the sensor remains unknown and I can’t figure out where I’m going wrong… :confused:

My HA installation runs on a RPi in a docker environment.

The binary sensor definition looks like this:

command_line:
  - binary_sensor:
      name: "File Existence"
      command: test -e /config/test.txt && echo 'off' || echo 'on'
      scan_interval: 5  # Set the interval in seconds to check the file existence

Troubleshooting so far:

  • tested the command inside the docker container bash. Command returns on or off, depending on whether file exists or not. File is in correct folder.
  • updated state manually from developer tools / states. After a few seconds the sensor updates back to “unknown”, so probably updates are being executed
  • checked home assistant log. No errors relating to the sensor to be seen.

Any help or ideas are greatly appreciated!

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

It’s ON and OFF, uppercase, by default

- binary_sensor:
    name: "File Existence"
    command: test -e /config/test.json && echo 'OFF' || echo 'ON'
    scan_interval: 5  # Set the interval in seconds to check the file existence

BTW, your realize your binary sensor will be false if the file exists, right?

@koying, thank you so much! ON and OFF vs on and off indeed fixed that whole thing :grinning:

And yes, you’re right, the logic is inverted, should rename the sensor to “file inexistence” :wink: