Fiz um sensor de chuva como indicado neste website.
Aqui a imagem:
Utilizei uma resistência igual a da imagem (1000ohm)
Coloquei o código no ESPhome:
esphome:
name: rain-sensor
friendly_name: rain-sensor
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "liC61y1Npw1PK/RBfiG1vdaS0n0SKLzsgCSCSrlskcU="
ota:
password: "16eea3eb58797448c81e1be86799b374"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Rain-Sensor Fallback Hotspot"
password: "rPc7XbsKnszN"
captive_portal:
sensor:
- platform: adc
id: source_sensor
pin: GPIO33
name: ADC
attenuation: 11db
internal: true
# It is important to have a low update interval so that
# the measurement has time to be done correctly during
# the activation of the voltage AND taking into account the median filter
update_interval: 250ms
filters:
- multiply: 0.846153 # 3.9 (11db attenuation full-scale voltage) -> 3.3V
- median:
window_size: 7
send_every: 4
send_first_at: 3
- platform: resistance
sensor: source_sensor
id: real_resistance_sensor
name: "rain resistance"
configuration: DOWNSTREAM
resistor: 1000
reference_voltage: 3.3V
internal: true
icon: "mdi:omega"
filters:
- lambda: 'return max((float)$min_resistance, x);'
- lambda: 'return min((float)$max_resistance, x);'
on_value:
then:
- if:
condition:
lambda: |-
return (
id(real_resistance_sensor).state > $min_resistance
&&
id(real_resistance_sensor).state <= $max_resistance
);
then:
- sensor.template.publish:
id: resistance_sensor
state: !lambda 'return id(real_resistance_sensor).state;'
switch:
- platform: gpio
id: resistance_bias
name: "rain resistance bias"
icon: "mdi:power"
pin:
number: GPIO19
mode: OUTPUT
mas quando tento instalar, recebo este erro:
INFO ESPHome 2024.3.2
INFO Reading configuration /config/esphome/rain-sensor.yaml...
Failed config
sensor.resistance: [source /config/esphome/rain-sensor.yaml:52]
platform: resistance
sensor: source_sensor
id: real_resistance_sensor
name: rain resistance
configuration: DOWNSTREAM
resistor: 1000
reference_voltage: 3.3V
internal: True
icon: mdi:omega
filters:
- lambda: return max((float)$min_resistance, x);
- lambda: return min((float)$max_resistance, x);
on_value:
then:
- if:
condition:
lambda: |-
return (
id(real_resistance_sensor).state > $min_resistance
&&
id(real_resistance_sensor).state <= $max_resistance
);
then:
-
Unable to find action with the name 'sensor.template.publish'.
sensor.template.publish:
id: resistance_sensor
state: !lambda |-
return id(real_resistance_sensor).state;
Eu tenho outro sensor instalado, mas pelo que percebi, este dura mais tempo.
Será que alguém me pode indicar o que estou a fazer de errado?