Announcement: AppDaemon 3.0.2!

Hi All, it’s been a while since the last release, due to some real life issues - but the good news is we have a new release now!

There are lots of goodies here, including support for HASS’ new authentication methods via Long Lived Tokens, and the official release of the AppDaemon MQTT plugin.

I also added support for version 5 of Font Awesome icons - that will be a breaking change for many dashboards and skins but I also included a compatibility mode to give you time to make the necessary changes.

Here is the full list of changes:

3.0.2 10/31/2018

Features

  • added set_textvalue() api call.
  • added app_init_delay to delay App Initialization
  • Added ability to register apps to receive log entries
  • Added instructions for running a dev build
  • Added support for Long Lived Access Tokens
  • Updated MDI Icons to 3.0.39
  • Updated Font Awesome Icons to 5.4.2
  • Added MQTT Plugin - contributed by Tod Schmidt <https://github.com/tschmidty69>__
  • Many MQTT Plugin enhancements - contributed by Odianosen Ejale <https://github.com/Odianosen25>__
  • Added entitypicture widget - contributed by hwmland <https://github.com/hwmland>__
  • Docker start script will now check recursively for additional requirements and install them - contributed by Kevin Eifinger <https://github.com/eifinger>__
  • Added ability to set units explicitly in widgets - contributed by Rene Tode <https://github.com/ReneTode>__
  • Added --upgrade to pip3 call for recursive requirements.txt scanning - contributed by Robert Schindler <https://github.com/efficiosoft>__
  • Added the ability to pass stringified JSON parameters to service calls - contributed by Clyra <https://github.com/clyra>__

Fixes

  • Fixed incorrect service call in set_value()
  • Enforce domain name in rss feed target to avoid issues with other functions
  • Previously deleted modules will now be correctly reloaded to reflect changes
  • Fixed a bug in get_scheduler_entries()
  • Prevent periodic refresh of HASS state from overwriting App created entities - contributed by Odianosen Ejale <https://github.com/Odianosen25>__
  • Fix to honor cert_path - contributed by Myles Eftos <https://github.com/madpilot>__
  • Run AD in docker as PID 1 - contributed by Rolf Schäuble <https://github.com/rschaeuble>__
  • Fix encoding error in log messages - contributed by Markus Meissner <https://github.com/daringer>__
  • Fix a bug in get_plugin_meta() - contributed by Odianosen Ejale <https://github.com/Odianosen25>__
  • Various Doc corrections and additions - contributed by Odianosen Ejale <https://github.com/Odianosen25>__
  • Various fixes in the Docker docs - contributed by Simon van der Veldt <https://github.com/simonvanderveldt>__
  • Namespace fixes - contributed by Odianosen Ejale <https://github.com/Odianosen25>__
  • More namespace fixes - contributed by Odianosen Ejale <https://github.com/Odianosen25>__
  • Fixes of the namespaces fixes :wink: - contributed by Brian Redbeard <https://github.com/brianredbeard>__
  • Fix typo in sample systemd config - contributed by Evgeni Kunev <https://github.com/kunev>__
  • Fix to cert path config - contributed by nevalain <https://github.com/nevalain>__

Breaking Changes

  • RSS target names must now consist of a domain as well as the target name, e.g. rss.cnn_news
  • SSE Support has been removed
  • Use of ha_key for authentication is deprecated and will be removed at some point. For now it will still work
  • Many Font Awesome Icon names have changed - any custom icons you have on dashboards will need to be changed to suit - see docs for more detail.

While working through the upgrade it is strongly advised that you clear your browser cache and force recompiles of all of your dashboards to flush out references to old icons. This can be done by manually removing the compiled subdirectory in conf_dir, specifying recompile=1 in the arguments to the dashboard, or setting the hadashboard option dash_compile_on_start to 1.

16 Likes

before there are questions about it:

hassio hassos users need to wait untilt there is an update from the addon.
removing the compiled dir is for hassio hassos users no option.

and if i (and the docs) am correct its dash_force_compile: 1 (and not recomplie)

