I have created a binary sensor to test if a web server is responding. I am using the command_line / binary_sensor hierarchy as follows:
- binary_sensor:
command: ‘curl -v --stderr - https://192.168.nn.nn:nn01 | grep -e xxCERTNAMExx > /dev/null && (echo server_is_up) || (echo server_is_down)’
name: “serverxxxisrunning”
device_class: running
payload_on: “server_is_up”
payload_off: “server_is_down”
scan_interval: 60
command_timeout: 15
Note: I am only getting back mostly the SSL/TLS handshake and this is all I want. I am grepping on the Server Cert Name to know the server is running without having to log in.
If I run this from the HA terminal directly, it works and the SSL handshake completes, and the command returns “server_is_up”.
As a sensor, the status never goes to running, implying it does not ever see a “server_is_up” returned.
When I was using http and grepping on clear text web page returned, it worked. Now that I am using https and grepping on the cert in the SSL exchange, it does not work.
So:
- https / grep the SSL handshake works from the HA terminal - full successful SSL handshake also dumped if I dont pipe it to the grep
- https / grep the SSL handshake sensor config does NOT work
- http / grep clear web text works with this sensor config
Is curl https somehow not supported in the sensor ?
Is curl https somehow done differently when run by HA ?
Is there a way to step by step debug the running of the binary sensor ?
Any other suggestions ?
Brendan