Template configuration

I’m trying to create template switch but i’m getting error.
Confg:

switch:
  - platform: template
    switches:
      television:
        value_template: "{{ is_state('switch.plug_158d00039bb63c.attributes.load_power'|int > 50) }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.tv
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.tv
        icon_template: >-
          {% if is_state('switch.plug_158d00039bb63c.attributes.load_power'|int > 50) %}
            mdi:television
          {% else %}
            mdi:television-off
          {% endif %}
      

Error:

Szczegóły loga (ERROR)
Logger: homeassistant.helpers.entity
Source: helpers/template.py:1016
First occurred: 10:33:50 (1 occurrences)
Last logged: 10:33:50

Update for switch.television fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 470, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/template/switch.py", line 195, in async_update
    state = self._template.async_render().lower()
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 228, in async_render
    return compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.7/site-packages/jinja2/sandbox.py", line 462, in call
    return __context.call(__obj, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1016, in wrapper
    return func(hass, *args[1:], **kwargs)
TypeError: is_state() missing 1 required positional argument: 'state'

All sorts of errors in that code. First:

switch: with the colon.

Then I think you want state_attr not is_state for testing the attribute (reference).

Finally, the bracket is in the wrong place for both value_template and icon_template:

{% if state_attr('switch.plug_158d00039bb63c', 'load_power')|int > 50 %}

See where that gets you…

Thanks,
First: The colon was there from the beginning but I accidentally deleted it. :roll_eyes:
Rest: Thank you very much