Skip to content

Instantly share code, notes, and snippets.

@jesserockz
Last active December 22, 2023 12:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jesserockz/f6573a3e4721903927de899b3019d668 to your computer and use it in GitHub Desktop.
Save jesserockz/f6573a3e4721903927de899b3019d668 to your computer and use it in GitHub Desktop.
ESPHome Ikea Kitchen Microwave
substitutions:
devicename: play_kitchen
friendly_name: Play Kitchen
ip: '10.5.5.222'
wifi_reboot_timeout: 0s
########### PINS #########
# 3.3V 5V
# GPIO15 GROUND
# dht # GPIO13 GPIO2 LED / buzzer
# B # GPIO12 GPIO0
# A # GPIO14 GPIO4 SDA 23017
# knob # GPIO16 GPIO5 SCL 23017
# # A0 GPIO3 RX
# RST GPIO1 TX
# 0x20
############## MCP23017 ###############
# 7S CLK # 8 7 door_reed
# 7S DIO # 9 6 red
# 10 5 green
# 11 4 blue
# 12 3
# 13 2
# 14 1
# 15 0
# 3.3V INTA
# GND INTB
# RST
# SCK A2 - GND
# SDA A1 - GND
# A0 - GND
############# ROTARY ############
# 5 3.3v
# B 4 blue
# GND # C 3 knob
# A 2 green
# 1 red
esphome:
name: $devicename
platform: ESP8266
board: esp01_1m
api:
services:
- service: set_frequency
variables:
frequency: float
then:
- output.esp8266_pwm.set_frequency:
id: buzzer
frequency: !lambda 'return frequency;'
- service: set_level
variables:
level: float
then:
- output.set_level:
id: buzzer
level: !lambda 'return level;'
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda 'return song_str;'
logger:
# level: VERBOSE
wifi:
use_address: $ip
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
reboot_timeout: $wifi_reboot_timeout
output_power: 20.5db
ap:
ssid: $devicename
password: '12345678'
captive_portal:
ota:
globals:
- id: current_mode
type: int
initial_value: '0'
- id: last_mode
type: int
initial_value: '0'
- id: opened
type: bool
initial_value: 'false'
output:
- platform: gpio
id: output_red
pin:
mcp23017: mcp23017_hub
number: 6
mode: OUTPUT
inverted: true
- platform: gpio
id: output_green
pin:
mcp23017: mcp23017_hub
number: 5
mode: OUTPUT
inverted: true
- platform: gpio
id: output_blue
pin:
mcp23017: mcp23017_hub
number: 4
mode: OUTPUT
inverted: true
- platform: esp8266_pwm
pin: GPIO2
id: buzzer
inverted: true
rtttl:
output: buzzer
light:
- platform: binary
id: light_red
name: "$friendly_name Red"
output: output_red
- platform: binary
id: light_green
name: "$friendly_name Green"
output: output_green
- platform: binary
id: light_blue
name: "$friendly_name Blue"
output: output_blue
- platform: fastled_clockless
id: light_rgb
name: "$friendly_name LED Strip"
chipset: WS2811
pin: GPIO15
num_leds: 8
rgb_order: GRB
default_transition_length: 0s
effects:
- random:
- addressable_rainbow:
- addressable_color_wipe:
- addressable_scan:
- addressable_twinkle:
- addressable_fireworks:
display:
platform: tm1637
id: tm1637_display
clk_pin:
mcp23017: mcp23017_hub
number: 8
dio_pin:
mcp23017: mcp23017_hub
number: 9
intensity: 1
update_interval: 500ms
lambda: |-
static int tick = 0;
static int endtick = 0;
static int openTick = 0;
tick++;
int mins = (int)id(encoder).state / 60;
int secs = (int)id(encoder).state % 60;
id(buzzer).set_level(0);
if(id(opened)) {
id(opened) = false;
openTick = tick;
}
switch(id(current_mode)) {
case 0:
if ((tick % 2) == 0)
it.strftime("%H.%M", id(homeassistant_time).now());
else
it.strftime("%H%M", id(homeassistant_time).now());
break;
case 1:
it.print("Open");
if (tick - openTick >= 120) {
id(current_mode) = 0;
id(microwave).update();
}
break;
case 2:
it.printf("%02d.%02d", mins, secs);
break;
case 3:
if(mins == 0 && secs == 0) {
id(current_mode) = 5;
id(microwave).update();
return;
}
if ((tick % 2) == 0) {
id(encoder).set_value(id(encoder).state - 1);
it.printf("%02d.%02d", mins, secs);
} else
it.printf("%02d%02d", mins, secs);
break;
case 4:
if ((tick % 2) == 0) {
it.printf("%02d.%02d", mins, secs);
id(light_blue).turn_on().perform();
} else {
id(light_blue).turn_off().perform();
it.print(" ");
}
break;
case 5: {
endtick++;
if (endtick % 2 == 0 && endtick <= 6) {
it.print(" ");
} else {
it.print("End");
if (endtick <= 6) {
id(buzzer).set_level(0.5);
}
}
if (endtick == 10) {
endtick = 0;
id(current_mode) = 0;
id(microwave).update();
}
break;
}
}
text_sensor:
- platform: template
id: microwave
name: "$friendly_name Microwave"
lambda: |-
id(light_red).turn_off().perform();
id(light_green).turn_off().perform();
id(light_blue).turn_off().perform();
id(light_rgb).turn_off().perform();
switch(id(current_mode)) {
case 0:
return {"standby"};
case 1: {
id(light_red).turn_on().perform();
auto call = id(light_rgb).turn_on();
call.set_rgb(1.0, 1.0, 1.0);
call.set_brightness(0.5);
call.perform();
return {"open"};
}
case 2:
return {"starting"};
case 3: {
id(light_blue).turn_on().perform();
auto call = id(light_rgb).turn_on();
call.set_rgb(1.0, 1.0, 1.0);
call.set_brightness(0.5);
call.perform();
return {"running"};
}
case 4:
return {"paused"};
case 5:
id(light_green).turn_on().perform();
return {"finished"};
default:
return {};
}
sensor:
- platform: rotary_encoder
id: encoder
name: "$friendly_name Timer"
unit_of_measurement: 'seconds'
icon: 'mdi:clock'
pin_a:
number: GPIO14
mode: INPUT_PULLUP
pin_b:
number: GPIO12
mode: INPUT_PULLUP
max_value: 5999
min_value: 0
on_value:
then:
- lambda: |-
switch(id(current_mode)) {
case 0:
id(current_mode) = 2;
id(microwave).update();
}
- platform: dht
pin: GPIO13
model: DHT11
temperature:
name: "$friendly_name Temperature"
filters:
- median:
window_size: 5
send_every: 3
send_first_at: 2
humidity:
name: "$friendly_name Humidity"
update_interval: 10s
- platform: wifi_signal
name: "$friendly_name WiFi Signal"
update_interval: 60s
- platform: uptime
name: "$friendly_name Uptime"
# - platform: adc
# pin: A0
# name: "$friendly_name Brightness"
# update_interval: 60s
# unit_of_measurement: lx
# filters:
# - lambda: |-
# return (x / 10000.0) * 6000000.0;
i2c:
sda: GPIO4
scl: GPIO5
scan: False
frequency: 100kHz
mcp23017:
- id: 'mcp23017_hub'
address: 0x20
binary_sensor:
- platform: gpio
pin:
number: GPIO16
mode: INPUT_PULLDOWN_16
id: knob_click
on_release:
then:
- lambda: |-
ESP_LOGD("switch", "before_mode %d", id(current_mode));
switch(id(current_mode)) {
case 0:
id(current_mode) = 2;
break;
case 2:
if(id(encoder).state == 0) {
id(current_mode) = 0;
} else {
id(current_mode) = 3;
}
break;
case 3:
id(current_mode) = 4;
break;
case 4:
id(current_mode) = 3;
break;
case 5:
id(current_mode) = 0;
break;
}
ESP_LOGD("switch", "after_mode %d", id(current_mode));
id(microwave).update();
- platform: gpio
pin:
mcp23017: mcp23017_hub
number: 7
mode: INPUT_PULLUP
id: door_reed
on_press:
then:
- lambda: |-
id(last_mode) = id(current_mode);
id(current_mode) = 1;
id(opened) = true;
id(microwave).update();
on_release:
then:
- lambda: |-
switch (id(last_mode)) {
case 3:
id(current_mode) = 4;
break;
case 5:
id(current_mode) = 0;
id(last_mode) = 0;
break;
default:
id(current_mode) = id(last_mode);
break;
}
id(microwave).update();
switch:
- platform: restart
name: "Reboot $friendly_name"
- platform: output
name: "$friendly_name Buzzer"
output: buzzer
time:
- platform: homeassistant
id: homeassistant_time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment