Template in tcp sensor

I’ve had an HA 0.28 install on RPI that died due to a SD card corruption. After that I’ve rebuilt it with HASSBIAN (HA 0.31) and copied ‘configuration.yaml’ from backup and now I’m having this error:

16-10-30 00:27:03 homeassistant.components.sensor: Error while setting up platform tcp
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/sensor/tcp.py", line 47, in setup_platform
    add_devices([TcpSensor(hass, config)])
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/sensor/tcp.py", line 60, in __init__
    value_template = Template(value_template, hass)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 59, in __init__
    raise TypeError('Expected template to be a string')
TypeError: Expected template to be a string

The only way to get the tcp sensor running is removing the value_template line

This is the sensor config:

- platform: tcp
    name: Total Power
    host: api.thingspeak.com
    port: 80
    timeout: 10
    payload: "GET /channels/000000/fields/1/last?api_key=XXXX\n"
    value_template: "{{ value | round(1) }}"
    unit: W

What am I doing wrong?

Thanks.

I’m still a little shaky on value templates myself, but what is value? The error sounds like it is expecting it to be a string when it is actually an integer.

The template I mentioned above was one of various attempts to remove the error. The original template that worked in .28 was:

"{{value|round|int}}"

I’m also not really into templates but I think value is the value obtained form the sensor. In this case a float value obtained from thingspeak that I want to round to an int.

What I feel strange is the fact that it doesn’t mater what I put in value_template. It always gives that error.

Have made some more tests: no success.

Simply using:

value_template: "{{1}}"

Also produces the error…

:pensive:

I’ve been having the same issue and I think i’ve diagnosed the problem. Looks like the TCP sensor wasn’t updated at some point and it doesn’t correctly initialise the template. I’m submitting a Pull to fix this.

[Edit]

Sumitted as PR 5211

1 Like