I have a fan component that I have made, It works two ways one using binary_sensor and one using Output… but they both operate differently.
I want to link them together. For now, what happens is when I press the touch sensor/binary_sensor it changes the fan speed but the state is not updated on Lovelace Card. I want it such that when a button is pressed the Lovelace card is changed as well.
Here is my code:
switch:
- platform: gpio
pin: D5
name: "Master Bedroom Fan Speed Relay 1"
id: mbedspeed1
- platform: gpio
pin: D6
name: "Master Bedroom Fan Speed Relay 2"
id: mbedspeed2
- platform: gpio
pin: D7
name: "Master Bedroom Fan Speed Relay 3"
id: mbedspeed4
binary_sensor:
- platform: gpio
pin: D0
name: 'Turn Off Fan'
on_press:
then:
- switch.turn_off: mbedspeed1
- switch.turn_off: mbedspeed2
- switch.turn_off: mbedspeed4
- platform: gpio
pin: D1
name: 'Fan Speed 1'
id: d10
on_press:
then:
- switch.turn_on: mbedspeed1
- switch.turn_off: mbedspeed2
- switch.turn_off: mbedspeed4
- platform: gpio
pin: D2
name: 'Fan Speed 2'
on_click:
then:
- switch.turn_off: mbedspeed1
- switch.turn_on: mbedspeed2
- switch.turn_off: mbedspeed4
- platform: gpio
pin: D3
name: 'Fan Speed 3'
on_click:
then:
- switch.turn_on: mbedspeed1
- switch.turn_on: mbedspeed2
- switch.turn_off: mbedspeed4
- platform: gpio
pin: D4
name: 'Fan Speed 4'
on_click:
then:
- switch.turn_off: mbedspeed1
- switch.turn_off: mbedspeed2
- switch.turn_on: mbedspeed4
output:
- platform: template
id: custom_fan
type: float
write_action:
- if:
condition:
- lambda: return ((state == 0));
then:
# action for off
- switch.turn_off: mbedspeed1
- switch.turn_off: mbedspeed2
- switch.turn_off: mbedspeed4
- if:
condition:
- lambda: return ((state > 0) && (state < 0.3));
then:
# action for speed 1
- switch.turn_on: mbedspeed1
- switch.turn_off: mbedspeed2
- switch.turn_off: mbedspeed4
- if:
condition:
lambda: return ((state > 0.3) && (state < 0.6));
then:
# action for speed 2
- switch.turn_off: mbedspeed1
- switch.turn_on: mbedspeed2
- switch.turn_off: mbedspeed4
- if:
condition:
lambda: return ((state > 0.6) && (state < .9));
then:
# action for speed 3
- switch.turn_on: mbedspeed1
- switch.turn_on: mbedspeed2
- switch.turn_off: mbedspeed4
- if:
condition:
lambda: return ((state == 1));
then:
# action for speed 4
- switch.turn_off: mbedspeed1
- switch.turn_off: mbedspeed2
- switch.turn_on: mbedspeed4
fan:
- platform: speed
id: mbedfan
output: custom_fan
name: "Master Bedroom Fan"
speed_count: 4