Receiving UDP traffic

Hi, I am an absolute HA beginner trying to follow your instructions, but HA throws the following error at me:

2018-10-21 21:43:39 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/helpers/discovery.py", line 160, in async_load_platform
    hass, component, hass_config)
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/setup.py", line 45, in async_setup_component
    return await setup_tasks[domain]  # type: ignore
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/helpers/discovery.py", line 160, in async_load_platform
    hass, component, hass_config)
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/setup.py", line 45, in async_setup_component
    return await setup_tasks[domain]  # type: ignore
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/config_entries.py", line 439, in async_forward_entry_setup
    self.hass, component, self._hass_config)
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/setup.py", line 45, in async_setup_component
    return await setup_tasks[domain]  # type: ignore
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/setup.py", line 56, in async_setup_component
    return await task  # type: ignore
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/setup.py", line 118, in _async_setup_component
    conf_util.async_process_component_config(hass, config, domain)
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/config.py", line 759, in async_process_component_config
    platform = get_platform(hass, domain, p_name)
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/loader.py", line 60, in get_platform
    return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/site-packages/homeassistant/loader.py", line 92, in get_component
    module = importlib.import_module(path)
  File "/volume1/.@plugins/AppCentral/python3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/volume1/homeassistant/custom_components/sensor/udp.py", line 119, in <module>
    self._state = self._data[:200]
NameError: name 'self' is not defined

What to do now?

Hi there,

Given the error type and given that the original file has an empty line at line 119, it seems as if the script was somehow mangled when you copied/pasted it - and indentation does matter with python.

Can you please make sure you have a proper copy of the file? You could directly save the raw version at:
https://raw.githubusercontent.com/glpatcern/domotica/master/homeass/code/udp.py

Cheers,
Giuseppe

Thank you for your quick reply! I have downloaded the mint file as instructed and will test this as soon as I have the possibility, which is not before next Saturday.

Hans Frederik

Hello,

Thanks for the great UDP component. Unfortunately, I get the error message:

Unable to bind on port 9102: [errno -2] Name does not resolve

Probably the Docker container can not hear outside. Since Iā€™m running ā€˜Home Assistantā€™ on Hassio, Iā€™m not sure how to open the port with ā€˜ā€“net=hostā€™ or ā€˜-pā€™.

Maybe somebody can help me.

many Greetings
Michael

@MichaelR
Have you tried installing Portainer and fiddling with the container settings in there?
!!!(CAUTION)!!!
Make sure you have backed up first!! If it goes wrong donā€™t blame me, but there should be a way to publish ports or create the mappings needed, I think.

Rgds

John

Hi,

I am getting the following error:
ā€œIntegration udp not found when trying to verify its sensor platform.ā€

The udp.py file is in ā€œ\HASSIO\config\custom_components\sensorā€

And I am using the code script:

Sensor:
#Camera kinderkamer geluid
  - platform: udp
    port: 51110
    timeout: 30
    name: Geluid kinderkamer

What am I missing?

Wiebe

Hi.
I have got similar result:

Platform error sensor.udp - Integration 'udp' not found.

Script in file udp.py in ā€œ\config\custom_components\sensorā€ and in configuration.yaml I added:

sensor:
  - platform: udp
    port: 57775
    timeout: 60
    name: OneWire

Any idea whats wrong?

I have got exactly the same error like radekD:
Platform error sensor.udp - Integration 'udp' not found.

ā€¦running on Hass.io (HassOS 3.5) , version 0.103.3

image

Same thing hereā€¦ Maybe itā€™s because this is not the right place for the scripts anymore?

I started using home assistant only recently, but I think the setup for custom components has changed. I got it working as follows:
directory: <CONFIG_DIR>/custom_components/udp
In which you put the following files:

  • sensor.py (file listed above)
  • manifest.json

manifest.json content:

{
  "domain": "udp",
  "name": "UDP Platorm",
  "documentation": "https://github.com/glpatcern/domotica/blob/61aa260abf865eb761aed2c67a2d47066316d52d/homeass/code/udp.py",
  "dependencies": [],
  "codeowners": [],
  "requirements": []
}

Hope this also works for you

2 Likes

That works!

Me not :frowning:
Do you have something different?

I have a folder /custom_components/udp/ with files init,py; manifest.json; sensor.py.
File init.py is empty
File manifest.json contains

{
  "domain": "udp",
  "name": "UDP Platorm",
  "documentation": "https://github.com/glpatcern/domotica/blob/61aa260abf865eb761aed2c67a2d47066316d52d/homeass/code/udp.py",
  "dependencies": [],
  "codeowners": [],
  "requirements": []
}

File sensor.py is from github.

In configuration.yaml I have this part:

sensor:
  - platform: "udp"
    port: 57777
    timeout: 60
    name: 28FF7917721605B1

FYI, Iā€™ve prototyped a lightwaverf TRV integration, so you can change the target temperature, as well as view itā€¦
https://github.com/ColinRobbins/Homeassistant-Lightwave-TRV

Rather than try to read the UDP in HA, which I found unreliable, Iā€™ve created a simple proxy to capture the UDP traffic, and serve it to HA in via the HA update poll loop.

1 Like

Hello Giuseppe
i try to use your function,
how i can catch the value that i receive with this UDP sensor ?

I try to send some packets with Sender software but i reach the timeout . ā€¦ so your function doesnā€™t see any data.

I try insert a tcp sensor and i recive data so there is not problem of ā€œcontanierā€ i have home assistant installed in raspberry directly dedicated NO docker container
Thansk in advance for your support.
Bye
Paolo

Hi Paolo,

I fear HA has evolved so much that the whole idea of synchronously listening for UDP traffic in a HA sensor was not great and is now basically deprecated. In fact I never contributed that sensor for this reason (I still use a variant of this in a custom integration, but I suffer from lack of updates and warnings all the time).

Iā€™ve just seen @ColinRobbinsā€™ work about proxying the traffic and that looks like a great idea, though more complex to deploy. Also you will be able to see if your data is received by the proxy, independently from HA. I could only recommend this as a solution thenā€¦ Surely Iā€™ll try that on my other integration (which is discussed here).

Cheers,
Giuseppe

1 Like

Sorry to reply on such an old post,
I now need some kind or udp listener which reads send data from an udp post.
I thied this,

added init.py and a manyfest and Iā€™m allowed to create sensors.
However, they do not work.
The log shows this

My guess would be that some firewall is added in HAOS and I am not allowed to use random ports anymore.

I was hoping may someone still uses an UDP listener and can help me out here.

Hi, Iā€™m also trying to create an integration that just reads UDP broadcast data on a specific port. Iā€™m running within HASSIO/supervisor and it always just fails with OSError: [Errno 98] Address in use

From what I understand the docker container is started with -net=host option which I thought would allow those UDP packets in, but Iā€™m not sure it is.

I have got a simplified version of the integration working on my local dev pc but I always get the above error when it runs in HA.

lā€™ll be interested if you make any progress, as we may have the same problem. Iā€™m not sure if creating an Addon instead is the only option.

In the end I used the node-red addon and integration.
This one can be configured as Udp listener and do some transformation to set the value of an entity.

I actually donā€™t use this anymore as I now have my devices connect to each other without ha. So I canā€™t send you a sample.
But node-red was the solution for me