Command_line binary_sensor remains 'unknown'

Hello there,

Here is my command_line sensor

command_line:
  - binary_sensor:
      name: "Connection à l'onduleur"
      command: >
        if ifconfig | grep -q 192.168.200; then echo on; else echo off; fi
      unique_id: 6a5bd84e-5a06-499e-a232-d6d35e134ad6
      device_class: connectivity

I don’t know what is ‘wrong’ with this but it remains unknown forever

image

Tried so far : restart, fast reload, command line entities, nothing seems to work.

The command line is working in a shell window:

I also tried to force shell, replacing the command by
command: "/bin/sh -c 'if ifconfig | grep -q 192.168.200; then echo on; else echo off; fi'"
but it is the exact same result :cry:

Can someone help me?

Try this?

command_line:
  - binary_sensor:
      name: "Connection à l'onduleur"
      command: "if ifconfig | grep -q 192.168.200; then echo on; else echo off; fi"
      unique_id: 6a5bd84e-5a06-499e-a232-d6d35e134ad6
      device_class: connectivity
      payload_on: 'on'
      payload_off: 'off'

Dam** this is it.
The documentation is confusing!

payload_on string (optional, default: ON)
The payload that represents enabled state.

payload_off string (optional, default: OFF)
The payload that represents disabled state.

As it is on/off, I thought it was not necessary. But it seems that ON and ‘on’ is not the same thing.

Thx

1 Like