Core 2024.2.1
Supervisor 2024.01.1
Operating System 11.5
Frontend 20240207.1
I’m trying to create a sensor per TCP - Home Assistant
but nothing appears in the developer-tools/states view. The yaml/check-configuration
is happy, as is an external yaml-lint utility. I use yam/all-yaml-configuration
to load the config. I don’t see anything turning up in logs.
Sorry you didn’t get any help. The TCP sensor isn’t a common subject.
As with most topics, you often need to know where to look.
That’s not quite true: the amount of data that can be returned is large, certainly way over 3072 bytes. However, the eventual state that you store in the entity must be no more than 255 characters. Use the value_template to extract that state from the incoming data.
I had the same problem; full restart instead of config reload does indeed solve the problem! The fact that this is necessary should trigger an investigation by the developer of the config reload function, me thinks…
As mentioned in my reply, a full restart solved the problem, but temporarily… I did receive a valid response via the TCP sensor from my TCP/IP-server (a Draytek Vigor 2927 router), but after I changed a few things in the router/network to gain access to it, each restart of HASS suddenly generated a system error while I did not change anything in the TCP-sensor YAML.
Although I’m not an experienced Python/HASS developer, my extensive experience as a former software developer gave me the distinct feeling that the TCP-platform is buggy and unstable, which is a pity because it has a lot of potential.
My next attempt to access a device by TCP/IP will probably entail programming the integration in Python although I’m not looking forward to that…
I got loads of errors, related to the TCP platform, whereas I did not change anything in the sensor-yaml, although it worked fine ONCE.
Another reason is that the TCP-sensor can only come into existence after a HA restart, not a reload. How can this be?
Meanwhile I’ve been trying to program a simple TCP-call in Python, but that’s even a bigger disaster: I get errors on basic things like: import socket… (not found)
Hope you understand that my frustration levels are through the roof if it isn’t possible to make something simple as a TCP-IP service call…
the tcp-sensor generates all of a sudden these errors:
Error while setting up tcp platform for sensor
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 344, in _async_setup_platform
await asyncio.shield(task)
File “/usr/local/lib/python3.12/concurrent/futures/thread.py”, line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/tcp/sensor.py”, line 27, in setup_platform
add_entities([TcpSensor(hass, config)])
^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/tcp/common.py”, line 92, in init
self.update()
File “/usr/src/homeassistant/homeassistant/components/tcp/common.py”, line 145, in update
value = sock.recv(self._config[CONF_BUFFER_SIZE]).decode()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte
I gave up, and am using a command-line integration call to some custom python which does the TCP call, massages the returned text data and does an mqtt publish, with an mqtt-integration set of sensors.
So many moving parts to get the job done.
Mind, pulling the text data apart within HA sensors would also have been a bit of an effort.
You’ll need to make multiple sensors then, one per “item”.
I’m not familiar with the TCP sensor, but it would be useful if there were something like the RESTFul integration where you make one call and can create lots of sensors from the response.
Perhaps look at an automation / script that pulls the TCP response into a text file, then update all your sensors from that, to save multiple calls and potentially unsynchronised data?