Hello. I have a project where I want to control a relay. Basically the logic is that I get +12V in from a control panel. This +12V I could step down to 3V to sense on GPIO on the ESP, or I could run the 12V through a relay to close a GPIO pin to high or low depending on the preference.
When this is done I want the ESP to close another relay automatically, no interaction from HA. In the HA interface / MQTT the status should update a relay switch to on. Should the 12V shut down to 0V the same relay output should open/disconnect.
The same relay switch should also be possible to control from HA, and preferrably also be able to read the status of the 12V input (does not matter if is represented as an on/off sensor or a voltage).
Sadly I suck at writing code. I guess I need to write a custom sensor. Could anyone help with this?
So far I have tinkered around the ESP32 to control a relay. That works.
I had to move the sensor and relay control due to det pull_up in boot of the ESP. Cannot have the relay just switch at boot. Altered the code like this to make it work:
esphome:
name: eber_d4_control
platform: ESP8266
board: nodemcuv2
wifi:
ssid: "replace"
password: "replace"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Eber D4 Control Fallback Hotspot"
password: "replace"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "replace"
ota:
password: "replace"
web_server:
port: 80
switch:
- platform: gpio
name: "test_lights_deca Onboard light"
pin: 2
inverted: True
restore_mode: ALWAYS_OFF
id: output_led #### <--- Note this ####
- platform: gpio
name: "d1_relay_signal"
pin: D1
# inverted: True
restore_mode: ALWAYS_OFF
id: output_relay
binary_sensor:
- platform: gpio
pin: D2 # or whatever pin you use
name: "Input Eber Controlpanel D801" # Or whatever you want to call it
filters:
- delayed_on: 10ms # debounce the relay contacts
- delayed_off: 10ms
on_release:
then:
- switch.turn_off: output_relay
- switch.turn_off: output_led
on_press:
then:
- switch.turn_on: output_relay
- switch.turn_on: output_led
If anyone is curious this is what I am building. It is a heater control for a boat.
But, the issue I am having is that when the ESP boots it defaults to “on” for the “Input Eber Controlpanel D801” even if it is off. How can I, either get the ESP to detect the state, or default the binary sensor to off?
Enable the pull_up resistor for D2 (It’s floating at the moment - not good) and invert the signalling (when your switch D801 is on D2 is pulled to ground).