Hey everyone, i’ve got a command line sensor setup that essentially calls a script, which sends a telnet command to an HDMI switcher and converts the returned value to a string on which input is in use. This was working fine for the past few years, but Ive noticed it has stopped working recently (could be anytime in the last 6 months).
When I update the sensor manually using the homeassistant.update_entity
service, it works and I get the value back that is expected.
Then when the command line scan interval runs (defaulted at 60 seconds), it wipes out the state leaving it blank.
Here’s my command line code:
command_line:
- sensor:
name: Matrix Living Room Input
unique_id: somenumbers
command: !secret matrix_get_input_1
That calls this from the secrets file (IP blocked out):
matrix_get_input_1: '/config/scripts/hdmi_matrix/get_input.sh x.x.x.x 23 1'
And here’s the contents of that script - get_input.sh:
#! /bin/bash
host="$1"
port="$2"
output="$3"
result=`{ echo "get out$output vs"; sleep 1; } | telnet $host $port 2>/dev/null | grep OUT | awk '{print $3}'`
case "$result" in
IN1)
echo "Shield"
;;
IN2)
echo "PS5"
;;
IN3)
echo "Switch"
;;
IN4)
echo "PC"
;;
esac
As mentioned, when i call the script manually from the command line it works every time. When I use the update service in HA, it works too every time. When the sensor runs on its default scan interval, the resulting state is wiped away. Any suggestions?