I’m new to ESPHome. I have a ESP8266 connected to a sensor and a relay. They are configured below:
switch:
- platform: gpio
name: relay_1
inverted: True
pin: 13
restore_mode: RESTORE_DEFAULT_OFF
sensor:
- platform: adc
pin: A0
name: "Water Tank Voltage"
update_interval: 5s
filters:
- median:
- multiply: 3.3
In order for the sensor to work, the relay needs to be switched ON. How can I ensure that the relay is switched on + a delay before taking a sensor reading? I’m a bit new to ESPHome so appreciate the help!
tom_l
January 6, 2021, 9:45am
2
See the second attempt in this post:
I would suggest doing it like this:
sensor:
- platform: adc
pin: A0
accuracy_decimals: 4
icon: "mdi:water-percent"
id: rainsensor
name: "Rainsensor Garden"
interval:
- interval: 1min
then:
- output.turn_on: rs_power
- delay: 500ms
- component.update: rainsensor
- output.turn_off: rs_power
output:
- platform: gpio
pin: D4
id: rs_power
The rainsensor is connected to D4 and A0.
EDIT: Forget the above. this won’t work, as HA po…
1 Like
@tom_l you are a hero of this forum, thank you for the answer (and for being so active and helpful!)
Below is my final solution after integrating from the post you shared:
output:
- platform: gpio
pin: 13
inverted: True
id: water_sensor_power
sensor:
- platform: adc
pin: A0
id: "_waterTankVoltage"
internal: True
filters:
- median:
- multiply: 3.3
- platform: template
name: "Water Tank Sensor Voltage"
id: "waterTankVoltage"
unit_of_measurement: "%"
icon: "mdi:water-percent"
interval:
- interval: 15s
then:
- output.turn_on: water_sensor_power
- delay: 10s
- component.update: _waterTankVoltage
- sensor.template.publish:
id: waterTankVoltage
state: !lambda |-
return id(_waterTankVoltage).state;
- delay: 200ms
- output.turn_off: water_sensor_power
Works exactly as expected. ESPHome is magic
2 Likes
tom_l
January 6, 2021, 5:23pm
4
hummingbear:
ESPHome is magic
Yeah it’s a fantastic project. Makes DIY IoT devices very easy.