Blackbox probing Home Assistant

Having an developer/ops/support background I am interested in good monitoring to be able to investigate after unexpected things happen. Especially my Z-Wave and Zigbee network is where I am not so sure about the observed latency and whether or not it is doing what it should 24/7. I started writing an AppDaemon app to set a switch to on and then observe a binary_sensor until it is also switching to on, since they are electrically connected I can measure round trip latency. To achieve that I used ESPhome with a minimal config and the switch and binary_sensor are a pin each with a jumper wire connecting them.

# ESPhome configuration
  - platform: template
    name: "ping"
    lambda: 'return false;'
      - output.turn_on: out_pin
      - delay: 1000ms
      - output.turn_off: out_pin
  - platform: gpio
    pin: D6
    name: "pong"
  - platform: gpio
    pin: D5
    id: out_pin

Since the goal is to measure the latency of my Zigbee and Z-Wave networks and not just the latency introduced by ESPhome to toggle a pin I added a ZHA door sensor to trigger an update that exercises the Zigbee network. To keep the circuits isolated I used a PC817 optocoupler and at a later stage I will replace the battery of the door sensor to either run on 3.3V or introduce an other low drop voltage regulator to not have to constantly replace batteries as this "door" is opening and closing every minute.

alt text

The AppDaemon part is relatively straight forward and consists of two applications. The first one provides a way to add a point to a Google Cloud Monitoring metric. Replacing that with a different monitoring platform should be relatively simple. The second application handles a single prober and defines a ping and a pong entity. Every minute it changes the ping entity to on and waits until the pong entity is reporting an on state as well. The time in between those two events is the round trip latency and then reported to monitoring.

# app.yaml used in AppDaemon
  module: prober
  class: StackdriverMonitoring
  project: myproject-name
  credentials_json: "/config/gcp_serviceaccount.json"

  module: prober
  class: Prober
  pong: binary_sensor.pong
  metric_name: prober_latency

  module: prober
  class: Prober
  ping: switch.ping_zha
  pong: binary_sensor.pong_zha
  metric_name: zha_latency