Skip to content

Instantly share code, notes, and snippets.

@randybb
Created October 29, 2023 15:52
Show Gist options
  • Save randybb/87eadf7cb74af2ca26d215e58833cc51 to your computer and use it in GitHub Desktop.
Save randybb/87eadf7cb74af2ca26d215e58833cc51 to your computer and use it in GitHub Desktop.
gate
substitutions:
device: car1
name: CAR1
comment: "car1"
esphome:
name: mcu-${device}
comment: ${comment}
on_loop:
then:
lambda: |-
static uint32_t last_state = 0;
auto state = App.get_app_state();
if (state != last_state) {
if (state & STATUS_LED_ERROR) {
auto call = id(led).turn_on();
call.set_effect("ERROR");
call.perform();
} else if (state & STATUS_LED_WARNING) {
auto call = id(led).turn_on();
call.set_effect("BOOT");
call.perform();
} else {
//auto call = id(led).turn_off();
//call.perform();
auto call = id(led).turn_on();
call.set_effect("BEACON");
call.perform();
}
last_state = state;
}
esp32:
board: m5stack-atom
framework:
type: esp-idf
external_components:
- source: components
packages:
common: !include common/logger.yaml
# PINOUTS: M5ATOM
# IR G12
# NEO G27
# BUTTON G39
# I2C0 SDA G26
# I2C0 SCL G32
# I2C1 SDA G25
# I2C1 SCL G21
# UART0 RX G3
# UART0 TX G1
# UART1 RX G23
# UART1 TX G33
# 1-WIRE G22
# NC G19
esp32_ble_beacon:
type: iBeacon
uuid: 'CAR_1_UUID'
major: 36246
minor: 1
light:
- platform: esp32_rmt_led_strip
name: "${name} LED"
id: led
rgb_order: GRB
pin: 27
num_leds: 1
rmt_channel: 0
chipset: ws2812
restore_mode: ALWAYS_OFF
effects:
- strobe:
name: "BEACON"
colors:
- state: true
red: 0%
green: 0%
blue: 50%
duration: 200ms
- state: false
duration: 200ms
- state: true
red: 0%
green: 0%
blue: 50%
duration: 200ms
- state: false
duration: 10s
- lambda:
name: "ERROR"
update_interval: 0.5s
lambda: |-
static bool state = false;
auto call = id(led).turn_on();
call.set_transition_length(500);
call.set_rgb(1, 0, 0);
if (!state) {
call.set_brightness(1);
} else {
// If using 0, it freaks Home Assistant UI.
call.set_brightness(0.01);
}
call.perform();
state = !state;
- lambda:
name: "BOOT"
update_interval: 0.5s
lambda: |-
static bool state = false;
auto call = id(led).turn_on();
call.set_transition_length(500);
call.set_rgb(0, 1, 0);
if (!state) {
call.set_brightness(1);
} else {
// If using 0, it freaks Home Assistant UI.
call.set_brightness(0.01);
}
call.perform();
state = !state;
substitutions:
device: gate
name: Gate
comment: "Outside: Gate"
esphome:
name: mcu-${device}
comment: ${comment}
esp32:
board: m5stack-atom
framework:
type: esp-idf
version: recommended
external_components:
- source: components
packages:
common: !include common/common.yaml
# PINOUTS: M5ATOM
# IR G12
# NEO G27
# BUTTON G39
# I2C0 SDA G26
# I2C0 SCL G32
# I2C1 SDA G25
# I2C1 SCL G21
# UART0 RX G3
# UART0 TX G1
# RS485 RX G33
# RS485 TX G23
# RELAY-1 G22
# RELAY-2 G19
button:
- platform: output
name: "${name} Open"
id: gate_open
output: relay_1
duration: 200ms
- platform: output
name: "${name} Close"
id: gate_close
output: relay_2
duration: 200ms
output:
- platform: gpio
pin: 22
id: relay_1
- platform: gpio
pin: 19
id: relay_2
switch:
- platform: template
name: "${name} Open"
turn_on_action:
- button.press: gate_open
- platform: template
name: "${name} Close"
turn_on_action:
- button.press: gate_close
- platform: template
name: "${name} Auto Open"
id: auto_open
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
- platform: template
name: "${name} Auto Close"
id: auto_close
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
- platform: template
name: "${name} Enable CAR1"
id: enable_car1
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
- platform: template
name: "${name} Enable CAR2"
id: enable_car2
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
- platform: template
name: "${name} Enable CAR3"
id: enable_car3
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
- platform: template
name: "${name} Enable CAR4"
id: enable_car4
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
# Bluetooth related stuff
esp32_ble_tracker:
scan_parameters:
duration: 1min
# bluetooth_proxy:
binary_sensor:
- platform: ble_presence
id: ibeacon_car1
ibeacon_uuid: 'CAR_1_UUID'
name: "Vehicle iBeacon CAR1"
on_press:
- if:
condition:
and:
- switch.is_on: enable_car1
- switch.is_on: auto_open
- binary_sensor.is_off: ibeacon_car2
- binary_sensor.is_off: ibeacon_car3
- binary_sensor.is_off: ibeacon_car4
then:
- button.press: gate_open
on_release:
- if:
condition:
and:
- switch.is_on: enable_car1
- switch.is_on: auto_close
- binary_sensor.is_off: ibeacon_car2
- binary_sensor.is_off: ibeacon_car3
- binary_sensor.is_off: ibeacon_car4
then:
- button.press: gate_close
- platform: ble_presence
id: ibeacon_car2
ibeacon_uuid: 'CAR_2_UUID'
name: "Vehicle iBeacon CAR2"
on_press:
- if:
condition:
and:
- switch.is_on: enable_car2
- switch.is_on: auto_open
- binary_sensor.is_off: ibeacon_car1
- binary_sensor.is_off: ibeacon_car3
- binary_sensor.is_off: ibeacon_car4
then:
- button.press: gate_open
on_release:
- if:
condition:
and:
- switch.is_on: enable_car2
- switch.is_on: auto_close
- binary_sensor.is_off: ibeacon_car1
- binary_sensor.is_off: ibeacon_car3
- binary_sensor.is_off: ibeacon_car4
then:
- button.press: gate_close
- platform: ble_presence
id: ibeacon_car3
ibeacon_uuid: 'CAR_3_UUID'
name: "Vehicle iBeacon CAR3"
on_press:
- if:
condition:
and:
- switch.is_on: enable_car3
- switch.is_on: auto_open
- binary_sensor.is_off: ibeacon_car1
- binary_sensor.is_off: ibeacon_car2
- binary_sensor.is_off: ibeacon_car4
then:
- button.press: gate_open
on_release:
- if:
condition:
and:
- switch.is_on: enable_car3
- switch.is_on: auto_close
- binary_sensor.is_off: ibeacon_car1
- binary_sensor.is_off: ibeacon_car2
- binary_sensor.is_off: ibeacon_car4
then:
- button.press: gate_close
- platform: ble_presence
id: ibeacon_car4
ibeacon_uuid: 'CAR_4_UUID'
name: "Vehicle iBeacon CAR4"
on_press:
- if:
condition:
and:
- switch.is_on: enable_car4
- switch.is_on: auto_open
- binary_sensor.is_off: ibeacon_car1
- binary_sensor.is_off: ibeacon_car2
- binary_sensor.is_off: ibeacon_car3
then:
- button.press: gate_open
on_release:
- if:
condition:
and:
- switch.is_on: enable_car4
- switch.is_on: auto_close
- binary_sensor.is_off: ibeacon_car1
- binary_sensor.is_off: ibeacon_car2
- binary_sensor.is_off: ibeacon_car3
then:
- button.press: gate_close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment