Moving from Blynk to ESPHOME

Hello,

I am new to Home Assistant and ESPHOME.

I have an ESP32 where I was running a firmware with Blynk and now I want to switch to ESPHOME, but I have a problem (my knowledge) to do the automation.

I have a cover where I want it to open or close according to the temperature, whether it’s day or night, or if it’s raining.

I’m using the following configuration:

esphome:
  name: roof
  platform: ESP32
  board: esp32dev

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: ""

wifi:
  ssid: ""
  password: ""
  power_save_mode: none

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ""
    password: ""

captive_portal:

web_server:
  port: 80
sun:
  latitude: -0000000°
  longitude: -00000000°
  #name: "Sun Roof"
  id: sun_sun_esphome

time:
  - platform: sntp
    id: sntp_time
    timezone: "America/Sao_Paulo"

sensor:
  - platform: dht
    pin: 25
    temperature:
      name: "Varanda Temp"
      id: varanda_temp
    humidity:
      name: "Varanda Umidade"
      id: varanda_umidade
    update_interval: 60s
     
  
  - platform: adc
    pin: 34
    name: "Sensor de Chuva"
    icon: "mdi:water-percent"
    id: sensor_chuva
    update_interval: never
    attenuation: 11db


text_sensor:
  - platform: sun
    name: Sun Next Sunrise
    type: sunrise
  - platform: sun
    name: Sun Next Sunset
    type: sunset

output:
  - platform: gpio
    pin: 26
    id: power_chuva

interval:
  - interval: 60s
    then:
      - output.turn_on: power_chuva
      - delay: 300ms
      - component.update: sensor_chuva
      - delay: 100ms
      - output.turn_off: power_chuva

binary_sensor:
  - platform: gpio
    name: "Sensor Aberto"
    pin: 36
    id: sensor_aberto
    on_press:
      - delay: 150ms
      #- switch.turn_off: rele_fechar
      - switch.turn_off: rele_abrir
      - switch.turn_off: rele_fonte

  - platform: gpio
    name: "Sensor Fechado"
    pin: 39
    id: sensor_fechado
    on_press:
      - delay: 150ms
      - switch.turn_off: rele_fechar
      #- switch.turn_off: rele_abrir
      - switch.turn_off: rele_fonte


  - platform: gpio
    id: open_button
    pin: 32
    on_press:
      # Enable manual mode
      - switch.turn_on: modo_manual
      - cover.open: roof_controller
    on_release:
      - cover.stop: roof_controller
  - platform: gpio
    id: close_button
    pin: 33
    on_press:
      # Enable manual mode
      - switch.turn_on: modo_manual
      - cover.close: roof_controller
    on_release:
      - cover.stop: roof_controller

  - platform: gpio
    id: manual_button
    pin: 35
    on_press:
      # Enable manual mode
      - switch.turn_on: modo_manual
    on_release:
      - switch.turn_off: modo_manual



switch:
  - platform: gpio
    name: "Rele Fechar"
    pin: 13
    id: rele_fechar

  - platform: gpio
    name: "Rele Abrir"
    pin: 14
    id: rele_abrir

  - platform: gpio
    name: "Rele Fonte"
    pin: 27
    inverted: true
    id: rele_fonte

  - platform: template
    name: "Modo Manual"
    id: modo_manual
    optimistic: true

cover:
  - platform: endstop
    name: "Cobertura"
    id: roof_controller
    open_action:
      # Enable manual mode
      #- switch.turn_on: modo_manual
      # Cancel any previous action
      - switch.turn_off: rele_fechar
      # Turn the OPEN switch on briefly
      - switch.turn_on: rele_fonte
      - delay: 150ms
      - switch.turn_on: rele_abrir
    open_duration: 60s
    open_endstop: sensor_aberto
    close_action:
      # Enable manual mode
      #- switch.turn_on: modo_manual
      - switch.turn_off: rele_abrir
      - switch.turn_on: rele_fonte
      - delay: 150ms
      - switch.turn_on: rele_fechar
    close_duration: 72s
    close_endstop: sensor_fechado
    stop_action:
      # Enable manual mode
      #- switch.turn_on: modo_manual
      - switch.turn_off: rele_fechar
      - switch.turn_off: rele_abrir
      - switch.turn_off: rele_fonte
    max_duration: 75s
    #optimistic: true
    #assumed_state: true
    #has_position: true

And I want to add the following logic for automation, but since I have multiple triggers I have no idea how to do it.

if (id(modo_manual).state) {
} else {
  
if (id(sensor_chuva).state == 3.90 for more then 5 minutes) {
    cover.open: roof_controller

} else if ((id(sun_sun_esphome).state == sun.is_above_horizon ) and (id(varanda_temp).state > 20 )){
    cover.open: roof_controller
  
} else if ((id(sun_sun_esphome).state == sun.is_below_horizon ) and (id(varanda_temp).state > 24 )){
      cover.open: roof_controller
  
  } else {
      cover.close: roof_controller

  } 
  
}

Can anyone help me?

Thanks

1 Like