Engine start after power restore

Good evening,

A deodorizer connected to a homeassistant… an ESP32C3 connected to a 3.3V motor via an MX1508 Motor Driver Module.

I followed this tutorial:

The problem is that when the device starts up (after a power failure), the deodorizer activates. I wanted to know how I can prevent the motor from starting after a power failure.

I think this depends on some sort of current oscillation at start-up that activates the motor. Perhaps with a resistor?

the project is similar to this one only I use an ESP32C3 without the 3.3 buck converter (I use the 3.3V output of the ESP32C3 directly):

here is my code:

esphome:
  name: airfresh
  friendly_name: Airfresh
  on_boot:
    then:
      - lambda: |-
          id(spray_count) += 1;
          id(spray_counter).update();


esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf

captive_portal:

globals:
  - id: spray_count
    type: int
    restore_value: yes
    initial_value: '0'
    
switch:
  - platform: gpio
    id: fwd
    name: Motor Forward
    pin: 6 #int2
  

  - platform: gpio
    id: rvs
    name: Motor Reverse
    pin: 5 #int1


sensor:
  - platform: template
    name: "Conteggio Spruzzate"
    id: spray_counter
    unit_of_measurement: "spray"
    accuracy_decimals: 0
    update_interval: 1s
    lambda: |-
      return id(spray_count);

button:
  - platform: template
    id: btn_spray
    name: "Spray"
    on_press:
      - switch.turn_on: fwd
      - delay: 300ms
      - switch.turn_on: rvs
      - delay: 500ms
      - switch.turn_off: fwd
      - delay: 300ms
      - switch.turn_on: fwd
      - delay: 500ms
      - switch.turn_off: fwd
      - switch.turn_off: rvs  
      - lambda: |-
          id(spray_count) += 1;
          id(spray_counter).update();


  - platform: template
    name: "Reset Conteggio Spray"
    icon: "mdi:counter-reset"
    on_press:
      - lambda: |-
          id(spray_count) = 0;
          id(spray_counter).update();

Perhaps your code?

Ps. your Esp32 voltage regulator might have hard time there in long term…

thanks…

captive_portal:

globals:
  - id: spray_count
    type: int
    restore_value: yes
    initial_value: '0'
    
switch:
  - platform: gpio
    id: fwd
    name: Motor Forward
    pin: 6 #int2
  

  - platform: gpio
    id: rvs
    name: Motor Reverse
    pin: 5 #int1


sensor:
  - platform: template
    name: "Conteggio Spruzzate"
    id: spray_counter
    unit_of_measurement: "spray"
    accuracy_decimals: 0
    update_interval: 1s
    lambda: |-
      return id(spray_count);

button:
  - platform: template
    id: btn_spray
    name: "Spray"
    on_press:
      - switch.turn_on: fwd
      - delay: 300ms
      - switch.turn_on: rvs
      - delay: 500ms
      - switch.turn_off: fwd
      - delay: 300ms
      - switch.turn_on: fwd
      - delay: 500ms
      - switch.turn_off: fwd
      - switch.turn_off: rvs  
      - lambda: |-
          id(spray_count) += 1;
          id(spray_counter).update();


  - platform: template
    name: "Reset Conteggio Spray"
    icon: "mdi:counter-reset"
    on_press:
      - lambda: |-
          id(spray_count) = 0;
          id(spray_counter).update();

but I think it’s a HW issue… I tried some configuration but the motor starts instantly when the power is connected. so I think it can be resolved perhaps with resistance but I’m not sure.

it is installed near an air conditioning vent… I use it in some particular cases, not always. Maybe four or five times a month to perfume the whole house.

Boot pin fluctuations would be too short to spray anything.
I’m not familiar with that motor driver.
Anyway, to start with, set your switches restore_mode: ALWAYS_OFF

I’ve already tried it… as ChatGPT suggested (I don’t ask much of ChatGPT, 95% of the time it gets it wrong… but in rare cases it can give me an answer)

I had a quick search about the driver and there should be weak pull-downs on input.
What gives little bit doubts here is gpio6, it might be pulled up after reset.

You could do two things. On your yaml change the switch pins to some other free pins but leave the physical wiring on 5/6. That gives you answer if the problem is esphome related or not.
If it’s not, then use some “clean” pins for your motor control, for example Gpio1 and 3.

i just got worked Airwick like this: https://community.home-assistant.io/t/airwick-electric-controlled-sprays/281098/2.I updated my project. now it works without battery,it uses mains power with step-down converter.

in the end I solved it by changing the pins… pin 10 for the Motor Forward and pin 4 for the Motor Reverse.