How do I check the availability of a webserver?

I’ve been using this for a while:

binary_sensor:
  - platform: command_line
    name: example.com
    device_class: connectivity
    command: response=$(curl -LIk -m 3 https://example.com -o /dev/null -w "%{http_code}\n" -s); test "$response" -eq 200 && echo "ON" || echo "OFF"
    scan_interval: 300
    value_template: '{{ value }}'
5 Likes