Thanks Rene - the URL argument to force a compile should be recompile=1 as stated, I should have made that clearer. dash_force_compil is an alternative to dash_compile_on_start and is part of the HADasboard config secion of appdaemon.yaml

The new hassio addon should be available soon, @frenck is aware of the new release.

oke, to clarify this:

specifying recompile=1 in the arguments to the dashboard

means

add recompile=1 to your dashboardurl like:
http://dashboardurl/your_dash?recompile=1

and indeed i was thinking you were talking about changing things in appdaemon.yaml :wink:

good to hear that the hassio users can use it soon also.

1 Like

I have been playing around with the MQTT plugin, and I can’t seem to use the MQTT api methods

2018-10-31 21:37:32.677179 WARNING AppDaemon: Traceback (most recent call last):
  File "/home/homeassistant/appdaemon_venv/lib/python3.6/site-packages/appdaemon
/appdaemon.py", line 1581, in init_object
    init()
  File "/home/homeassistant/.homeassistant/apps/mqtt_light/mqtt_light.py", line
12, in initialize
    self.mqtt_subscribe("abc")
AttributeError: 'MqttLights' object has no attribute 'mqtt_subscribe'

I can subscribe using the config, and receive messages through listen_event, so it is basically working, but it seems like I am missing some inheritance somewhere.

did you base your class on the hass plugin or on the MQTT plugin?

:tada: Released AppDaemon Hass.io add-on v1.6.0

I’ve updated the Hass.io add-on to include this latest 3.0.2 release. There is a difference with the original announcement above by @aimc:

  • The add-on migrates the use of ha_key to token automatically in case you use http://hassio/homeassistant as the ha_url (which you should on Hassio)

  • The clearing/flushing of the compiled directory is handled by the add-on automatically, so no special configuration or actions from your end are needed.

Full Changelog

