Unreliadble esp8266 nodemcuv2 setup

Hi!
I have spent lots of hours before coming to post here.
I have been playing for over a year with esp and home automation (domoticz cause I was afraid of the yaml files) and recently I setup a Hassio VM on my UnRaid server running perfectly and learning everything the proper way (3-4 videos to learn for pull-up resistors!).

I have a esp8266 nodemcuv2 powered with a samsung 2A and a good micro-usb cable. (Plans to change power supply)
I have connected 4 float-switches on D2 D3 D5 D6 and used 4.7K pull-ups from a 3.3v pin.
I have used ~5meters UTP cable to connect the float switches with the ESP.

I just created my first schematic and I included the ESPHome settings.
My problem is that it is not reliable.
When I power it up everything works exactly as it should. I test each float switch manually and it works. After some time (unknown) it hangs. Now all my switches are off and it is stuck on the boot states. As I am currently away, I re-uploaded esphome to reboot and it still says D2 D3 D5 ON but my water tank is empty! D6 stuck to off as it was off when I powered the ESP.

My biggest problem is that I don’t know how to debug.
Any help is welcome!

circuit

esphome:
  name: watertank
  platform: ESP8266
  board: nodemcuv2

wifi:
  networks:
  - ssid: "SpitiA"
    password: "xxxxxx"
  - ssid: "SpitiB"
    password: "xxxxxx"
  - ssid: "SpitiD"
    password: "xxxxxxx"
  manual_ip:
    static_ip: 192.168.1.200
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.20
    dns2: 192.168.1.1

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxx"

ota:
  password: "xxxxxxx"

binary_sensor:
- platform: gpio
  pin: D2
  name: level20
- platform: gpio
  pin: D3
  name: level40
- platform: gpio
  pin: D5
  name: level60
- platform: gpio
  pin: D6
  name: level90

If D3 is low while the NodeMCU boots it will fail. See the reference table lower down on this page:

Might be your problem. Try swapping D3 for D7.

1 Like

That’s my bad! I had read which pins to use and I must have started with D1 D2 D5 D6 but while solving other problems I must have used the wrong pins!

I will try to change power supply and the pin tonight.
Thank you

I upped the log level to very verbose in case I get any message in order to help me debug.

5M of cable is an antenna as well, connected directly to the processor pins. So you could be picking up all sorts of interference which locks up the processor. Put a 0.1uF capacitor in parallel to each switch connected data pin on the processor and ground.

So…
I corrected the wrong pin D3 and used a variable power supply set at 4.5v directly to Vin/Ground pings and after 24hours it is still working.

My next project again involves 5-7M of UTP cat5e cable and I can not find capacitors to buy (I have placed an order but it will take time to arrive).
I own a multimeter Mastech MS8268. Can I use it to detect interference?
Is there a guide to read for proper eletrical circuit designing for newbies?

Thank your for your help :slight_smile:

Unfortunately you won’t be able to use that meter to detect interference. For that you would need an oscilloscope. Or a sensitive headphone connected to the wire via a current limiting resistor, a keen ear and a quiet room. Or run it through an amp.

The value of the capacitor isn’t too critical. Anything from a few hundred pF to about 1uF would likely work.

1 Like

Until this morning that I had a power cut it was working properly.
My new problem is that despite the water tank level didn’t change it reports all values inverted.

Before power cut I had all sensor on so Full Tank
Now all sensors are off so <20%
And I didn’t change anything!!!
(My value template is so complicated as I wanted to know if one sensor is not working properly and result ERROR)

- platform: template
    sensors:
      water_level:
        friendly_name: "Water Tank Level"
        value_template: >-
          {% if is_state('binary_sensor.level90', 'on') and is_state('binary_sensor.level60', 'on') and is_state('binary_sensor.level40', 'on') and is_state('binary_sensor.level20', 'on') %}
          Full
          {% elif is_state('binary_sensor.level60', 'on') and is_state('binary_sensor.level90', 'off') and is_state('binary_sensor.level40', 'on') and is_state('binary_sensor.level20', 'on') %}
          >60%
          {% elif is_state('binary_sensor.level40', 'on') and is_state('binary_sensor.level60', 'off') and is_state('binary_sensor.level90', 'off') and is_state('binary_sensor.level20', 'on') %}
          >40%
          {% elif is_state('binary_sensor.level20', 'on') and is_state('binary_sensor.level40', 'off') and is_state('binary_sensor.level60', 'off') and is_state('binary_sensor.level90', 'off') %}
          >20%
          {% elif is_state('binary_sensor.level20', 'off') and is_state('binary_sensor.level40', 'off') and is_state('binary_sensor.level60', 'off') and is_state('binary_sensor.level90', 'off') %} 
          <20%
          {% else %}
          ERROR 
          {% endif %}

Check your 3.3V connection to the switches. This is the only common point of failure for all switches.

It happened again today.
3.3V is working properly and all connections look good.
After a power loss (HA and ESP) it’s showing inverted state for all pins.
It was working properly for at least 7 days as I tested.
Tried to reboot (switch below) and it’s not helping.
Also tried to power restart and it didn’t help.

I don’t remember how I “fixed” it a week ago.
I think I only rebooted from power supply (off/on) and it worked.

I manually turned off/on gpios D5 D6 and D1 D2 fixed! D5 D6 still showing wrong state.

Also I need help which capacitor to buy from banggood as I am going to place an order.

My last hope is that the problem is the capacitor!

switch:
  - platform: restart
    name: "Restart"