Since the ESP32R4 controller is based on the ESP32 microcontroller, ESPHome is used for connecting to Home Assistant. ESPHome firmware will allow you to integrate ESP32R4 controller with HASS or Node-Red, as well as configure the embedded automatization of the controller to work without external control

Getting Started with ESPHome and Home Assistant

In this guide, we’ll go through how to install ESPHome on an ESp32R4 controller using the ESPHome Dashboard, installed as a Home Assistant add-on.

If you do not have the ESPHome on your Home Assistant, you can install it with this instruction https://esphome.io/guides/getting_started_hassio.html

Have 2 ways to migrate from TASMOTA to ESPHome:

Basic functions of ESP32R4 controller:

  • WiFi setting.
  • LED status. Basic functions and WiFi, BLE, MQTT connecting status.
  • Buzzer. Initialization and play ringtones.
  • Relays – Outputs. GPIO settings.
  • Buttons – Inputs. Binary sensors. GPIO settings.
  • Automatization.
  • RF315/433MHz-receiver and 4 buttons KeyFob. Optional module. Initialization. sniffing RF codes. Automatization

WiFi

This core ESPHome component sets up WiFi connections to access points for you. You need to have a network configuration (either Wifi or Ethernet) or ESPHome will fail in the config validation stage. You also can’t have both Wifi and Ethernet setup in the same time (even if your ESP has both wired).

It’s recommended to provide a static IP for your node, as it can dramatically improve connection times.

! We recommended using the secrets of the WiFi credential in secrets.YAML (ESPhome folder)

YAML
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.110
    gateway: 192.168.1.1
    subnet: 255.255.255.0

Access Point Mode

ESPHome has an optional “Access Point Mode”. If you include AP: in your WiFi configuration, ESPHome will automatically set up an access point that you can connect to. Additionally, you can specify both a “normal” station mode and AP mode at the same time. This will cause ESPHome to only enable the access point when no connection to the WiFi router can be made.

YAML
wifi:
  ap:
    ssid: "ESP32R4-controller"
    password: "W1PBGyrokfLz"

More info: https://esphome.io/components/wifi.html#

Status LED

The status_led (LED with WiFi symbol on front panel) hooks into all ESPHome components and can indicate the status of the ASTRA device. Specifically, it will:

  • Stay ON. All functions and components work, WiFi/BLE/MATT is connected.
  • Blink slowly (about every second) when a warning is active. Warnings are active when for example reading a sensor value fails temporarily or the WiFi/MQTT connections are disrupted.
  • Blink quickly (multiple times per second) when an error is active. Errors indicate that ESPHome has found an error while setting up. In most cases, ESPHome will still try to recover from the error and continue with all other operations.
  • Stay OFF otherwise.

Note! When using this platform the high-level status_led component should not be included (at least over the same pin), as its functionality is directly provided by this platform. The only difference is that the platform won’t be loaded in OTA safe mode, while the component would be. If your device has a single LED that needs to be shared use status_led light platform instead

YAML
status_led:
  pin:
    number: GPIO4
    inverted: true

More info: https://esphome.io/components/status_led.html?highlight=led+status#

Buzzer

ESP32R4 controller have the sound-piezo Buzzer. To connect Buzzer to ESPHome, need to use the component Buzzer rtttl, with this component allows you to easily play monophonic songs (ringtones) or any sounds like an alarm. It accepts the Ring Tone Text Transfer Language, rtttl format (Wikipedia) which allows to the storage of simple melodies.

You can find many rtttl strings online on the web.

Also, you can try to use this (select one of the sounds that you like and add to rtttl string):

