Send message when state changes to ip port

Hello guys, is here a good soul, that will help me with following problem - exact step by step guide what I have to set, if I want to send some message to external IP, port based on sensor status changing?

I have sensor.sonytv with two states - active and standby (it’s good working). I want to inform some remote system when this state is changed by sending message using netcat (telnet on 5000 port) - following commands are also working from RPI putty:
echo -e “sony_tv_active\n\r\n\r” | nc 5000 -w 1
echo -e “sony_tv_standby\n\r\n\r” | nc 5000 -w 1

Unfortunatelly I’m unable to get it work with HA.
Any guide is welcome, thanks!