Hi,
I know this topic has been covered in other posts, but I am really unable to understand YAML and keep encountering errors.
I have set up AI Thinker Esp32-S variant with 8 channel Relay Module. Now, I want to connect manual switches (dumb Wall Switches) as a fail-safe in case esp32 does not have wi-fi or in case I do not have my phone handy, in which case, the relays would trigger with switches as well.
I have tried using on_press / on_click and other triggers, but kept encountering errors “does not inherit value” and so I left that option and went to HA automation creations.
I have created 8 switches that I am able to operated from the overview page of the HA without any glitch.
I am looking to use input pins (specifically PIN 5) on ESP32-S connected to the switches so that upon being activated with 3v current, they would trigger a relay. I have created HA Automation, however, that is not working when I connect PIN 5 to the 3V PIN on ESP32. Although when I press on Run Action, it does trigger Switch 1.
Any help would be much appreciated. I am pinning my Yaml code along with HA automations screenshot here.
Thanks in advance
Reading your requirements “fail-safe” no “wi-fi”. Because this is your requirement you can’t use HA as a automation, HA will will need wi-fi conection. So that’s out. You must have it on your ESP code… so
You cold try this. Must have a push button switch not toggle (on/off).
Thank you for the help. You are correct, HA Automations would not work in that case.
The HA Automations are working, as I was wrongly trying to trigger it by connecting pins with VCC and not GND.
I tried using the code provided by you, but it is ending up in fast flickering of switches. I even tried adding a delay of 1000ms like :
“”"
on_press:
then:
- delay: 1000ms
- light.toggle:
id: switch_1_light
“”"
but it keeps on flickering.
I think it an issue with the “toggle function”. Can you help me with this.
Thanks a lot in advance.
I have tried other pins, but the flickering issue remains.
Here is the log for the same.
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:40][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:40][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][light:046]: State: ON
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][light:046]: State: OFF
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
[23:14:41][D][light:046]: State: ON
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state ON
[23:14:41][D][binary_sensor:036]: ‘M_Switch_1’: Sending state OFF
[23:14:41][D][light:035]: ‘Switch 1’ Setting:
Hey @Blacky,
Cannot thank you enough for the help you are providing.
I seem to have pin pointed the issue. It does not lie with the code, rather with the ESP32 module.
I am using “Ai Thinker NodeMCU-32S-ESP32 Development Board – IPEX Version”
I unplugged all the wires providing input signals (even though I had not connected them to any GND / VCC) leaving the bare pins. Using the code provided by you, these pins seem to be touch sensitive. Upon even touching the blank wire without any charge, it seems to trigger the connected relays (connected via code) and if kept touched, they start flickering. Removing the wire stops the relays from flickering but then keeps them in “on” state.
Will add code herein again, just in case it may point out the reason for such action.
Hi,
All the selected input pins seem to be capacitive and working with touch as well. Could you kindly help me with the code so that the same may be used as push button. I saw a few examples wherein the value of ohms received upon touch was configured to be read as push button but they all were for Aurdino board and not HA (I mean yaml code).
However, with the board type as “nodemcu-32s”, it keeps on saying that most of the pins do not support touch.
Using the code provided, all the pins used are working with touch alone.
1/ With the code you just posted you have disconnected the switch and have bare wires.
2/ If that is correct when you touch the wires together (Bridge it out) and keep them connected the light comes on? (no flickering)
3/ When you disconnect them the light goes off?
next
1/ With my code you have disconnected the switch and have bare wires.
2/ If that is correct when you touch the wires together and release the light comes on? (no flickering)
3/ When you touch them together and hold them light on flickering?
4/ If you touch them together and release light on and if you gain touch them together and release light off.
Q: In HA do you have a toggle switch that turns the light on/off? if so what is the ID
sorry for asking questions… just trying to work this out in my head… would love to have in next to me
more code to try
binary_sensor:
- platform: gpio
pin:
number: 21
mode: INPUT_PULLUP
inverted: True
name: "M_Switch_1"
filters:
- delayed_on: 10ms
on_press:
then:
- light.toggle:
id: switch_1_light #this id is to be the one that works in HA change if necessary
or
binary_sensor:
- platform: gpio
pin:
number: 21
mode: INPUT_PULLUP
inverted: True
name: "M_Switch_1"
filters:
- delayed_on: 10ms
on_press:
then:
- light.toggle:
id: switch_1 #this id is to be the one that works in HA change if necessary
just checking your switch is wire from 21 to Ground?
I am sorry for the delay and the confusion.
The ESP32-S module I have been using seems to vary from the standard ESP32.
When the ESP was connected to the relay, the pins that were to be used as switch (Manual / dumb), were touch sensitive. So I removed the wires from those pins (input pins) and tried touching the exposed pins with bare hand, which seems to have been creating problems and switching the relays on and off leading to flickering.
So I tried to use “esp32_touch” platform but not all pins were supported to be used as touch inputs. Then I started shuffling the output pins and input pins (As per ESP-32 board layout for touch sensitive pins). I am successful in using 5 input pins which should be enough for now.
Now it is working perfectly once it is on, however, upon it being switched on, all the input pins send switch on signal (only once when the esp restarts). Is there any way around it?
I am also putting my code here, just in case you can provide more inputs or if someone else needs it in future.
Thanks a ton.
Hi there,
I did try to use the pull up function but it does not work with platform “esp_touch” and i had to change it to gpio. Changing the same to gpio led to having same issues of flickering. I did some tinkering and came to a conclusion that I had to set definition for threshold using “ESP32_touch” platform. I used a filter and it is working without any glitch. I am avoiding PIN 14 as suggested by you. It is working as intented. I will have to make some changes based on how my esp reacts on reboot but that will be done at a later stage.
Thank you for all the help.
You shouldn’t be having problems with input_pullup and as you are using switches using the binary sensor is the best option in my opinion.
Consider using resistors to do the pullup, I imagine you are doing the bench tests. If yes depending on where you run the wires you may start having problems with the finished project
This simply is an issue with the chip. I guess they are of sub par quality and hence the flickering issues and issues with them not connecting properly with WiFi.
Although a few of them work fine with “esp_touch” platform. Using them for now till I get replacements for all the chips.
Ordered esp32 wroom
They are working amazingly well with the code that you guys provided. Thank you for all the help guys.