Esp32 cam on/off by power_down_pin: GPIO32?

hello , how to use power_down_pin: GPIO32 ?

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  name: "Doorbell camera"

thank you

2 Likes

Hi bellad17, did you have any luck? I tried with a GPIO switch, but it gets instantly reverted to off every time I turn it on in the Home Assistant GUI:

switch:
  - platform: gpio
    pin: GPIO32
    name: "Camera stream"

It sais “while its inactive” but the only way i was able to start it back up was to make a button that toggles the reset_pin

try this. It will just give you 1 button that will power down or reset depending on the state of the camera.

switch:
  - platform: gpio
    name: 'Power Down Kitchen Cam'
    id: power_down
    internal: true
    pin: 
      number: GPIO32
      allow_other_uses: true
    inverted: false

    

button:
  - platform: restart
    name: "kitchen Cam Restart"
    internal: true
    id: restart_cam

  - platform: template
    name: "Power Down/Reset"  
    id: power_down_reset
    on_press:
      then:
        - if:
            condition:
              switch.is_off: power_down
            then: 
              switch.turn_on: power_down
            else:
              - if:
                condition:
                  switch.is_on: power_down
                then:
                  button.press: restart_cam   

@bellad17

I’m struggling with the same idea and when I try the upper code I’m getting the this error in ESPHome

Does this no longer work since ESPHome 2024.xx??

I have been able to compile the button code:

captive_portal:

#Configuration
switch:
  - platform: gpio
    name: 'Power Down Kitchen Cam'
    id: power_down
    internal: true
    pin: 
      number: GPIO32
      allow_other_uses: true
    inverted: false
  
  - platform: restart
    name: $hostname restart

button:
  - platform: restart
    name: "kitchen Cam Restart"
    internal: true
    id: restart_cam

  - platform: template
    name: "Power Down/Reset"  
    id: power_down_reset
    on_press:
      then:
        if:
          condition:
            switch.is_off: power_down
          then: 
            switch.turn_on: power_down
          else:
            if:
              condition:
                switch.is_on: power_down
              then:
                button.press: restart_cam   

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  vertical_flip: False
  horizontal_mirror: False
  name: stream

However, I am unable to make the compilation work since it provides the following error message.

Can some one provide a functional code?

What does the error message say??

It sais you are using Pin 32 in more than 1 place. You can only use a gpio for more than 1 thing in unique circumstances and in your circumstance, you just need to stop using Pin32 for 2 things and use a different pin for the second thing or fix your code if that’s the problem.

“Functional code” was posted multiple times and your problem isnt the code and it being wrong. You have errors in your code and just need to take a moment to learn how troubleshoot it.

This is really important to understand so ill try explaining it for you… when you see code going down a page and also strangely indented, its for a good reaso.

Everything underneath and indentated right, they are all commands for the top Left most spaced function…

   on_press:
      then:
        if:
          condition:
             - switch.is_off: power_down
          then: 
             - switch.turn_on: power_down
          else:
             if:
              condition:
                 - switch.is_on: power_down
              then:
                - button.press: restart_cam

Because on_press is all the way left, then everything underneath it and indented all belong to the on_press function and “then” is down 1 and indented 2 spaces which means your “then” belons to on_press and gets called second after on_press. Next is “if” and here its indented more because the “condition”, “then”, “else” belong to the first “if statement” and all of it belongs to or gets triggered by on_press.

If you have a more complex automation, like more than 1 if-then-else automations…

on_press:
      then:
        - if:
           condition:
              - switch.is_off: power_down
           then: 
              - switch.turn_on: power_down
           else:
             if:
              condition:
                 - switch.is_on: power_down
              then:
                - button.press: restart_cam

        - if:
           condition:
             - switch.is_on: power_down
          then: 
             - switch.turn_on: power_down
          else:
             if:
              condition:
                 - switch.is_on: power_down
              then:
                - button.press: restart_cam

Here there are 2 “if” statements or 2 primary ones at least. Notice how they are directly underneath each other and both “- if” are indented the same amount? This means both are seperate but equal and one or the other will run, not both. They are 2 seperate automations. Here when on_press happens, it will then check the first ‘if’ statement…

  - if:
           condition:
              - switch.is_off: power_down

If power_down is Off(True) then it will execute the code underneath that first ’ - if ’

 then: 
              - switch.turn_on: power_down

and so on.

If power_down is ON then the ’ - if ’ is False/Not True and then it and won’t execute that second ’ - if ’ code block

 condition:
              - switch.is_off: power_down

Kinda make sense?