Custom Application Monitoring via TCP Port

Good Evening All,

Was wondering if this is possible. There is an application that I would like to monitor and be able to run automations if it fails. The only way to monitor it would be to open the TCP port its running on and if it connects then the Sensor should read online and if it fails to connect then offline.

Once HASS connects to the port it just needs to disconnect again. Would need to be able to specify the timeout as well so I can tweak it to perfection as sometimes when the applications is under load it can take a few seconds to work. When I previously monitored this using some custom windows software I built I found a sweet spot of 20 seconds.

Is anyone able to assist with this one please? I have no idea how to acheive this. If it matters I am running Raspbian on Pi4 with HASSIO installed. I am a complete novice that does struggle!

Thanks in advance,
Max