Anyone got any ideas?
To change the fan’s direction, is it one IR code (it toggles the direction) or are there two IR codes (one for each direction)?
For the configuration of set_direction
, instead of the service calling a script, have you tried calling broadlink.send
? In other words, eliminate the script and place its service call within the Template Fan’s set_direction
.
That’s what I’d do. Template the package field with
data_template:
host: 'broadlinkip'
packet: >
{% if direction == 'forward' %}
forward packet number
{% else %}
Backward packet number
{% endif %}
I’m on mobile and don’t have access to the correct quote style, so you’ll need to change to the correct single quote type
Thanks for your help @petro and @123. Much appreciated. I tweaked my code below but it’s still not working. Did I do it correctly?
fan:
- platform: template
fans:
template_bedroom_fan:
friendly_name: "Master Bedroom Fan"
value_template: "{% if states('sensor.bedroom_fan_shelly_power') | float > 3 %}on{% else %}off{% endif %}"
speed_template: "{{ states('input_select.master_fan_set_speed') }}"
direction_template: "{{ states('input_select.master_fan_set_direction') }}"
turn_on:
service: script.bedroom_fan_on
turn_off:
service: script.bedroom_fan_off
set_speed:
service: script.master_fan_set_speed
data_template:
speed: "{{ speed }}"
set_direction:
service: broadlink.send
data_template:
host: 'hostip'
packet: >
{% if direction == 'forward' %}
'broadlinkcode.samefor.forwardandreverse='
{% else %}
'broadlinkcode.samefor.forwardandreverse='
{% endif %}
speeds:
# - 'Select Speed'
- '1' ## 4.27~5.07 watts ##
- '2' ## 6.33~6.67 watts ##
- '3' ## 9.46~9.93 watts ##
input_select:
master_fan_set_speed:
name: Master Bedroom Speed
options:
# - 'Select Speed'
- '1'
- '2'
- '3'
# initial: 'Select Speed'
icon: mdi:fan
master_fan_set_direction:
name: Master Fan Direction
options:
- 'forward'
- 'reverse'
This works in the template editor but does not change the fan direction.
set_direction:
service: broadlink.send
data_template:
host: '10.0.1.220'
packet: >
{% if states.input_select.master_fan_set_direction.state == 'forward' %}
'123456789AAAAAAAAAAAAAAAA='
{% else %}
'123456789AAAAAAAAAAAAAAAA='
{% endif %}
It’s a toggle (one code).
Also tried this just for fun, does not work either.
set_direction:
service: broadlink.send
data_template:
packet: >
{% if is_state('input_select.master_fan_set_direction', 'forward') %}
"123456789AAAAAAAAAAAAAAAA="
{% elif is_state('input_select.master_fan_set_direction', 'reverse') %}
"123456789AAAAAAAAAAAAAAAA="
{% endif %}
host: 10.0.1.220
Yet, if I use the same data in the Dev > Services tab, it works.
If one code is used to toggle the direction, why is your template checking the input_select’s direction? Forward or reverse, it sends the same code so I don’t see a need for a template.
set_direction:
service: broadlink.send
data:
host: '10.0.1.220'
packet: '123456789AAAAAAAAAAAAAAAA='
Anyway, that’s just an observation and it probably isn’t responsible for the problem.
Thanks and you’re correct, that did not work either. Might be a problem with the template fan integration? I’ve tidied up the code as you’ve suggested just in case.
I just re-read your original post and saw what you said with fresh eyes. The input_select
does not control the Template Fan’s direction.
The fan’s direction is controlled using the two buttons seen here in the lower left:
Your fan’s configuration has this:
direction_template: "{{ states('input_select.master_fan_direction')
That’s not for controlling the fan, that’s for reporting feedback from the actual fan.
When you change the fan’s direction using one of the two buttons in the UI (seen above), set_direction
runs and sends the Broadlink IR command to the actual fan. Then the Template Fan expects to receive the fan’s new direction via direction_template
.
From the documentation:
direction_template
(template)(Optional)
Defines a template to get the direction of the fan. Valid value: ‘forward’/‘reverse’
It says get the direction of the fan, not set the direction of the fan.
Ah ha! Now we’re getting somewhere. So if I have no feedback from the fan in regards to what direction it’s going, what do I put in the direction_template
as I was just copying the speed one above it?
The docs are quite confusing but from what you’re saying, the direction_template
creates the arrows does it? Based on your feedback, I’d say I have an issue with my speed template too as I’ve misinterpreted that function too (even though speed is working).
If there’s no feedback from the fan then just fake it. Here’s what I suggest:
Create an input_boolean to represent the fake direction status. Let’s say that on
means forward and `off means reverse.
Change the direction_template
so that it uses the input_boolean.
direction_template: "{{ 'forward' if is_state('input_boolean.master_fan_direction', 'on') else 'reverse' }}"
In set_direction
, add a second service call to toggle the state of the input_boolean.
set_direction:
- service: broadlink.send
data:
host: '10.0.1.220'
packet: '123456789AAAAAAAAAAAAAAAA='
- service: input_boolean.toggle
entity_id: input_boolean.master_fan_direction
Thank you, I’ll give that a try. So is my current input boolean valid?
master_fan_set_direction:
name: Master Fan Direction
options:
- 'forward'
- 'reverse'
Never mind, I just remove the options.
Success @123! Thank you. Been bugging me for 6 weeks. I used your exact code. I’ll put in a PR to see if we can have valid options for winter/summer as well as forward/reverse as that would increase the WAF!
The only thing I’d like to tidy up is the speed selection as currently it defaults to 1, but you have to select 2 or 3 to start the fan. I’d like to be able to select 1 as the first speed option. I know I can just turn it on when its on 1 but I’m a stickler for detail.
Here is my current speed set up which I complied from various forums posts.
speed_template: "{{ states('input_select.master_fan_set_speed') }}"
set_speed:
service: script.master_fan_set_speed
data_template:
speed: "{{ speed }}"
speeds:
# - 'Select Speed'
- '1' ## 4.27~5.07 watts ##
- '2' ## 6.33~6.67 watts ##
- '3' ## 9.46~9.93 watts ##
input_select:
master_fan_set_speed:
name: Master Bedroom Speed
options:
# - 'Select Speed'
- '1'
- '2'
- '3'
# initial: 'Select Speed'
icon: mdi:fan
script:
bedroom_fan_on:
alias: MasterFan (On)
sequence:
- service_template: >
{% if is_state("input_select.master_fan_set_speed", "1") %}
script.bedroom_fan_1
{% elif is_state("input_select.master_fan_set_speed", "2") %}
script.bedroom_fan_2
{% elif is_state("input_select.master_fan_set_speed", "3") %}
script.bedroom_fan_3
{% endif %}
master_fan_set_speed:
alias: Master Fan Set Speed
sequence:
- service: input_select.select_option
data_template:
entity_id: input_select.master_fan_set_speed
option: '{{speed}}'
- service: script.turn_on
data_template:
entity_id: script.bedroom_fan_{{ speed }}
Wondering if someone can assist with converting my template fan config over to the new percentage based system introduced in 201.3.x?
These two posts might be enough to get you started.
I forked an updated your gist here. You might need to tweak master_fan_set_percentage
a bit.
Legend! Thank you so much. I’ll give that a whirl in the morning and report back.
Hey @123 , sorry to hijack an old answer. I was wondering where in your example you would otherwise define which direction the broadlink code corresponds to?
I understand that situation was simply a toggle but I’m trying to figure out how to set commands for individual forwards and backward buttons. I have scripts that will change the direction I’m hoping to attach to the native buttons
Cheers
Linton
I don’t own a Broadlink device but two years ago this topic interested me but, unfortunately, not today. Hopefully someone else can assist you.