How do I check the availability of a webserver?

This does exactly what I need it to do. It returns Connected or Disconnected if my self-hosted sites are running, not just if there’s something on the other end. For instance, my crappy 502 bad gateway Nginx fail returned “disconnected”. Perfect, thank you.

1 Like

Hi there (my first HA post).

This works great for me for checking WAN and for LAN services (e.g. NAS, router, hoobs).

However, it doesn’t work for my Home Assistant instance (internal or external) or plex instance. It also fails for NAS services that use browser authentication (e.g. raidarr and sonarr).

Any idea for how to fix this?

Many thanks - needed to create a monitor to alert me when Honeywell Total Comfort Connect goes down, which is pretty frequent…

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

I use uptimerobot.com. it is free and HA has a component to integrate it as one sensor for each server.

2 Likes

To get a 200 respons you ned the exact correct end url, if it redirects it will fail.
Home-Assistant will redirect different if you er logge in or not, as for what I see it redirects to /auth/authorize…

Or you can use another respons code (test curl to see what) List of HTTP status codes - Wikipedia

Website down or up - #15 by Michel is the best I could find for this matter. I’d like to automatically handle notifications per-site instead of doing one automation per entity, but it’s good already.

Highly suggest: louislam/uptime-kuma: A fancy self-hosted monitoring tool (github.com)

Using this custom repo: https://github.com/meichthys/uptime_kuma

Looks like we might see this as an official integration in the future: Add Uptime Kuma Integration by meichthys · Pull Request #67985 · home-assistant/core (github.com)

I just wanted to check whether my OctoPrint camera was switched on or not - this worked a treat in my binary_sensor.yaml file, thank you all - I’d never have figured this out on my own.

# Check if OctoPrint camera is running
  - platform: command_line
    name: 'OctoPrint camera status'
    device_class: connectivity
    command: response=$(curl -LIk -m 5 http://octopi.local/webcam/ -o /dev/null -w "%{http_code}\n" -s); test "$response" -eq 503 && echo "OFF" || echo "ON"
    scan_interval: 60
    value_template: '{{ value }}'

Nice, but overkill when used for local network appliances.

I just created an integration (GitHub - mauro-midolo/homeassistant_webserver_status: Home Assistant Integration to check webserver status)

At the moment, the integration is not publish into HACS, you can import manually.

Using this integration you can have:

  • Connection status
  • http/https response time
  • http/https response code (i.e. 200, 301 or 400)