Rain sensor [Help]

Hi,

I’m trying to create a simple rain detection sensor that basically acts as a switch to help home assistant decide whether it should skip spraying my garden with dipel on a rainy day as it will likely wash off.

I’m simplifying the project found here

I have a pcb with traces on it connected to a weemos d1 mini with a reference resistor. I’m trying to convert the resistance to a simple on (wet) or off (dry) message but get the following compile error " Unable to find action with the name ‘sensor.template.publish’. sensor.template.publish: [source /config/esphome/rain-sensor.yaml:57] id: real_resistance_sensor state: !lambda |- return ON; "

I’ve had it working previously but had to rewrite the code from scratch and cant figure out what I’m doing wrong. As far as i could read in the docs sensor.template.publish action still exists?

**Any help would be appreciated

Below is my code

esphome:
  name: rain-sensor

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rain-Sensor Fallback Hotspot"
    password: !secret ap_password

captive_portal:

switch:
  - platform: gpio
    pin: D0
    name: "Rain sensor powerr"

sensor:
  - platform: adc
    id: source_sensor
    pin: A0
  - platform: resistance
    icon: "mdi:omega"
    internal: true
    sensor: source_sensor
    configuration: DOWNSTREAM
    resistor: 5.1kOhm
    reference_voltage: 3.3
    name: "${friendly_name} rain"
    id: real_resistance_sensor
    on_value:
    then:
      - if:
        condition:
        lambda: |-
        return (
        id(real_resistance_sensor).state > 100
       );
       then:
        - sensor.template.publish:
          id: real_resistance_sensor
          state: !lambda 'return ON;'

    

Could you please post your code properly, at the moment I see a backtick ` at the start of each line.

Hi, sorry about that. I tried asking to reddit also and had no luck, didn’t pickup on the different formatting. Should be fixed. Lost the original code again, so had to quickly correct it again

Just add an internal dummy template sensor, so the right files and libs are included in the build process.

binary_sensor:
  - platform: template
    name: "dummy"

Something like this?

Yes and I would add

    internal: true

to avoid exposing the dummy sensor to HA.

thank you for taking the time to help me. Ill give that a go and report back