Help - Temperature monitor using MQTT and AppDaemon

Hi,

Following the documentation I found that I can register an MQTT device as:

configuration.yaml

sensor bedroom:
  platform: mqtt
  state_topic: "home/bedroom/temperature"
  name: "MQTT Sensor 1"

Right now I trying to declare a simple app to monitor (log) the temperature (example from the documentation)

bedroom_temperature.py

import appdaemon.plugins.hass.hassapi as hass

class BedroomTemperature(hass.Hass):

    def initialize(self):
        self.log('BedroomTemperature.initialize')
        self.listen_state(self.state_change, "sensor.bedroom") 

    def state_change(self, entity, attribute, old, new, kwargs):
        self.log('BedroomTemperature.state_change: '+ new)

apps.yaml

bedroom:
  module: bedroom_temperature
  class: BedroomTemperature

but I get the following error during its initialization: … “Entity sensor.bedroom not found in AppDaemon”

2019-07-19 15:39:58.465360 INFO AppDaemon: Initializing app bedroom using class BedroomTemperature from module bedroom_temperature
2019-07-19 15:39:58.466493 INFO bedroom: BedroomTemperature.initialize
2019-07-19 15:39:58.466588 WARNING AppDaemon: bedroom: Entity sensor.bedroom not found in AppDaemon

If I change the listen_state from sensor.bedroom to sensor bedroom I don get the error, but the callback state_change it’s never called when I inject manually a new value to MQTT topic.

Any suggestion of what I’m doing wrong? or did I misunderstand something about MQTT+HA?

Notes:

  • First day using HA
  • I’m using Mosquito with its default configuration

This is my complete configuration.yaml file

default_config:

# 1 New content added
mqtt:
  broker: 127.0.0.1  

tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

# 2 New content added
sensor bedroom:
  platform: mqtt
  state_topic: "home/bedroom/temperature"
  name: "MQTT Sensor 1"

Did you check the entity name in HA? Go to the web page and under developer tools one of the buttons is “states” - click that. It will show you a list of all the entity names that exist.

You might also want to check the HA logs - I may not be up to date on all the allowed formats but that might not be a valid input format. My mqtt sensors look like this:

sensor:
  - platform: mqtt
    name: "temp_media_room" 
    state_topic: "env/temp/Media Room"
    unit_of_measurement: "°F"
    value_template: '{{ value_json.temperature }}'

Hi @TD22057

Thanks for the hint! the entity name wasn’t there.

Both ways (yours and mine) are correct

I restarted HA and everything works perfectly.

Do I have to restart HA very time I add a new entity manually (e.g., mqtt)?

@TD22057 thanks for your time!

Yes - pretty much any time you change the config file, you have to restart HA. I believe if you’re just editing the lovelace gui config it’s not required but for entities it is.

1 Like