Fan template configuration

Hello,

I have a ventilation system that has a tcp modbus.

My configuration:

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

fan:
  - platform: template
    fans:
      ventilation:
        friendly_name: "Ventilation system"
        value_template: "{{ states('fan.ventilation', 'on') }}" 
        speed_template: "{{ states('fan.ventilation.speeds') }}"                                                                                                                                                    
        turn_on:
          service: modbus.write_register
          data:
            unit: 1
            address: 1
            value: 2
        turn_off:
          service: modbus.write_register
          data:
            unit: 1
            address: 1
            value: 0
        set_speed:
          service: modbus.write_register
          data_template:
            unit: 1
            address: 1
            value: "{{ speed }}" 
        speeds:
          - '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/entity.py”, line 199, in async_update_ha_state
yield from self.async_device_update()
File “/usr/src/app/homeassistant/helpers/entity.py”, line 320, in async_device_update
yield from self.async_update()
File “/usr/src/app/homeassistant/components/fan/template.py”, line 302, in async_update
state = self._template.async_render()
File “/usr/src/app/homeassistant/helpers/template.py”, line 132, in async_render
return self._compiled.render(kwargs).strip()
File “/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py”, line 76, in render
return original_render(self, *args, **kwargs)
File “/usr/local/lib/python3.6/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/usr/local/lib/python3.6/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/usr/local/lib/python3.6/site-packages/jinja2/_compat.py”, 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/sandbox.py”, line 427, in call
return __context.call(__obj, *args, **kwargs)
TypeError: call() takes 2 positional arguments but 3 were given

Thanks.

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') }}"   

or

        speed_template: "{{ speed }}"   

may work.