IATkachenko / HA-SleepAsAndroid

Sleep As Android integration for Home Assistant
Apache License 2.0
163 stars 24 forks source link

Device, nor entity created in HA #9

Closed rplevka closed 3 years ago

rplevka commented 3 years ago

General information

Integration

Integration version: v1.2.0 HASS version: 2021.3.4 Root topic: SleepAsAndroid

Application settings

configured Sleep as android to use SleepAsAndroid/roman topic image topic:

How it works now?

The events are published by Sleep app to the broker and I can read them using mqtt client, However, the HASS integration doesn't create any device nor entity.

What do you expect?

Device and entity that would collect the events and states from the mqtt topic

Steps to reproduce

I followed all the steps as described in readme

Debug log

I can see logs like:

2[root@nas config]# grep sleep_as_android home-assistant.log | head -12
2021-04-22 13:11:41 WARNING (MainThread) [homeassistant.loader] You are using a custom integration sleep_as_android which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-04-22 13:11:42 INFO (MainThread) [homeassistant.bootstrap] Setting up stage 2: {'persistent_notification', 'input_number', 'map', 'input_datetime', 'mqtt', 'media_source', 'script', 'dhcp', 'met', 'default_config', 'alarm_control_panel', 'logbook', 'input_select', 'influxdb', 'cover', 'input_boolean', 'mobile_app', 'blueprint', 'sun', 'group', 'sleep_as_android', 'ssdp', 'updater', 'zeroconf', 'tts', 'counter', 'scene', 'my', 'tag', 'switch', 'zone', 'input_text', 'sensor', 'tasmota', 'kodi', 'binary_sensor', 'zha', 'history', 'system_health', 'automation', 'hacs', 'timer', 'nodered'}
2021-04-22 13:11:42 DEBUG (MainThread) [homeassistant.setup] Dependency sleep_as_android will wait for dependencies ['mqtt']
2021-04-22 13:11:44 INFO (MainThread) [homeassistant.setup] Setting up sleep_as_android
2021-04-22 13:11:44 INFO (MainThread) [homeassistant.setup] Setup of domain sleep_as_android took 0.0 seconds
2021-04-22 13:11:44 INFO (MainThread) [custom_components.sleep_as_android] Setting up ea7971cef4d1354ff40a907b229a869f 
2021-04-22 13:11:44 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=sleep_as_android>
2021-04-22 13:11:44 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.sleep_as_android
2021-04-22 13:11:44 DEBUG (MainThread) [custom_components.sleep_as_android.sensor] Subscribing to root topic 'SleepAsAndroid'
2021-04-22 13:11:44 DEBUG (MainThread) [custom_components.sleep_as_android.sensor] Subscribing to root topic is done!

Additional information

just wanted to say hi and thank you for the integration

IATkachenko commented 3 years ago

@rplevka, hello.

I cant se any "Got message ... " in log (must be at DEBUG level), so integration don't get messages from MQTT => could not detect device. Normally device should be created automatically after publishing first event...

I'll check it on fresh installation.

rplevka commented 3 years ago

so I enabled the debug logging level for the integration and restarted HASS just to find the mentioned messages in the log...and suddenly, even the device got created.

Weird. I'm not aware of any changes to the config. Also i tried to restart HASS server several times.

IATkachenko commented 3 years ago

What was exact actions order while your first attempt?

  1. Install the integration
  2. Restart HA
  3. Configure the integration
  4. Configure the application
  5. Send event from the application
  6. Check event via MQTT-client

Right? Maybe restart is required between steps 3 and 4 (or some code changes to avoid it).

However, something went wrong: new device should be created immediately after step 5. I'll check the integration installation on fresh HA installation to debug it.

rplevka commented 3 years ago

I believe those were exactly the steps, yeah - I was following the instructions - 1 thing i made differently - I used different topic structure at first:

phone/roman/sleep

after that i noticed the integration works with the root topic, so i switched to phone/sleep/roman structure. anyway, when trying to edit the integration settings, the topic in the form resets to "SleepAsAndroid" (possibly a bug?). I decided not to fight with it and go with the defaults.

Anyway, I've tried to restart HASS several times without any success. It almost looks like it started to work after I enabled debug logging output, which is probably just a correlation.

IATkachenko commented 3 years ago

Reconfiguration (without removing the integration) is not supported in correct way now, so it may affect too.

OK, now it work and you may use the Integration. And I'll check the installation process: may be I have bug in installation mechanism...

rplevka commented 3 years ago

thanks for your prompt reply!

rplevka commented 3 years ago

so I think the issue is here. The + wildcard only subscribes to the very next subtopic level. My all previous configuration attempts used multiple subtopics levels: phone/roman/sleep I guess in my scenario, it subscribed to phone/roman and thus was not receiving any messages.

I changed my topic structure to make the unique device part the last level: phone/sleep/roman.

I used the previous structure as I also use notify&fitness app + tasker mqtt to publish heart rate data from my wristband: phone/roman/heart nevermind, i will swap them.

Just curious, whether using # instead of + would work?

IATkachenko commented 3 years ago

Integration logic is to create device for every subtopic: if your family have several devices, then use single root topic for the sleep data and subtopic per device to create devices with names of subtopics. So, it need +.

Your variant is reasonable too: phone device may provide a lot of data and it is OK to group data by device. In this case subscription should be: prefix/device_name(+ again)/suffix.

May be we should have option in configuration dialogue to choose more comfortable way.

rplevka commented 3 years ago

maybe a feature request, but I could imagine something like a jinja template to delimit the subtopic part to be taken for a device name, e.g.

foo/bar/{{ device }}/baz