Yeah, I think this evaluates the exit code of grep. Which is 1 if there in no line containing ‘On’ in the file.
You can check that by calling echo $? after runnig the grep command.
Does it show the proper state?
I think it’s 0 for on and 1 for off
Aha. So what you are saying is that it will evaluate the exit code and not the actual output of the command?
I put the “-C” after the grep command so that it will count the number of 'On’s in the file which always will be 1 if the switch is On and 0 if the switch is off.
I will try to use the exit code insred. Thanx for the tip.
I figured it out. The problem was grep returns an error code when the count of occurrences is zero. I just added the below to the sensor command, so if forces true as a result even when the count is zero.
I use this for checking if my older Sony TV is off or on. The TV doesn’t have an API for actually checking if it is on, or off, so I just grep the status of ExtInput. If it’s 1, the TV is on. If it’s 0, or does not respond (i.e. off), then it’s 0. Adding || true has stopped the annoying log on HASS