Its possible when your target-port is a tcp-port. And almost all ports a running over tcp (http, ssh, ftp, smtp, …).
What you want is not a ping (it runs over ICMP and this “portless”).
But you can send a tcp “SYN” and wait for an “SYN ACK” - it should be returned immediately.
btw this is how nmap checking for open ports.
I dont know much about home assistant (Iam HA-newbie), but you can play around with nmap- and/or nc-command (netcat). If not, I can write a small bash-script in the next days.
That would the job alright but since I’m running Hassio on a pi 4 I don’t think you can just run any linux command.
I don’t think telnet is part of it for example and neither does the /dev/tcp command above.
Thanks for that just tried it but looks like this::
I wonder if it needs extra single quotes?
I can confirm via putty I get true which means it does work but HA sensor reports it as false
And how often does this check? Just once when HA server is starting? I would need this be run every hour
nmap 192.168.0.100 -p 21081
Starting Nmap 7.80 ( https://nmap.org ) at 2019-12-02 08:17 GMT Standard Time
Nmap scan report for 192.168.0.100
Host is up (0.079s latency).
PORT STATE SERVICE
21081/tcp open unknown
MAC Address: AB:CD:12:34:56:78 (Espressif)
Nmap done: 1 IP address (1 host up) scanned in 0.69 seconds
It seems that the internal HA parser for the command line sensor uses redirection also, and you can’t nest it. So the solution is to instance another bash.
- platform: command_line
name: Plex Service
command: /bin/bash -c "(echo > /dev/tcp/192.168.10.16/32400) > /dev/null 2>&1 && echo Up || echo Down"
value_template: '{{ value }}'
I just tried your code with a Smart TV to tell if it is powered on or off. It works fine when it’s turned on (the sensor state returns “Up”), but it returns “Unknown” when the TV is powered off. I tried it within the terminal in HA and it returns “Down” correctly. What could that be ?
Never mind, just figured this out. The command was taking longer than the default timeout value, therefore it was not able to return a good state. Just increased the command timeout and it now works fine:
Got this working! Thanks for the novel (to me): command: /bin/bash -c "(echo > /dev/tcp/HOST/PORT) > /dev/null 2>&1 && echo ON || echo OFF"
In case anyone else runs into the same problem as I did, HOST either needs to be an IP address OR FQDN (i.e. HOST.DOMAIN). In my case it was confusing because at the HA command line HOST only worked, but not when used as above as a sensor. But I eventually figured out that HOST.local does work.
I get the folllowing error[quote=“chrischambers, post:28, topic:151859, full:true”]
this is something I have been tring to work out - on and off for some time, but when I put the following code into my configuration file.
Ping operates by means of Internet Control Message Protocol (ICMP) packets. Pinging involves sending an ICMP echo request to the target host and waiting for an ICMP echo reply . The program reports errors, packet loss, and a statistical summary of the results, typically including the minimum, maximum, the mean round-trip times, and standard deviation of the mean.