Automation to Monitor Heartbeat from Monitor App

I am using Andrew Freyer’s Monitor app (which is fantastic, thank you Andrew) to track the presence of iPhones at home. I have the app running on a Pi Zero W which also hosts my PiHole. HA is running in a Docker container on my Mac media server.

I would like to enable the heartbeat functionality in the Monitor app and use this to confirm that the app is alive and functioning properly (and also as a proxy as to whether the Pi Zero is up). The monitor app publishes the payload {“identity” : “monitor”} under MQTT topic /Home/heartbeat/monitor.

I have added the above mqtt topic to my Configuration.yaml file as follows:

  - platform: mqtt
    name: Monitor heartbeat
    state_topic: "Home/heartbeat/monitor"

I have also cobbled together the following automation from various posts, both here and elsewhere on the web:

- alias: Monitor app is  alive and well
    - platform: mqtt
      topic: Home/heartbeat/monitor
    condition: template
    value_template: {{ trigger.payload_json.identity == "monitor" }}    
    - service: timer.start
      entity_id: timer.timer_monitor_sensor

- alias: Monitor app down
    - platform: event
      event_type: timer.finished
        entity_id: timer.timer_monitor_sensor
    - service: notify.ios_iphone_5
        title: "Monitor app is dead"
  message: "Help - Monitor app is down! Check the PiHole"

The basic idea is that HA starts a 5 minute timer every time it receives a message containing “monitor” under the Home/heartbeat/monitor topic. If the timer expires it indicates that no message has been received for 5 minutes and it is concluded that the Monitor app (and perhaps the Pi) is down which then triggers a notification to my iPhone.

Unfortunately I cannot figure out how to correctly check for “monitor” in the JSON formatted Matt message. The code that I have tried is based on this post from Reddit

However it results in the following errors:

2018-12-04 10:32:32 ERROR (SyncWorker_0) [homeassistant.util.yaml] invalid key: “OrderedDict([(‘trigger.payload_json.identity == “monitor”’, None)])”
in “/config/automations.yaml”, line 250, column 0
2018-12-04 10:32:32 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘trigger.payload_json.identity == “monitor”’, None)])”
in “/config/automations.yaml”, line 250, column 0

Can anyone advise what I am doing wrong in my automation.

1 Like

Did you ever get this working?