Sensor command line fails

Can someone help me to figure out why sensor command line fails to run and other works.
I’m using my script (see here: https://hastebin.com/ededepihis.bash) to extract the status of each sensor for temps, setpoint, status etc.
no issue with the script I think
here is the log file where is greps all the data: https://hastebin.com/meqanekexa.css

temperature setpoint

2017-10-27 14:12:07 INFO (SyncWorker_14) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -s 5
2017-10-27 14:12:07 INFO (SyncWorker_8) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -s 7

temperature

2017-10-27 14:12:07 INFO (SyncWorker_13) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -t 6
2017-10-27 14:12:07 INFO (SyncWorker_4) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -t 0

motion sensor - failed

2017-10-27 14:13:08 INFO (SyncWorker_10) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -d 0
2017-10-27 14:13:08 ERROR (SyncWorker_10) [homeassistant.components.sensor.command_line] Command failed: /opt/scripts/status/state.sh -d 0

this is my config

binary_sensor:
   - platform: command_line
     command: /opt/scripts/status/state.sh -d 4
     name: motion bathroom
     device_class: motion
     payload_on: 1
     payload_off: 0

sensor:
  - platform: command_line
    name: tmp_set_living
    command:  /opt/scripts/status/state.sh -s 0
    unit_of_measurement: "°C"

I realy have no clue where too look.

What version of HomeAssistant are you using?

latest version 0.56.2

Sorry, I wasn’t clear in my question, which version of HA are you using (hassbian, HASS.io, linux v-env install)?

running on raspberry pi3 (dietpi debian8) with with Virtual Env, file has the corrected permission
I get the temp/setpoint and relay states correct using the same script, it’s just the motion sensors not working correctly.

Although when motion is detected ON, the state is reported but not the OFF state and constant error message of commands failed all the time.

Running the command manually provides no error: ./state.sh -x -m 0:

DEBUG (6484 @2017-10-27 15:57:17): Debugging enabled
DEBUG (6484 @2017-10-27 15:57:17): Checking status of DigitalIn ID 0
DEBUG (6484 @2017-10-27 15:57:17): DigitalIn ID 0 has a raw status of OFF
DEBUG (6484 @2017-10-27 15:57:17): DigitalIn ID 0 has a parsed status of 0
0

succes

2017-10-27 15:54:46 INFO (SyncWorker_0) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -t 0
2017-10-27 15:54:46 INFO (SyncWorker_8) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -s 10

failed

2017-10-27 15:54:46 INFO (SyncWorker_15) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -m 4
2017-10-27 15:54:46 ERROR (SyncWorker_15) [homeassistant.components.sensor.command_line] Command failed: /opt/scripts/status/state.sh -m 4
2017-10-27 15:54:46 INFO (SyncWorker_19) [homeassistant.components.sensor.command_line] Running command: /opt/scripts/status/state.sh -m 0
2017-10-27 15:54:46 ERROR (SyncWorker_19) [homeassistant.components.sensor.command_line] Command failed: /opt/scripts/status/state.sh -m 0

To sum up, while there is no activity, I receive constant error messages. Once state is changed to ‘ON’ then the sensor state gets updated, but ones there is no movement is stays “ON” and my log is full of “command failed” messages as shown above. Running the command manually show that the sensor state if “OFF”

image

Can you try your script without the last if statement?

#if [ ${STATUS} -eq 0 ]; then 
#  exit 1
#else
#  exit 0
#fi

Why does it exit with 1 (Catchall for general errors) when it returns 0?

1 Like

A guess, I’ve used it in mine, if you put quotes around the command - does it help?

Hass doesn’t seem to like dashes exposed anywhere, except the customize.yaml

So they’d look like this for instance:

sensor:
  - platform: command_line
    name: tmp_set_living
    command:  "/opt/scripts/status/state.sh -s 0"
    unit_of_measurement: "°C"

It’s not my script, some helped at discord HA chat to create this script.

Commenting it out was indeed the fix but then the states of the switches gets mixed up (on/off) constantly. Not sure why.

Ended up creating 2 scripts where motion sensor states using the commented out version as you proposed.

So far it’s working and no error no more.

@Bit-River no issues with quotes

Thank you all for the quick response.