Forget Python Scripts - AppDaemon - Alexa Notify of New Versions of Home Assistant

I’ve been using Python scripts to do some of my advanced automations, but was really getting frustrated by not being allowed to import libraries.

Then I found a mention of AppDaemon here on the forum. Since then, life is good.

This AppDaemon app checks to see if a new version of Home Assistant has been released, and then has Alexa notify of the good news.

For this to work, you will need to install the Notify Me skill. You will also need to register for an Access Code which will be used to authenticate Home Assistant.

Next, you will need to configure two custom sensors in your configuration.yaml file.

sensor:
  - platform: version
    name: Installed HA Version
    source: local
  - platform: version
    name: Available HA Version
    source: pypi

Next is to get AppDaemon installed. Go read this. Spoiler: The instructions for installing AppDaemon are at the very bottom.

There is some tweaking necessary, as the documentation is somewhat out-of-date. Below is my appdaemon.yaml. (If you copy and paste this, note that my ha_url uses HTTPS, not HTTP. Don’t let that one letter trip you up.)

secrets: /home/homeassistant/.homeassistant/secrets.yaml
appdaemon:
  logfile: STDOUT
  errorfile: STDERR
  log_generations: 3
  threads: 10
  latitude: [REDACTED]
  longitude: [REDACTED]
  elevation: [REDACTED]
  time_zone: America/Chicago
  plugins:
    HASS:
      type: hass
      ha_url: https://127.0.0.1:8123
      token:  !secret appdaemon_token
      cert_verify: false

Here is my apps.yaml.

version_monitor:
  module: version_monitor
  class: VersionMonitor

And here is version_monitor.py:

import appdaemon.plugins.hass.hassapi as hass
import datetime
import json
import requests


class VersionMonitor(hass.Hass):

    def initialize(self):
        self.ver_installed = self.get_state('sensor.installed_ha_version')
        self.ver_available = self.get_state('sensor.available_ha_version')
        self.update_time = datetime.time(18, 0, 0)
        self.alexa_notify_secret = '[REDACTED]'
        self.has_been_announced = False
        self.ver_monitor = self.run_daily(self.report_new_version, self.update_time)

    def report_new_version(self, kwargs):
        if self.ver_installed == self.ver_available:
            self.has_been_announced = False
            return

        if self.has_been_announced:
            return

        alert_msg = 'A new version of Home Assistant is available. {} has been released.'.format(self.ver_available)
        body = json.dumps({'notification': alert_msg, 'accessCode': self.alexa_notify_secret})

        requests.post(url="https://api.notifymyecho.com/v1/NotifyMe", data=body)
        self.has_been_announced = True

If someone figures out how to access your secrets file from within the app, please let me know!

I hope you enjoy this little app. I especially hope that this introduces someone to AppDaemon. I know I wish I found it much sooner than I did.