Way to get installed version of AppDaemon programmatically?

Is there any way I can programmatically get the version of my installed AppDaemon (for use in a HASS sensor)?

You can make a command_line sensor wich greps the appdaemon log.
For example, i’m using appdaemon docker container.

docker logs appdaemon | grep 'AppDaemon Version' | head -n1 | awk '{print $6}'

Returns: 3.0.0b3
Not sure where the appdaemon log is in a normal environment, or if this works in hass.io.

I think you want tail rather than head to make sure you pick up the last time AD was started?

Thank you, @VDRainer and @gpbenton – I really like that idea. Unfortunately, I run HASS and AppDaemon in separate Docker containers; I don’t want expose the entire Docker socket to the HASS container.

That said, your direction gives me an idea: I could feasibly run a remote SSH command between the containers. I’ll give that a shot and report back.

You could search through the log file from appdaemon. You can get the logfile in v3 from

self.get_main_log().handlers[0].baseFilename

This is broken in v3b3, but should be fixed in b4.

In version 2 you can get it from

            self.errorfile = self.config["AppDaemon"]['errorfile']

Ahh, that’s interesting – so, the idea would be to create a sensor on the fly from within AppDaemon (as described here: Sensor creation)?

1 Like

That’s it.

But now I think about it, for docker the log is sent to stdout, so the idea might not work.

You’re right – that didn’t work. Bummer. :face_with_raised_eyebrow:

Here’s what I ended up doing – will leave it here for anyone who’s running individual Docker containers and wants to do something similar.

First, I created a shared directory for both HASS and AppDaemon that points to the same location on the host: /shared

Second, I modified my AppDaemon Dockerfile so that, during build-time, the version number gets placed into a text file within /shared:

FROM hypriot/rpi-alpine-scratch:v3.4
MAINTAINER Aaron Bach <[email protected]>

ENV APPDAEMON_VERSION=3.0.0b3
ENV ARCH=arm
ENV CROSS_COMPILE=/usr/bin/

RUN apk update \
    && apk add --update \
      bash \
      build-base \
      ca-certificates \
      coreutils \
      libffi-dev \
      linux-headers \
      python3 \
      python3-dev \
      supervisor \
      tzdata \
    && pip3 install --upgrade \
      pip \
      appdaemon==${APPDAEMON_VERSION} \
      packaging==16.8 \
      python-Levenshtein==0.12.0 \
    && rm -rf /var/cache/apk/*

# Copy configuration files:
COPY conf/supervisor/supervisor.conf /etc/supervisor.conf

# Copy the installed version number of AppDaemon to the shared directory:
RUN echo "${APPDAEMON_VERSION}" > /shared/.AD_VERSION

# Run Supervisor:
WORKDIR /root

(notice the RUN command near the end and how it references an environment variable from the top)

With this in place, I can use a command line sensor to read from that file.

Quirky, I know, but it seems to work.

without accessing the logs:

write an app that reads the dir
/usr/local/lib/python3.5/dist-packages (or simular, but the dir with the subdir appdaemon)
select the subdirs that have appdaemon in the name
1 is just appdaemon, the other is something like:
appdaemon-3.0.0b2.dist-info
from that you can use set_state to create a sensor.

no need to create anything, no need to modify anything, the app will keep on running and setting the sensor value after an update from appdaemon, without the need to modify the docker again.

import os

def init(...):
  self.run_daily(self.set_sensor,...)

def set_sensor(...):
  subdirs = os.listdir("/usr/local/lib/python3.5/dist-packages")
    for subdirname in subdirs:
      if "appdaemon" in subdirname.lower():
        if "info" in subdirname.lower():
          parts = subdirname.split("-")
          version =parts[1][:-5]
          self.set_state("sensor.appdaemon_version",state=version)

the correct dir to the sitepackages probably also can be found with:
import site
path = site.getsitepackages()
which will even keep the app running after changing python version.

but i read that that not always works, but sys.path should also give the dist-packages dir

Interesting concept! I went ahead with my method because I needed to do the same thing with a few other apps (Node-RED, ha-dockermon, etc.), but your solution is very nice!

just out of curiosity why not

appdaemon --version | awk ‘{ print $2 }’

you might have to specify the path for appdaemon but that’s not to hard.

The problem I’m running into is getting it from a separate machine where I have appdaemon installed. ssh doesn’t seem to be working right and of course no error in the HA error log about it.

I guess we could write a quick function that would create a sensor with the value in it.

3 Likes