Update of binary_sensor.tv_status is taking over 10 seconds

Hi, I created a sensor to monitor the power on status of my TV following the command_line sensor guide.
This is the sensor I created:

binary_sensor:
  - platform: command_line
    command: 'ping -c 1 192.168.0.2 | grep "1 packets received" | wc -l'
    name: 'tv_status'
    device_class: connectivity
    payload_on: 1
    payload_off: 0

and it works well for me both when the TV is on and when it is off, but when it is off the log is filled with these errors:

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:694
First occurred: 20:30:20 (141 occurrences)
Last logged: 22:27:50

Update of binary_sensor.tv_status is taking over 10 seconds

I also tried to add the command_timeout item by increasing the value (from 15 seconds which is default up to 30 seconds) and also the scan_interval item by changing the default value (which is equal to 60 seconds) but it didn’t help. null, as if HA ignored the set timeout value and always defaulted to 10 seconds.
From the terminal I typed the command ping -c 1 192.168.0.2 and I counted up to 8 seconds before the answer (with TV off) so it shouldn’t time out … yet …
Has anyone else noticed this problem and if it solved it ???

Would a ping binary sensor work for you?

1 Like

Yes, it works fine without having any warnings in the registry.
However I think that in the command_line there is something to fix if using ping from there then all those warnings are generated.
Thanks so much!

ping -c 1 -W 5 specifies a timeout of 5 seconds. That should get rid of the warnings.

I guess there could be some differences between your terminal and the environment where the command_line binary sensor runs it’s command.

It probably is.
Terminal is HA SSH & Web Terminal add-on while pinging command_line will likely have a different environment.
For the sake of completeness, my system runs on a Raspberry PI4 with Raspbian OS and supervised Home Assistant on Docker.