Control a ceiling fan using Esphome and NodeMCU but only full speed working, speed 1,2 and 3 are not?

What’s wrong with this??

My installation with circuit diagram.

My code is working correctly and I can turn off the fan and on as well
But it only works on full speed and lower speed of 1,2 and 3 doesn’t work
I’m using: 2.2uF 400V x1 3.3uF 400V x1 220kohm 1/4W x2 2.2 ohm 1/4W x2
This all components I’m using to control the fan speed
But it doesn’t seem to work… speed 1,2 and 3 don’t work but 4 works well

What sort of fan?

Voltage?

Current?

Can we see the code?

It is normal ceiling fan… 240V AC…

Well for a start R1 and R3 are probably not rated for that voltage. 1/4W resistors rarely have a voltage rating suitable for the peak voltage you are exposing them to (325V).

I can’t do any calculations for current because you have not supplied a power or current rating for your fan.

Also still no config.

I’ve been following this tutorial… https://youtu.be/AJwdF4L6HNU

Here you’ll find everything that I’ve done…

Why have you opened another thread?

Where is here?

The first thread was about how do I make a fan regulator and second one is I am unable to get control speed, they both are different… follow this link to see what I am using: Fan Speed Control with & without Internet | Blynk | ESP32 Projects - YouTube

We need to see your code. I am not interested in following some youtube video to see it. The video jockey is not even using esphome. You are.

Hey, Thank you so much for your help but the issue is resolved, the error was the wrong connection of Resistors, once I connected them properly according to the circuit diagram it worked like charm. I was aware I had done the mistake in connection and so I was asking you to check the connection… But anyways thank you once again…

You still need to address this unless you want to burn your house down.

Yes I understand, I am not using it on live things, I was just testing things out… Thank You… I will fix it when I go live with real connections.

I hope you will be able to do a write up with your esphome code for the benefit of others. Cheers.

You were so right regarding this… it caught fire during the testing process only… I was trying to make it work using a touch sensor as well as using ESPHome… and all of a sudden the resistor was on fire…

I mean once you have a module that doesn’t catch fire. :slight_smile:

Yes I know that, I was just letting you know what happened… I am ready with code, all I want now is to get stable resistors, which do you think I should go with?

Fan Speed Controller - DIYWiki seems to say 400v for each component, but I saw another site that said 600v.

Hello this is my code to control the fan speed and this works well, but the only problem I am having is when I press the button/sensor it updates but the updated version is not shown in HA Dashboard, how can I link sensors with output.

Thank You.

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_click:
      then:
        - switch.turn_off: mbedspeed1
        - switch.turn_off: mbedspeed2
        - switch.turn_off: mbedspeed4

  - platform: gpio
    pin: D1
    name: 'Fan Speed 1'
    on_click:
      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

Hi - Were you able to fix circuit and code?