Skip to content

Instantly share code, notes, and snippets.

@jvitkauskas
Created January 30, 2022 20:17
Show Gist options
  • Save jvitkauskas/95d7f8952f5ac69f926663039839b320 to your computer and use it in GitHub Desktop.
Save jvitkauskas/95d7f8952f5ac69f926663039839b320 to your computer and use it in GitHub Desktop.
substitutions:
name: esphome-web-0aad1c
# ylyk01yl bluetooth remote control
remote_mac: "A4:C1:38:00:00:00"
# ylkg07yl bluetooth wall switch/dimmer
wall_switch_mac: "F8:24:41:00:00:00"
# Use https://github.com/psylity/yeelight-dimmer-python to get it
wall_switch_bind_key: "87d4762922530d904a6d3e4f"
globals:
- id: color_temperature_preset
type: int
restore_value: no
initial_value: '0'
esphome:
name: ${name}
esp32:
board: esp32doit-devkit-v1
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ota:
api:
logger:
sensor:
- platform: adc
pin: GPIO35
name: "${name} power supply"
attenuation: 11db
output:
- platform: ledc
pin: GPIO19
id: output_warm
power_supply: power
# limit of the stock firmware (1.5V)
max_power: 0.50
- platform: ledc
pin: GPIO21
id: output_cold
power_supply: power
- platform: ledc
pin: GPIO23
id: output_nightlight
power_supply: power
power_supply:
- id: power
pin: GPIO22
enable_time: 0s
keep_on_time: 2s
light:
- platform: monochromatic
name: "${name} night light"
id: night_light
output: output_nightlight
gamma_correct: 0
on_turn_on:
- light.turn_off: ceiling_light
- platform: cwww
name: "${name} ceiling light"
id: ceiling_light
cold_white: output_cold
warm_white: output_warm
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K
constant_brightness: true
gamma_correct: 0
on_turn_on:
- light.turn_off: night_light
esp32_ble_tracker:
scan_parameters:
interval: 250ms
window: 250ms
duration: 1min
active: false
external_components:
- source: github://syssi/esphome-yeelight-ceiling-light@add-yeedimmer-ylkg07yl-support
refresh: 0s
xiaomi_ylyk01yl:
mac_address: "${remote_mac}"
last_button_pressed:
name: "last button pressed"
on_button_on:
then:
- light.turn_on: ceiling_light
on_button_off:
then:
- light.turn_off: ceiling_light
- light.turn_off: night_light
on_button_sun:
then:
if:
condition:
light.is_off: night_light
then:
- lambda: |-
id(color_temperature_preset) += 1;
if (id(color_temperature_preset) > 5) {
id(color_temperature_preset) = 0;
}
- light.turn_on:
id: ceiling_light
color_temperature: !lambda |-
switch (id(color_temperature_preset)) {
case 1: return 1000000.0 / 3000; break;
case 2: return 1000000.0 / 3500; break;
case 3: return 1000000.0 / 4200; break;
case 4: return 1000000.0 / 5000; break;
case 5: return 1000000.0 / 6500; break;
}
return 1000000.0 / 2700;
on_button_m:
then:
if:
condition:
light.is_on: night_light
then:
light.turn_on: ceiling_light
else:
light.turn_on: night_light
on_button_plus:
then:
- light.dim_relative:
id: ceiling_light
relative_brightness: +10%
transition_length: 0.1s
- delay: 0.1s
on_button_minus:
if:
condition:
lambda: |-
float brightness = 1;
id(ceiling_light).remote_values.as_brightness(&brightness);
return brightness >= 0.1;
then:
- light.dim_relative:
id: ceiling_light
relative_brightness: -10%
transition_length: 0.1s
- delay: 0.1s
else:
- light.turn_on:
id: ceiling_light
brightness: 1%
transition_length: 0.1s
- delay: 0.1s
xiaomi_ylkg07yl:
mac_address: "${wall_switch_mac}"
bindkey: "${wall_switch_bind_key}"
keycode:
name: "last keycode"
id: keycode
encoder_value:
name: "last encoder value"
id: encoder_value
action_type:
name: "last action type"
id: action_type
on_press:
then:
- light.toggle: ceiling_light
on_rotate:
- light.dim_relative:
id: ceiling_light
relative_brightness: !lambda |-
if (id(encoder_value).state <= 127) {
return +0.1;
} else {
return -0.1;
}
transition_length: 0.1s
- delay: 0.1s
on_press_and_rotate:
then:
- lambda: |-
if (id(keycode).state <= 127) {
id(color_temperature_preset) += 1;
} else {
id(color_temperature_preset) -= 1;
}
if (id(color_temperature_preset) < -1) {
id(color_temperature_preset) = -1;
}
if (id(color_temperature_preset) > 5) {
id(color_temperature_preset) = 5;
}
- if:
condition:
lambda: 'return id(color_temperature_preset) < 0;'
then:
light.turn_on:
id: night_light
else:
light.turn_on:
id: ceiling_light
color_temperature: !lambda |-
switch (id(color_temperature_preset)) {
case 1: return 1000000.0 / 3000; break;
case 2: return 1000000.0 / 3500; break;
case 3: return 1000000.0 / 4200; break;
case 4: return 1000000.0 / 5000; break;
case 5: return 1000000.0 / 6500; break;
}
return 1000000.0 / 2700;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment