AppDaemon - listening for events on one entity but getting events for every entity

I’m new to AppDaemon, learning by reading the documentation and various tutorials. I’m trying to create an AppDaemon app that listens for events on a single entity, but I seem to be getting events for every entity. I’m sure it’ll be a beginners mistake, but I can’t spot what it is. Can anyone help? App and logs below.

I’m using AppDaemon v4.2.2 and HA 2022.11.4

The AppDaemon manual uses a syntax like this

hass.listen_state(hass_callback, "sensor.outsidesensor_temperature")

Reading the AppDaemon API documentation I have gotten this working, but I’m curious why I have to use this format rather than the above format that most others seem to use.

self.get_entity("sensor.outsidesensor_temperature").listen_state(self.print_entity)

I also noticed this warning in the logs WARNING AppDaemon: Unknown Plugin Configuration in get_plugin_api() - any suggestions there? I’ve included my appdaemon.yaml as well below.

Application

import hassapi as hass

class OutsideTemperatureSensorChange(hass.Hass):

    def initialize(self):
        self.adbase = self.get_ad_api()
        self.hass = self.get_plugin_api("hass")
        self.adbase.log("Initialising class OutsideTemperatureSensorChange")

        self.listen_state(self.print_entity,entity='sensor.outsidesensor_temperature')

    def print_entity(self, entity, attribute, old, new, kwargs):
        try:
            self.log(f'Entity state change for {entity}')
        except Exception as e:
            print("An exception occurred")
            print(e)

Logs

2023-01-11 19:24:18.994253 INFO AppDaemon: Initializing app outsidesensor using class OutsideTemperatureSensorChange from module test-outside-temp-sensor-change
2023-01-11 19:24:18.998402 WARNING AppDaemon: Unknown Plugin Configuration in get_plugin_api()
2023-01-11 19:24:19.000666 INFO outsidesensor: Initialising class OutsideTemperatureSensorChange 

2023-01-11 19:24:33.844714 INFO outsidesensor: Entity state change for sensor.openweathermap_pressure
2023-01-11 19:24:33.860593 INFO outsidesensor: Entity state change for sensor.openweathermap_rain
2023-01-11 19:24:33.868016 INFO outsidesensor: Entity state change for sensor.openweathermap_uv_index
2023-01-11 19:24:33.875297 INFO outsidesensor: Entity state change for sensor.openweathermap_forecast_precipitation
2023-01-11 19:24:48.456860 INFO outsidesensor: Entity state change for sensor.lounge_temperature
2023-01-11 19:24:57.642086 INFO outsidesensor: Entity state change for sensor.fridgesensor_temperature
2023-01-11 19:24:57.676640 INFO outsidesensor: Entity state change for sensor.fridgesensor_battery
2023-01-11 19:24:57.701121 INFO outsidesensor: Entity state change for sensor.fridgesensor_humidity
2023-01-11 19:24:57.708786 INFO outsidesensor: Entity state change for sensor.loungesensor_humidity
2023-01-11 19:24:57.716009 INFO outsidesensor: Entity state change for sensor.loungesensor_temperature
2023-01-11 19:24:57.723185 INFO outsidesensor: Entity state change for sensor.loungesensor_battery
2023-01-11 19:24:57.730369 INFO outsidesensor: Entity state change for sensor.outsidesensor2_temperature
2023-01-11 19:24:57.737644 INFO outsidesensor: Entity state change for sensor.outsidesensor2_signal_strength
2023-01-11 19:25:57.798467 INFO outsidesensor: Entity state change for sensor.kitchensensor_battery
2023-01-11 19:26:48.959634 INFO outsidesensor: Entity state change for sensor.lounge_temperature
2023-01-11 19:26:58.062386 INFO outsidesensor: Entity state change for sensor.officesensor_battery_percentage
2023-01-11 19:26:58.101783 INFO outsidesensor: Entity state change for sensor.officesensor_signal_strength
2023-01-11 19:26:58.134126 INFO outsidesensor: Entity state change for sensor.officesensor_humidity
2023-01-11 19:26:58.156423 INFO outsidesensor: Entity state change for sensor.loungesensor_humidity
2023-01-11 19:26:58.175689 INFO outsidesensor: Entity state change for sensor.loungesensor_temperature
2023-01-11 19:26:58.188429 INFO outsidesensor: Entity state change for sensor.loungesensor_signal_strength
2023-01-11 19:26:58.198540 INFO outsidesensor: Entity state change for sensor.outsidesensor2_temperature
2023-01-11 19:26:58.208541 INFO outsidesensor: Entity state change for sensor.outsidesensor2_signal_strength

Config

logs:
  main_log:
    filename: /home/appdaemon/.appdaemon/log/appdaemon.log
  access_log:
    filename: /home/appdaemon/.appdaemon/log/access.log
  error_log:
    filename: /home/appdaemon/.appdaemon/log/error.log
  diag_log:
    filename: /home/appdaemon/.appdaemon/log/diag.log
    log_generations: 5
    log_size: 1024
    format: "{asctime} {levelname:<8} {appname:<10}: {message}"
appdaemon:
  time_zone: Pacific/Auckland
  latitude: -40.00000
  longitude: 111.1111
  elevation: 155
  plugins:
    HASS:
      type: hass
      ha_url: http://192.168.1.16:8123
      token: (removed)
http:
    url: http://192.168.1.16:5050
admin:

Look at the docs. listen_state doesn’t use entity in its call.

https://appdaemon.readthedocs.io/en/latest/AD_API_REFERENCE.html#appdaemon.entity.Entity.listen_state

I’ve figured it out - I was using “entity=” as a parameter to the listen_state call.

This is what I was doing

self.listen_state(self.print_entity,entity='sensor.outsidesensor_temperature')

This is what I should’ve been doing

self.listen_state(self.print_entity,'sensor.outsidesensor_temperature')

@Troon I found the issue at pretty much the same time you replied by reading the docs - thanks :slight_smile:

1 Like