Healthchecks.io integration

Healthchecks.io is a very nice service that allows you to monitor the status of some automatic tasks (backups,…). It can also be used to check regularly that a device is still running and online (heartbeat). Healthchecks integrate with multiple services (mail, telegram, whatsapp,…) so it can send messages if some check fails.

On top of that, it can also be polled by API to check the status of the various checks implemented.

I think it would be a very nice integration witrh HA. First as a sensor: HA could poll healthcheck API in order to check the status of the different checks. A second option would be to make it so healthcheck can directly send alerts to home-assistant instead of telegram, so it could trigger actions in HA later on.

Agreed, that would be useful https://github.com/custom-components/healthchecksio should work for now.

1 Like

So far I am using the RESTful sensor and template sensors in order to get everything. This works quite well, but would definitely be better if integrated directly.

where do you do the config of this. I have copied the folder and added the integration but cant find anywhere to setup the config for this.

thanks

I’m currently working on this, and am having trouble getting the auth keys correctly configured. Would you be willing to post a sanitized version of your sensor/template config?

Hi, sorry for the delay. I did not check these forums for quite some time… If it stills interest you, here is the sensor I am using

- platform: rest
  name: healthcheck_backups
  resource: https://healthchecks.io/api/v1/checks/
  value_template: 'OK'
  json_attributes:
    - checks
  headers:
    X-Api-Key: !secret healthchecks_api
    Content-Type: application/json
    User-Agent: Home Assistant REST sensor
    Accept: application/json
  scan_interval: 300
  force_update: true

Then I use a template sensor in order to parse the output and have something nice to display in HA.

- platform: template
  sensors:
    helathchecks_sensor1:
      friendly_name_template: "{{states.sensor.healthcheck_backups.attributes.checks[0].name}}"
      value_template: "{{states.sensor.healthcheck_backups.attributes.checks[0].status}}"
      attribute_templates:
        next_ping: >-
          {% if states.sensor.healthcheck_backups.attributes.checks[0].next_ping == none %}
            None
          {% else %}
            {{((as_timestamp(states.sensor.healthcheck_backups.attributes.checks[0].next_ping)-as_timestamp(now())) | float/(24*60*60)) | round(1)}}
          {% endif %}
      icon_template: >-
        {% if states.sensor.healthcheck_backups.attributes.checks[0].status == "up" %}
          mdi:check-circle
        {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "down" %}
          mdi:close-circle
        {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "paused" %}
          mdi:pause-circle
        {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "started" %}
          mdi:play-circle
        {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "grace" %}
          mdi:clock
        {% else %}
          mdi:help-circle
        {% endif %}

It is probably not that complicated to port such a simple logic to a full blown healthchecks integration that would generate the sensors properly from the API result. I just do not have time to do it now or anytime soon.

5 Likes

@ludeeus thanks for this, just found it! :grinning:

1 Like

Just in case anyone comes across this and wants an updated template sensor, here is my code (many thanks to @lambtho)

template:
  - sensor:
      - name: "HealthCheck.io Status"
        unique_id: 04f8f434-805e-4548-9c12-1ee97d98aa0c
        state: "{{states.sensor.healthcheck_backups.attributes.checks[0].status}}"
        attributes:
          next_ping: >-
            {% if states.sensor.healthcheck_backups.attributes.checks[0].next_ping == none %}
              None
            {% else %}
              {{((as_timestamp(states.sensor.healthcheck_backups.attributes.checks[0].next_ping)-as_timestamp(now())) | float/(24*60*60)) | round(1)}}
            {% endif %}
        icon: >-
          {% if states.sensor.healthcheck_backups.attributes.checks[0].status == "up" %}
            mdi:check-circle
          {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "down" %}
            mdi:close-circle
          {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "paused" %}
            mdi:pause-circle
          {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "started" %}
            mdi:play-circle
          {% elif states.sensor.healthcheck_backups.attributes.checks[0].status == "grace" %}
            mdi:clock
          {% else %}
            mdi:help-circle
          {% endif %}
1 Like

Hello,

how do you ping a healthcheck via homasssistant?

Greetings,
Hendrik

See the first part here in my previous comment.
The rest sensor pings the URL automatically by simply checking it.

You then use a template sensor to render everything properly in Home Assistant

Has anyone had troubles recently with the custom component (GitHub - custom-components/healthchecksio: Update and display the status of your healthchecks.io checks.)?

For some reason, it started to fail repeatedly to ping from HA and at some point, the entity for Home Assistant monitor (and only that one) was just not provided by the integration anymore.

.

I had to make a manual automation with rest to do the pings, otherwise, healthchecks.io was detecting false downtimes.

1 Like