YAML
'The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6'
'Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6'
'TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5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p,f#,p,2e.,p,f#,e,4f#,e,f#,p,e,p,4d.,p,f#,4e,d,e,p,d,p,e,p,d,p,2c#.,p,d,c#,4d,c#,d,p,e,p,4f#,p,a,p,4b,a,b,p,a,p,b,p,2a.,4p,a,b,a,4b,a,b,p,2a.,a,4f#,a,b,p,d6,p,4e.6,d6,b,p,a,p,2b'
'StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6'
'GoodBad:d=4,o=5,b=56:32p,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,d#,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,c#6,32a#,32d#6,32a#,32d#6,8a#.,16f#.,32f.,32d#.,c#,32a#,32d#6,32a#,32d#6,8a#.,16g#.,d#'
'TopGun:d=4,o=4,b=31:32p,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,16f,d#,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,g#'
'A-Team:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#'
'Flinstones:d=4,o=5,b=40:32p,16f6,16a#,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,d6,16f6,16a#.,16a#6,32g6,16f6,16a#.,32f6,32f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,a#,16a6,16d.6,16a#6,32a6,32a6,32g6,32f#6,32a6,8g6,16g6,16c.6,32a6,32a6,32g6,32g6,32f6,32e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,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d'
'smbdeath:d=4,o=5,b=90:32c6,32c6,32c6,8p,16b,16f6,16p,16f6,16f.6,16e.6,16d6,16c6,16p,16e,16p,16c'
'Monty P:d=4,o=5,b=200:f6,8e6,d6,8c#6,c6,8b,a#,8a,8g,8a,8a#,a,8g,2c6,8p,8c6,8a,8p,8a,8a,8g#,8a,8f6,8p,8c6,8c6,8p,8a,8a#,8p,8a#,8a#,8p,8c6,2d6,8p,8a#,8g,8p,8g,8g,8f#,8g,8e6,8p,8d6,8d6,8p,8a#,8a,8p,8a,8a,8p,8a#,2c6,8p,8c6'
'Yaketysax:d=4,o=5,b=125:8d.,16e,8g,8g,16e,16d,16a4,16b4,16d,16b4,8e,16d,16b4,16a4,16b4,8a4,16a4,16a#4,16b4,16d,16e,16d,g,p,16d,16e,16d,8g,8g,16e,16d,16a4,16b4,16d,16b4,8e,16d,16b4,16a4,16b4,8d,16d,16d,16f#,16a,8f,d,p,16d,16e,16d,8g,16g,16g,8g,16g,16g,8g,8g,16e,8e.,8c,8c,8c,8c,16e,16g,16a,16g,16a#,8g,16a,16b,16a#,16b,16a,16b,8d6,16a,16b,16d6,8b,8g,8d,16e6,16b,16b,16d,8a,8g,g'
'YMCA:d=4,o=5,b=160:8c#6,8a#,2p,8a#,8g#,8f#,8g#,8a#,c#6,8a#,c#6,8d#6,8a#,2p,8a#,8g#,8f#,8g#,8a#,c#6,8a#,c#6,8d#6,8b,2p,8b,8a#,8g#,8a#,8b,d#6,8f#6,d#6,f.6,d#.6,c#.6,b.,a#,g#'
'BarbieGirl:d=4,o=5,b=125:8g#,8e,8g#,8c#6,a,p,8f#,8d#,8f#,8b,g#,8f#,8e,p,8e,8c#,f#,c#,p,8f#,8e,g#,f#'
'TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5'

Initialization:

YAML
output:
  - platform: ledc
    pin: GPIO12
    id: rtttl_out

rtttl:
  output: rtttl_out

Plays an rtttl tone:

YAML
on_...:
  then:
    - rtttl.play: ‘StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6’

For example, add a ringtone to the startup of the device:

YAML
on_boot:
  # buzzer on on startup
    priority: -100
    then:
      - rtttl.play: ‘StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6'

More info: https://esphome.io/components/rtttl.html?highlight=rtttl

RELAYS – Outputs – GPIO Switch. 

The GPIO switch component of the platform allows you to use any pin on your node as a switch. You can for example hook up a relay to a GPIO pin and use it through this platform.

YAML
switch:
  - platform: gpio
    name: "Relay 1"
    pin: 25
    id: relay1
  - platform: gpio
    name: "Relay 2"
    pin: 26
    id: relay2
  - platform: gpio
    name: "Relay 3"
    pin: 33
    id: relay3
  - platform: gpio
    name: "Relay 4"
    pin: 32
    id: relay4

Interlocking

In some cases, it is necessary to ensure that two outputs are never active at the same time. ESPHome has a feature to prevent two GPIO Switches from being active at the same time called interlocking. Just give each switch in the “interlocking group” an interlock option with a list of all the switches in the group.

YAML
# Example configuration entry
# Prevent relay #1 and relay #2 from being activated at the same time.
switch:
  - platform: gpio
    pin: GPIO25
    name: "Relay #1"
    id: relay1
    interlock: [relay2]

  - platform: gpio
    pin: GPIO26
    name: "Relay #2"
    id: relay2
    interlock: [relay1]

more info: https://esphome.io/components/switch/gpio.html

BUTTONS – Inputs. Binary Sensor. Switches, sensors.

