Template Fan - Set Direction

Hi All,

I’m in the middle of setting up a template fan to add the direction functionality to an MQTT fan.
Its mostly going ok :confused:

Where i’m currently stuck is on the template for set direction.
I have set up a sensor from my MQTT fan for what the true direction is so I get feed back. I also have scripts for both forwards and backwards direction setting.

The only examples ive found where people have implemented direction is broadlink toggles.
I know if should be simple but I just dont know how to get started if I have both forward and reverse scripts.

Here is my code so far:

fan:
  - platform: template
    fans:
      guest_template_fan:
        friendly_name: "Template fan"
        value_template: "{{ states('fan.bedroom_fan') }}"
        percentage_template: "{{ state_attr('fan.bedroom_fan', 'percentage') }}"
        turn_on:
          service: fan.turn_on
          data_template:
            entity_id: fan.bedroom_fan
        turn_off:
          service: fan.turn_off
          data_template:
            entity_id: fan.bedroom_fan
        set_percentage:
          service: fan.set_percentage
          data:
            percentage: "{{ percentage }}"
          target:
              entity_id: fan.bedroom_fan
         
                
        direction_template: "{{ 'forward' if is_state('sensor.guest_room_fan_direction', 'forward') else 'reverse' }}"
        set_direction:
          service: script.fan_direction
          data:
            direction: "{{ direction }}"
        speed_count: 6

my direction scripts are called script.bedroom_fan_forward & script.bedroom_fan_reverse which are just TuyaSend commands I may just build into the fan itself.

Any help on either of these issues would be very helpful :slight_smile:

Thank you

Linton

1 Like

Closing this off.

After much searching and experimentation I realised the direction buttons are simply a toggle and not individually mapped buttons. (This little tidbit would have been much appreciated if it were in the docs)

I solved it by using a ‘choose’ script with conditions and then simply running one of my corresponding scripts to change the direction.

Hope this helps someone in the future

do you mind sharing your script. i have most of it working on my side, but… if i set the speed of the fan, for some reason it stops and then reverses direction. i only call the direction toggle on the power_on script side of things, so it really boggles my mind when it reverses.

Can this be tied to a slider?