xbmcnut
(xbmcnut)
October 19, 2019, 9:44pm
1
I’ve been building my Broadlink fans for weeks and everything is working great except the direction command. It seems I may need a data_template in my script as the template fan direction command is not accepting my basic script. Can anyone help me build that?
speed_template: "{{ states('input_select.master_fan_set_speed') }}"
direction_template: "{{ states('input_select.master_fan_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: script.turn_on
entity_id: script.master_fan_reverse
master_fan_reverse:
alias: Master Fan Reverse
sequence:
- service: broadlink.send
data:
host: 'ipofbroadlink'
packet: 'broadlinkcodetosend'
If I run the script on its own, the fan reverses but if I use the input_select with forward/reverse, it does not.
This is the section from the Template Fan I’m unsure about.
set_direction:
service: script.fan_direction
data_template:
direction: "{{ direction }}"
xbmcnut
(xbmcnut)
October 19, 2019, 10:35pm
2
UPDATE: I’ve copied the speed template in an attempt to get the direction working but using the code below, it still does not work. Anyone see why? As before, the individual forward/reverse scripts work on their own.
direction_template: "{{ states('input_select.master_fan_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: script.master_fan_direction
data_template:
direction: "{{ direction }}"
master_fan_direction:
name: Master Fan Direction
options:
- 'forward'
- 'reverse'
master_fan_reverse:
alias: Master Fan Reverse
sequence:
- service: broadlink.send
data:
host: 'broadlinkip'
packet: 'broadlinkcodetosend'
master_fan_forward:
alias: Master Fan Forward
sequence:
- service: broadlink.send
data:
host: 'broadlinkip'
packet: 'broadlinkcodetosend'
master_fan_direction:
alias: Master Fan Direction
sequence:
- service: input_select.select_option
data_template:
entity_id: input_select.master_fan_direction
option: '{{direction}}'
- service: script.turn_on
data_template:
entity_id: script.master_fan_{{ direction }}
123
(Taras)
October 30, 2019, 12:29pm
4
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
.
petro
(Petro)
October 30, 2019, 12:44pm
5
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
xbmcnut
(xbmcnut)
November 1, 2019, 2:52am
6
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'
xbmcnut
(xbmcnut)
November 1, 2019, 3:14am
7
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 %}
xbmcnut
(xbmcnut)
November 1, 2019, 3:15am
8
It’s a toggle (one code).
xbmcnut
(xbmcnut)
November 1, 2019, 3:34am
9
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.
123
(Taras)
November 1, 2019, 3:53am
10
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.
xbmcnut
(xbmcnut)
November 1, 2019, 5:21am
11
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.
123
(Taras)
November 1, 2019, 6:01am
12
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.
xbmcnut
(xbmcnut)
November 1, 2019, 6:08am
13
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).
123
(Taras)
November 1, 2019, 6:18am
14
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
1 Like
xbmcnut
(xbmcnut)
November 1, 2019, 6:26am
15
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.
xbmcnut
(xbmcnut)
November 1, 2019, 9:13am
16
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 }}
xbmcnut
(xbmcnut)
November 2, 2019, 10:41am
17
Got it all working perfectly! Thanks for your help @123 and @petro . Full code here .
xbmcnut
(xbmcnut)
March 9, 2021, 9:19pm
18
Wondering if someone can assist with converting my template fan config over to the new percentage based system introduced in 201.3.x?
bdraco
(J. Nick Koston)
March 12, 2021, 8:03am
19
I have a lutron caseta plug that is technically a light but it’s dimmable. I had my little window box fan working perfectly with it until all the changes, I can get it to turn on and off, but any preset calls or percentage calls do nothing. Attaching my code snippet. I would be grateful for help. Ignore the rem’d out lines, I left them behind so I could use them for reference when making the new sections.
fan:
- platform: template
fans:
jrs_bedroom_window_fan:
friendl…
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.
shellypm1_fan.yaml
fan:
- platform: template
fans:
template_bedroom_fan:
friendly_name: "Master Bedroom Fan"
# Measures the power use from a Shelly1 PM and if over 3W, marks the fan as on
value_template: "{% if states('sensor.bedroom_fan_shelly_power') | float > 3 %}on{% else %}off{% endif %}"
# Uses the Shelly1 PM sensor value to determine what speed the fan is going at. Only set to measure 33, 66, 100
percentage_template: "{{ states('sensor.template_fan_percentage_master') }}"
# Uses a fake switch from an input_boolean as the fan has no way of reporting direction back to HA
This file has been truncated. show original
xbmcnut
(xbmcnut)
March 12, 2021, 9:30am
20
Legend! Thank you so much. I’ll give that a whirl in the morning and report back.