With ESPHome you can use different types of binary sensors. They will automatically appear in the Home Assistant front-end and have several configuration options. The triggers for binary sensors in ESPHome can to use for embedded automatization or with Home Assistant global automatization. For example, a press is triggered in the first moment when the button on your mouse is pushed down.

YAML
binary_sensor:
  - platform: gpio
    name: "SWITCH 1"
    pin: 
      number: 34
      mode:
        input: true

  - platform: gpio
    name: "SWITCH 2"
    pin: 
      number: 35
      mode:
        input: true

  - platform: gpio
    name: "SWITCH 3"
    pin: 
      number: 36
      mode:
        input: true

  - platform: gpio
    name: "SWITCH 4"
    pin: 
      number: 39
      mode:
        input: true

More info: https://esphome.io/components/binary_sensor/index.html?highlight=binary_sensor#

RF315/433MHz receiver and KeyFob.

Pls follow this instruction: https://esp32r4.com/rf315-rf433mhz-keyfob-or-wall-switch-esphome-hass-settings-and-rf-communication/

Conclusion. Sample code.

YAML
esphome:
  name: esphome-web-6c749c
  on_boot:
  # buzzeron on startup
    priority: -100
    then:
      - rtttl.play: 'A-Team:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#'

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG

status_led:
  pin:
    number: GPIO4
    inverted: true

output:
  - platform: ledc
    pin: GPIO12
    id: rtttl_out

rtttl:
  output: rtttl_out

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.110
    gateway: 192.168.1.1
    subnet: 255.255.255.0
  ap:
    ssid: "Esphome-Web-6C749C"
    password: "bcakwljI9Skp"

captive_portal:

remote_receiver:
  pin: GPIO27
  dump: rc_switch
  # Settings to optimize recognition of RF devices
  tolerance: 50%
  filter: 50us
  idle: 4ms
  buffer_size: 2kb

switch:
  - platform: gpio
    name: "Relay 1"
    pin: 25
    id: relay1
  - platform: gpio
    name: "Relay 2"
    pin: 26
    id: relay2
  - platform: gpio
    name: "Relay 3"
    pin: 33
    id: relay3
  - platform: gpio
    name: "Relay 4"
    pin: 32
    id: relay4
    
binary_sensor:
  - platform: gpio
    name: "SWITCH 1"
    pin: 
      number: 34
      mode:
        input: true

  - platform: gpio
    name: "SWITCH 2"
    pin: 
      number: 35
      mode:
        input: true

  - platform: gpio
    name: "SWITCH 3"
    pin: 
      number: 36
      mode:
        input: true

  - platform: gpio
    name: "SWITCH 4"
    pin: 
      number: 39
      mode:
        input: true

  - platform: remote_receiver
    name: "Button A"
    device_class: motion
    rc_switch_raw:
      code: "011100100110101000001000"
      protocol: 1
    on_press:
      then:
        - switch.toggle: relay1

  - platform: remote_receiver
    name: "Button B"
    device_class: motion
    rc_switch_raw:
      code: "011100100110101000000100"
      protocol: 1
    on_press:
      then:
        - switch.toggle: relay2    

  - platform: remote_receiver
    name: "Button C"
    device_class: motion
    rc_switch_raw:
      code: "011100100110101000000010"
      protocol: 1
    on_press:
      then:
        - switch.toggle: relay3          

  - platform: remote_receiver
    name: "Button D"
    device_class: motion
    rc_switch_raw:
      code: "011100100110101000000001"
      protocol: 1
    on_press:
      then:
        - switch.toggle: relay4  

  - platform: remote_receiver
    name: "Button ALL ON"
    device_class: motion
    rc_switch_raw:
      code: "000001000111010100000001"
      protocol: 1
    on_press:
      then:
        - switch.turn_on: relay1
        - switch.turn_on: relay2        
        - switch.turn_on: relay3        
        - switch.turn_on: relay4                

  - platform: remote_receiver
    name: "Button ALL OFF"
    device_class: motion
    rc_switch_raw:
      code: "000001000111010100000010"
      protocol: 1
    on_press:
      then:
        - switch.turn_off: relay1
        - switch.turn_off: relay2        
        - switch.turn_off: relay3        
        - switch.turn_off: relay4

You should now be able to fully integrate Home Assistant and ESPHome with your ESP32R4 controller and use it for your projects or home automatization.

If you have any issues, let us know in the comments, and be sure to subscribe below for instant updates on new topics.