Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device, nor entity created in HA #9

Closed
1 task done
rplevka opened this issue Apr 22, 2021 · 9 comments · Fixed by #14
Closed
1 task done

Device, nor entity created in HA #9

rplevka opened this issue Apr 22, 2021 · 9 comments · Fixed by #14
Projects

Comments

@rplevka
Copy link
Contributor

rplevka commented Apr 22, 2021

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:

  • I can see MQTT messages from application at MQTT-server

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
Copy link
Owner

IATkachenko commented Apr 22, 2021

@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 rplevka changed the title Device, nor entity not created in HA Device, nor entity created in HA Apr 22, 2021
@rplevka
Copy link
Contributor Author

rplevka commented Apr 22, 2021

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
Copy link
Owner

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
Copy link
Contributor Author

rplevka commented Apr 22, 2021

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
Copy link
Owner

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
Copy link
Contributor Author

rplevka commented Apr 22, 2021

thanks for your prompt reply!

@rplevka
Copy link
Contributor Author

rplevka commented Apr 22, 2021

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
Copy link
Owner

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
Copy link
Contributor Author

rplevka commented Apr 23, 2021

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

@IATkachenko IATkachenko added this to the 2.0 milestone May 10, 2021
@IATkachenko IATkachenko added this to In progress in 1.3.0 May 10, 2021
@IATkachenko IATkachenko removed this from the 1.3 milestone May 10, 2021
@IATkachenko IATkachenko moved this from In progress to Test in 1.3.0 Aug 17, 2021
IATkachenko added a commit that referenced this issue Aug 17, 2021
Now we may use %%%device%%% macro for integration to get device name from different parts of MQTT topic.

Old root_topic configuration option will be replaced by old_root_topic_value/%%%device%%% template.

Have no breaking changes, but have a lot of changes in code, so it should be v2.0.0 release.
Fixes #9, #8

***
* refactor: move mqtt topic to own property, replace root_topic

It is a property by meaning, that should be generated from config.

* refactor(sensor): move adding of previous configured entities to own function

It is not related to subscription to root topic

* feat: added device_macro

This constant contain macro for getting position from topic

* wip: fix cycle imports and sensor name

* wip: process new message if we have sensor

* refactor: make parameters of async_setup private

to avoid "variable is not used" PyCharm warning

* refactor(SleepAsAndroidInstance): turn list of sensors to Dict

and add method for getting sensor by it's name

* feat(SleepAsAndroidSensor): add model to device info.

Model is MQTT to point out that it is MQTT integration.

* wip: added todo

* doc: add typehint for second parameter of subscribe_root_topic

* feat: add critical message if we can't subscribe to topic

* refactor: add more debug messages

* style: added blank line after function definition

* test(docker): add event sender

* fix(sensor): use integration prefix in default sensor name

* fix(instance): use correct message in get_sensor KeyError exception

* feat(updating): update to new version

* feat: allow empty old options

* fix: skip error while creating new device

* style(instance): remove extra blank lines

* refactor(instance): remove unused import

* doc: update documentation

* doc: add topic_template description
1.3.0 automation moved this from Test to Done Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
1.3.0
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants