Been playing around with ESPHome to get some door and window sensors. is there a preferred location for creating the template sensors (either in ESPHome or as automations in HA)? Just as a reference, i started down the path of doing them in ESPHome, but wondering if there is a better/easier way since I have dozens of these. here is the config in ESPHome for the first 5 I created:
# Basic Config
esphome:
name: sonoff-bridge
#to helo with disconnects
on_loop:
then:
- lambda: delay(5);
on_boot:
then:
- lambda: !lambda |-
if (id(window_dining_room_e_l).state) {
id(window_dining_room_e_l).publish_state(true);
} else {
id(window_dining_room_e_l).publish_state(false);
}
if (id(window_dining_room_e_r).state) {
id(window_dining_room_e_r).publish_state(true);
} else {
id(window_dining_room_e_r).publish_state(false);
}
if (id(window_living_room_e_l).state) {
id(window_living_room_e_l).publish_state(true);
} else {
id(window_living_room_e_l).publish_state(false);
}
if (id(window_living_room_e_r).state) {
id(window_living_room_e_r).publish_state(true);
} else {
id(window_living_room_e_r).publish_state(false);
}
if (id(door_living_room).state) {
id(door_living_room).publish_state(true);
} else {
id(door_living_room).publish_state(false);
}
esp8266:
board: esp01_1m
uart:
tx_pin: 1
rx_pin: 3
baud_rate: 19200
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: redacted
gateway: redacted
subnet: 255.255.255.0
dns1: redacted
power_save_mode: none
fast_connect: true
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Sonoff-Bridge Fallback Hotspot"
password: "password"
ota:
password: "password"
captive_portal:
web_server:
port: 80
# Enable logging
logger:
level: DEBUG
baud_rate: 0
# Enable Home Assistant API
api:
services:
- service: send_rf_code
variables:
sync: int
low: int
high: int
code: int
then:
- rf_bridge.send_code:
sync: !lambda 'return sync;'0x373C
low: !lambda 'return low;'0x01E00x0564
high: !lambda 'return high;'
code: !lambda 'return code;'
- service: learn
then:0x14A10A
- rf_bridge.learn
- service: advanced_learn_on
then:
- rf_bridge.start_advanced_sniffing
- service: advanced_learn_off
then:
- rf_bridge.stop_advanced_sniffing
- service: bucket_learn_on
then:
- rf_bridge.start_bucket_sniffing
rf_bridge:
on_code_received:
then:
- homeassistant.event:
event: esphome.rf_code_received
data:
sync: !lambda 'return format_hex(data.sync);'
low: !lambda 'return format_hex(data.low);'
high: !lambda 'return format_hex(data.high);'
code: !lambda 'return format_hex(data.code);'
#################################################
## Dining room windows EAST - Left and Right ##
## Left and Right as you face them from inside ##
#################################################
## Living Room Window EAST
- if:
# ON - Received RFBridge Code: sync=0x3799 low=0x0199 high=0x0599 code=0x17999A
condition:
lambda: |-
return data.code == 0x17999A;
then:
- binary_sensor.template.publish:
id: window_dining_room_e_l0x14A10E
state: ON
- if:
# OFF - Received RFBridge Code: sync=0x3788 low=0x0199 high=0x0599 code=0x17888E
condition:
lambda: |-
return data.code == 0x17888E;
then:
- binary_sensor.template.publish:
id: window_dining_room_e_l
state: OFF
- if:
# ON - Received RFBridge Code: sync=0x36C4 low=0x01EA high=0x0599 code=0x14777A
condition:
lambda: |-
return data.code == 0x14777A;
then:
- binary_sensor.template.publish:
id: window_dining_room_e_r
state: ON
- if:
# OFF - Received RFBridge Code: sync=0x3799 low=0x01EA high=0x0550 code=0x14666E
condition:
lambda: |-
return data.code == 0x14666E;
then:
- binary_sensor.template.publish:
id: window_dining_room_e_r
state: OFF
#################################################
## Living room windows EAST - Left and Right ##0xABBD0E
## Left and Right as you face them from inside ##
#################################################0xAF790A
- if:
# ON - Received RFBridge Code: sync=0x3799 low=0x0199 high=0x0599 code=0x17999A
condition:
lambda: |-
return data.code == 0x17999A;
then:
- binary_sensor.template.publish:
id: window_living_room_e_l
state: ON
- if:
# OFF - Received RFBridge Code: sync=0x3788 low=0x0199 high=0x0599 code=0x17888E
condition:
lambda: |-
return data.code == 0x17888E;
then:
- binary_sensor.template.publish:
id: window_living_room_e_l
state: OFF
- if:
# ON - Received RFBridge Code: sync=0x36EC low=0x01EA high=0x055A code=0xAB555A
condition:
lambda: |-
return data.code == 0xAB555A;
then:
- binary_sensor.template.publish:
id: window_living_room_e_r
state: ON
- if:
# OFF - Received RFBridge Code: sync=0x36EC low=0x01F4 high=0x0550 code=0xAB555E
condition:
lambda: |-
return data.code == 0xAB555E;
then:
- binary_sensor.template.publish:
id: window_living_room_e_r
state: OFF
########################################
## Living room door - Top Deck Door ##
########################################
- if:
# ON - Received RFBridge Code: sync=0x3799 low=0x01F4 high=0x055A code=0xAF444A
condition:
lambda: |-
return data.code == 0xAF444A;
then:
- binary_sensor.template.publish:
id: door_living_room
state: ON
- if:
# OFF - Received RFBridge Code: sync=0x3714 low=0x01EA high=0x055A code=0xAF444E
condition:
lambda: |-
return data.code == 0xAF444E;
then:
- binary_sensor.template.publish:
id: door_living_room
state: OFF
on_advanced_code_received:
then:
- homeassistant.event:
event: esphome.rf_advanced_code_received
data:
length: !lambda 'char buffer [10];return itoa(data.length,buffer,16);'
protocol: !lambda 'char buffer [10];return itoa(data.protocol,buffer,16);'
code: !lambda 'return data.code;'
# Device Specific Config
binary_sensor:
- platform: status
name: "RF Bridge Status"
# Dining room windows facing east
- platform: template
# ON - Received RFBridge Code: sync=0x3799 low=0x0199 high=0x0599 code=0x17999A
# OFF - Received RFBridge Code: sync=0x3788 low=0x0199 high=0x0599 code=0x17888E
name: "ESP Dining Room Window - East Left"
id: window_dining_room_e_l
device_class: window
- platform: template
# ON - Received RFBridge Code: sync=0x36C4 low=0x01EA high=0x0599 code=0x14777A
# OFF - Received RFBridge Code: sync=0x3799 low=0x01EA high=0x0550 code=0x14666E
name: "ESP Dining Room Window - East Right"
id: window_dining_room_e_r
device_class: window
# Living Room Windows facing east
- platform: template
# ON - Received RFBridge Code: sync=0x3799 low=0x0199 high=0x0599 code=0x17999A
# OFF - Received RFBridge Code: sync=0x3788 low=0x0199 high=0x0599 code=0x17888E
name: "ESP Living Room Window - East Left"
id: window_living_room_e_l
device_class: window
- platform: template
# ON - Received RFBridge Code: sync=0x36EC low=0x01EA high=0x055A code=0xAB555A
# OFF - Received RFBridge Code: sync=0x36EC low=0x01F4 high=0x0550 code=0xAB555E
name: "ESP Living Room Window - East Right"
id: window_living_room_e_r
device_class: window
# Living Room Door
- platform: template
# ON - Received RFBridge Code: sync=0x3799 low=0x01F4 high=0x055A code=0xAF444A
# OFF - Received RFBridge Code: sync=0x3714 low=0x01EA high=0x055A code=0xAF444E
name: "ESP Living Room Door"
id: door_living_room
device_class: door