Help with command line switch (permissions?)

Hi Guys,

I’m stuck using the command line switch. command_on and command_off is working fine. Command_state doesn’t work. (works fine in the terminal btw)

I think it might have something to do with permissions of the homeassistant user? I’ve searched the forum and tried this:

sudo su -s /bin/bash homeassistant

when I run: echo “pow 0” | cec-client -s -d 1 | grep “power status: on” > nul && (echo “true”) || (echo “false”) I get:

bash: nul: Permission denied
false

and now I’m stuck… and looking for someone to get me back on track :slight_smile:

switch:
   platform: command_line
   switches:
     tv_woonkamer:
       command_on: 'echo "on 0" | cec-client -s -d 1'
       command_off: 'echo "standby 0" | cec-client -s -d 1'
       command_state: 'echo "pow 0" | cec-client -s -d 1 | grep "power status: on" > nul && (echo "true") || (echo "false")'
       value_template: '{{ value }}'
       friendly_name: TV Woonkamer

That’s trying to redirect the output to the file nul, I assume you meant /dev/null, but you’d be better to use:

grep -q "power status: on"
1 Like

groep -q was the solution. Its working now. Thanks Tinkerer!