UPnP Availability integration

Hi everyone!

I just updated my (2-year-old, but not very advertised) UPnP sensor integration, which I have been using personally for automations involving devices that were not directly supported by Home Assistant.
To put it short, this integration allows you to track the on/off state of any UPnP-conforming device. And as it is based on the notifications send out by the devices, the changes are instantaneous: no need to wait for the next update poll cycle to trigger turning on the lights when you turn off your telly!

I have not tried it myself, but this could potentially be useful also for supported devices which are not pushing their updates: instead of waiting the next update cycle to trigger the automations, an automation based on the state change could trigger a force update.

The installation is very simple, just install it as any other custom component and add the integration via the UI (it’s called “UPnP Availability”) and it will create entities for the supported devices and start tracking them immediately. As soon as a new supported devices are turned on, new entities are created automatically with no need for configuration.

The integration and some short documentation is available at https://github.com/rytilahti/homeassistant-upnp-availability.

At the moment I’m wondering whether I should try to PR this into Home Assistant Core or simply submit it to HACS (or leave as it is). So let me know what you think, any feedback is appreciated! :slight_smile:

A couple of screenshots:

3 Likes

HA core is always good, so long as you comply with all the quite tricky coding standards they insist on (I don’t mean that pejoratively to the devs, they have to have standards, but they can be quite tricky standards to adhere to!)

So my vote would be to put it in HACS now and also to submit it to core. That way it will get some wider exposure via HACS, and eventually be in core.

+1 for official repo HA Core.

The coding standards are fine, but it is always a bit more effort (in this case creating a separate pypi package to maintain), so my train of thought was to gather some input whether that’s worth the effort.

I will think about pushing it to the core, but for the time being I followed your proposal and added a hacs.json so that it can be added as a custom repository to hacs :slight_smile:

Nearly gave up after finding the new Xbox integration is useless for using my lad’s Xbox state in automations, but your integration is perfect, thank you so much.

1 Like

Glad to hear you found it useful! :+1:

1 Like

The integration is not working for me, after installing it via HACS it does not show up with my integrations. Does this need an update?

I just installed it and it works fine. Did you restart HA then add the integration via the ui?

Github was down about that time, and HACS wasn’t able to download the code. I had the same problem.

1 Like

Thank you, it indeed works now.

Has this integration broken the code dosent load

2021-06-20 12:30:22 WARNING (MainThread) [homeassistant.loader] You are using a custom integration nodered 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-06-20 12:30:22 WARNING (MainThread) [homeassistant.loader] You are using a custom integration upnp_availability 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 Ass
istant
2021-06-20 12:30:38 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 129, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 117, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 69, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 122, in async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 561, in async_create_flow
    integration.get_platform("config_flow")
  File "/usr/src/homeassistant/homeassistant/loader.py", line 499, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 504, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/upnp_availability/config_flow.py", line 16, in <module>
    config_entry_flow.register_discovery_flow(
TypeError: register_discovery_flow() missing 1 required positional argument: 'connection_class'
2021-06-20 12:42:38 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
  return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 129, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 117, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 69, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 122, in async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 561, in async_create_flow
    integration.get_platform("config_flow")
  File "/usr/src/homeassistant/homeassistant/loader.py", line 499, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 504, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/upnp_availability/config_flow.py", line 16, in <module>
    config_entry_flow.register_discovery_flow(
TypeError: register_discovery_flow() missing 1 required positional argument: 'connection_class'

any help would be good

System Health

version: core-2021.3.4
installation_type: Home Assistant Container
dev: false
hassio: false
docker: true
virtualenv: false
python_version: 3.8.7
os_name: Linux
os_version: 5.4.0-74-generic
arch: x86_64
timezone: Australia/Melbourne

GitHub API: ok
Github API Calls Remaining: 4982
Installed Version: 1.12.4
Stage: running
Available Repositories: 842
Installed Repositories: 2

logged_in: true
subscription_expiration: 30 June 2021, 10:00
relayer_connected: true
remote_enabled: false
remote_connected: false
alexa_enabled: false
google_enabled: true
can_reach_cert_server: ok
can_reach_cloud_auth: ok
can_reach_cloud: ok

dashboards: 5
resources: 0
views: 8
mode: storage

When did you install it?

Related to this: Move iot_class from code to manifest (remove deprecated call) by deadly667 · Pull Request #5 · rytilahti/homeassistant-upnp-availability · GitHub - could you update your homeassistant instance to see if that helps?

Im pulling the latest home assistant container from homeassistant/home-assistant:stable ill let you know how i go.

ok so now this is weird I have the intergration added via HACS and the Folder is in the custom componants as shown below.

but when i go into add the intergration it cant be found

EDIT: I cant add any extra replies, to the comment below yes the manifest.json is there

When did you install the custom_component?

I’ll ask it another way. Is there a version key in custom_components/upnp_availability/manifest.json

Hi, Nick yes I have the Manifest.json there I removed the integration and reinstalled it via adding a custom repository to HACS and adding the repository from there.

but as stated above when I go into integrations I don’t see the integration in the list but I can see in the logs that it has loaded the custom component.

2021-06-22 09:02:06 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration upnp_availability 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-06-22 09:02:06 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration nodered 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-06-22 09:02:06 WARNING (SyncWorker_2) [homeassistant.loader] We found a custom integration tapo_control 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-06-22 09:02:06 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hacs 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,

You did click on the + button?

I just installed it via HACS, and (after restarting HA, which you have obviously done) it was in the add integrations list when you click the + button.

HI Nick,

well after leaving it sit for half a day it suddenly appeared in the list when clicking the + maybe this was a browser cache issue so thanks heaps I have it added now I just need to figure out how to get the UPNP broadcasts to span across subnets.

thanks again

A notification start appearing, with every restart:

Invalid config

The following integrations and platforms could not be set up:

* upnp_availability.binary_sensor

Please check your config and [logs](http://192.168.2.100:8123/config/logs).

Checking the logs:
Logger: homeassistant.setup
Source: setup.py:316
First occurred: 09:39:58 (1 occurrences)
Last logged: 09:39:58

Unable to prepare setup for platform upnp_availability.binary_sensor: Platform not found (cannot import name ‘UpnpAdvertisementListener’ from ‘async_upnp_client.advertisement’ (/usr/local/lib/python3.9/site-packages/async_upnp_client/advertisement.py)).