Fan template configuration


I have a ventilation system that has a tcp modbus.

My configuration:

type: tcp
host: 192.xx.xx.xx
port: 502

  - platform: template
        friendly_name: "Ventilation system"
        value_template: "{{ states('fan.ventilation', 'on') }}" 
        speed_template: "{{ states('fan.ventilation.speeds') }}"                                                                                                                                                    
          service: modbus.write_register
            unit: 1
            address: 1
            value: 2
          service: modbus.write_register
            unit: 1
            address: 1
            value: 0
          service: modbus.write_register
            unit: 1
            address: 1
            value: "{{ speed }}" 
          - '1' 
          - '2' 
          - '3'

If I go to Developer Tools → Services and select:
Service: fan.turn_on
Entity: fan.ventilation
and hit CALL SERVICE it is starting the ventilation system so it’s working. (also working for fan.turn_off, fan.set_speed)

Using the fan template things do not work.
Any suggestions?

Also, when starting home assistant I see this on the logs:

2018-08-10 07:02:02 ERROR (MainThread) [homeassistant.helpers.entity] Update for fan.ventilation fails
Traceback (most recent call last):
File “/usr/src/app/homeassistant/helpers/”, line 199, in async_update_ha_state
yield from self.async_device_update()
File “/usr/src/app/homeassistant/helpers/”, line 320, in async_device_update
yield from self.async_update()
File “/usr/src/app/homeassistant/components/fan/”, line 302, in async_update
state = self._template.async_render()
File “/usr/src/app/homeassistant/helpers/”, line 132, in async_render
return self._compiled.render(kwargs).strip()
File “/usr/local/lib/python3.6/site-packages/jinja2/”, line 76, in render
return original_render(self, *args, **kwargs)
File “/usr/local/lib/python3.6/site-packages/jinja2/”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/usr/local/lib/python3.6/site-packages/jinja2/”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/usr/local/lib/python3.6/site-packages/jinja2/”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
File “/usr/local/lib/python3.6/site-packages/jinja2/”, line 427, in call
return, *args, **kwargs)
TypeError: call() takes 2 positional arguments but 3 were given


value_template and speed_template are supposed to be getting the information about the state of the fan from the fan somehow. You have it getting the data from the fan.ventilation entity itself. That won’t work.

Also, the reason for the exception is you gave the states function two arguments when it only takes one. I think you’re were trying to use is_state. But, again, you have to get the state from the fan, not the entity itself.

He actually may be able to get the speed from itself. I believe what drives this template is the speeds dropdown and the speed_template is just what is displayed to the UI. Kind of like the switch template. I haven’t used this myself, but I have supported a few people making this, so I could be wrong. But I think I recall someone using it like this.

        speed_template: "{{ state_attr('fan.ventilation', 'speeds') }}"   


        speed_template: "{{ speed }}"   

may work.