TCP
The TCP integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] allows the integration of some services for which a specific Home Assistant integration does not exist. If the service communicates over a TCP socket with a simple request/reply mechanism then the chances are that this integration will allow integration with it.
There is currently support for the following device types within Home Assistant:
Sensor
To enable the TCP integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more], add the following lines to your configuration.yaml
configuration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] file.
在更改了configuration.yaml
configuration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] 文件后,重启 Home Assistant 以应用更改。 该集成现在显示在集成页面的 设置 > 设备与服务 下。其实体在集成卡片上以及实体标签上列出。
# Example configuration.yaml entry
sensor:
- platform: tcp
host: IP_ADDRESS
port: PORT
payload: PAYLOAD
Configuration Variables
How long in seconds to wait for a response from the service before giving up and disconnecting.
Defines a template to extract the value. By default it’s assumed that the entire response is the value.
The size of the receive buffer in bytes. Set this to a larger value if you expect to receive a response larger than the default.
Examples
In this section you find some real-life examples of how to use this sensor.
EBUSd
The EBUSd
$ echo "r WaterPressure" | nc 10.0.0.127 8888
0.903;ok
You will notice that the output from the service is not just a single value (it contains “;ok” as well). To grab the value we’re interested in, we can use a Jinja2 template. The response received is injected into the template as the value
variable. To use this value within Home Assistant, use the following configuration:
sensor:
# Example configuration.yaml entry
- platform: tcp
name: Central Heating Pressure
host: 10.0.0.127
port: 8888
timeout: 5
payload: "r WaterPressure\n"
value_template: "{{ value.split(';')[0] }}"
unit_of_measurement: Bar
hddtemp
The tool hddtemp
collects the temperature of your hard disks.
$ hddtemp
/dev/sda: SAMSUNG MZMTE256HMHP-000L1: 39°C
With hddtemp -d
you can run the tool in TCP/IP daemon mode on port 7634 which enables you to get the data across the network.
$ telnet localhost 7634
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
|/dev/sda|SAMSUNG MZMTE256HMHP-000L1|38|C|Connection closed by foreign host.
The entry for the configuration.yaml
file for a hddtemp
sensor could look like the example below.
sensor:
# Example configuration.yaml entry
- platform: tcp
name: HDD temperature
host: 127.0.0.1
port: 7634
timeout: 5
payload: "\n"
value_template: "{{ value.split('|')[3] }}"
unit_of_measurement: "°C"
Binary sensor
The TCP Binary Sensor is a type of TCP Sensor which is either “off” or “on”. In order to use this sensor type, in addition to the configuration for the TCP Sensor, you must supply a value_on
value to represent what is returned when the device is turned on.
To enable this sensor, add the following lines to your configuration.yaml
:
# Example configuration.yaml entry
binary_sensor:
- platform: tcp
host: IP_ADDRESS
port: PORT
payload: PAYLOAD
value_on: 1
Configuration Variables
The name you’d like to give the sensor in Home Assistant.
Defines a template to extract the value.
entire response is the value
The size of the receive buffer in bytes. Set this to a larger value if you expect to receive a response larger than the default.
How long in seconds to wait for a response from the service before giving up and disconnecting.