Changed

  • Updates AppDaemon to 3.0.2 (#29) (@acockburn)
  • Upgrades gcc to 6.4.0-r9
  • Switches use of token instead of ha_key
  • Adds logic to automatically flush compiled cache on version upgrade
  • Improves token update message on startup
2 Likes

I hadn’t, which was the problem. My excuse was there is no mention of having to do that in the docs.

It is obvious, once I think of it, since the hass apps are derived from something in the hass plugin, but some mention in the docs would probably help.

there are some parts of the docs rewritten, but when you use AD for a long time its hard to find those changes.
off course people like you dont look at the parts from the docs explaining how to write an app.

i have it already on my list to rearrange some parts from the docs, so if you have any idea how the docs could be better then please let us know.

@gpbenton - I added some stuff to the docs to hopefully clarify that a little.

https://appdaemon.readthedocs.io/en/dev/APPGUIDE.html#anatomy-of-an-app

1 Like

@aimc thanks for AppDaemon! i’ve recently started using it and it’s great! is there a place to where I can buy you a virtual beer/coffe?

2 Likes

Thanks, that would certainly explain it.

But in general, can I suggest that the information for each plugin is collected together in one place, rather than scattered throughout the pages - I mean the base class, events listened to, the api reference and whatever else is needed, plus of course, some examples.

A good idea yes - probably we should summarize that stuff in each plugin API reference at the top.

Thanks for the thought, but your thanks are payment enough - glad you like it!

3 Likes

Then let me add to that with more thanks! I had some issues getting started, but with your help I was able to accomplish all of my automation needs with Python and AD! It has been running great for months now!

2 Likes

Hi, I am trying to figure out how to listen to mqtt topics using the new MQTT-feature and how to pass the payload and topic to my app. I cannot find any examples in the documentation that help me any further. Is something like this possible?

pseudo-code:

class myapp(hass.Hass):
    def initialize(self):
        # first subscribe to a topic x/y/z
        self.mqtt_subscribe(self, x/y/z, **kwargs)
        # next, listen to it
        handle = listen_event(callback, event = None, **kwargs)

    def callback(payload)
       # do something with the received payload
       self.log(payload)

Can somebody help me? :slight_smile:

first make sure that you got your commands like subscribe and listen_event are correct
https://appdaemon.readthedocs.io/en/latest/MQTT_API_REFERENCE.html
and then make sure that your callback is right
https://appdaemon.readthedocs.io/en/latest/APPGUIDE.html#about-event-callbacks

There is an example at the end of the callback api section

self.listen_event(self.mqtt_message_recieved_event, "MQTT_MESSAGE", topic = 'homeassistant/bedroom/light')

although, in practice you have to also use the namespace parameter because the the appdaemon plugin will almost certainly be using the default.

And the callback is the same has any event callback

def my_callback(self, event_name, data, kwargs):

and the payload and topic are part of the data dictionary

data["payload"]
data["topic"]
1 Like

Hello,

First of all, it will not be possible to do self.mqtt_subscribe(self, x/y/z, **kwargs) within the HASS namespace. So it is better to do this in the plugin configuration. Also as highlighted by @gpbenton, you need to make use of the namespace parameter.

So your configuration should be something like this

MQTT:
     type: mqtt
     client_host: 192.168.0.xx
     client_user: !secret mqtt_username
     client_password: !secret mqtt_password
     namespace: mqtt
     client_topics:
         - x/y/z

You can leave most of the parameters empty if you are using localhost and have no username and password on your broker.

in your code, you do the following

class myapp(hass.Hass):
    def initialize(self):
        self.handle = self.listen_event(self.mqtt_callback, 'MQTT_MESSAGE', namespace = 'mqtt')

    def mqtt_callback(self, event_name, data, kwargs):
       # do something with the received payload
       self.log(data['payload'])

Hope this helps. More examples will be released soon, so it becomes easier to build using it

Regards

Awesome! It works!
My config:

log:
  logfile: STDOUT
  errorfile: STDERR
appdaemon:
  api_port: 5001
  threads: 10
  plugins:
    HASS:
      type: hass
      ha_url: "http://192.168.0.199:8123"
      token: !secret appdaemon_token
    MQTT:
     type: mqtt
     client_host: 192.168.0.9
     namespace: mqtt
     client_topics:
         - x/y/z

and apps.yaml

mqtttest:
  module: mqtttest
  class: mqtttest

and finally mqtttest.py

import appdaemon.plugins.hass.hassapi as hass

class mqtttest(hass.Hass):

  def initialize(self):
       self.handle = self.listen_event(self.mqtt_callback, 'MQTT_MESSAGE', namespace = 'mqtt')

  def mqtt_callback(self, event_name, data, kwargs):
       # do something with the received payload
       self.log(data['payload'])

Doing mosquitto_pub -t "x/y/z" -m "lala"
gives 2018-11-14 19:02:25.004754 INFO mqtttest: lala in the logs

I hope this helps any other lost souls.

2 Likes

Would you mind posting one working example please
How do you subscribe or publish to a topic?

self.mqtt_publish("monitor/gg-mon", "100", qos = 0, retain = True, namepace = "mqtt")

ends up with this error

AttributeError: 'mqtttest' object has no attribute 'mqtt_publish'

Edit:
I made some progress here, after changing the app to

import appdaemon.plugins.mqtt.mqttapi as mqtt
#import appdaemon.plugins.hass.hassapi as hass
class mqtttest(mqtt.Mqtt):

  def initialize(self):
       self.handle = self.listen_event(self.mqtt_callback, 'MQTT_MESSAGE', namespace = 'mqtt')

  def mqtt_callback(self, event_name, data, kwargs):
       # do something with the received payload
       self.log(data['payload'])
       self.log("Sending back to mqtt")
       self.mqtt_publish("monitor/gg-mon", "100", qos = 0, retain = True, namepace = "mqtt")

I am getting

2019-02-03 08:33:51.403842 CRITICAL AppDaemon: Wrong Namespace 'default' selected for MQTT Service. Please use proper namespace before trying again
2019-02-03 08:33:51.405779 WARNING mqtttest: Could not execute Service Call, as wrong Namespace 'default' used