Esphome lambda/automation code help

Hi,
I built a simple irrigation controller. I have a solar panel connected to a charge controller and a 12V battery. From the load part of the charge controller I reduced the voltage to 5V and that powers my Wemos S2 mini board with 2 relays controlling 2 solenoid valves.
That is all working great. I can manually switch on water in valve 1 and/or 2.
The device goes to sleep at night. The battery is big enough to keep the device running for a couple of days and it will only get better in the summer with longer days.

Now in Home Assistant I created a template driven sensor that looks at the weather forecast and if there was no rain in the last 24h the sensor has value ON otherwise it is OFF.

In ESPHome I read the sensor value using this yaml code:

  - platform: homeassistant
    id: zone1_irrigation
    name: Zone 1 Irrigation
    entity_id: sensor.zone1_irrigation

What I don’t know how do I now tell esphome that if sensor.zone1_irrigation is On to turn on Relay1?
Thanks

what I use to turn on an LED that lets me know that the irrigation pump is on… change the led to your relay

text_sensor:
  - platform: homeassistant
    name: Pump Status
    internal: False
    entity_id: switch.shelly_watertankpump
    on_value:
      then:
        lambda: |-
          if(x == "on") {
            auto call = id(pumpled).turn_on();
            call.perform();
          } else {
            auto call = id(pumpled).turn_off();
            call.perform();
          }
1 Like