Created
August 27, 2020 07:38
-
-
Save rlowens/314522dd0a41739c50e5781e204a1930 to your computer and use it in GitHub Desktop.
NodeMCU base configuration for ESPHome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
substitutions: | |
device_name: node1 | |
device_description: NodeMCU dev board, 15x2 pins with 2 LEDs and 2 buttons. Change this line to talk about what your board is for/where it is located. | |
friendly_name: Node 1 | |
esphome: | |
name: ${device_name} | |
comment: ${device_description} | |
platform: ESP8266 | |
board: nodemcuv2 | |
wifi: | |
ssid: !secret wifissid #define these in a secrets.yaml in your esphome folder, or in your main HA config folder and have a secrets.yaml in esphome that loads that with just "<<: !include ../secrets.yaml" | |
password: !secret wifipass | |
fast_connect: on #we only have one WiFi AP so just use the first one that matches | |
ap: #since we listed an SSID above, this AP mode will only enable if no WiFi connection could be made | |
ssid: ${friendly_name}_AP | |
password: !secret wifipass | |
# Enable Captive Portal on the AP mode, to make it easy to change the wifi settings if they fail | |
captive_portal: | |
# Enable logging | |
logger: | |
baud_rate: 0 #disable UART logging since we aren't monitoring GPIO1 TX. Remove this line if you want to view the log by connecting the USB to a computer and viewing the COM port with Termite or Teraterm or similar. | |
# Enable Home Assistant API | |
api: | |
# Enable OTA updates | |
ota: | |
# Enable web server | |
web_server: | |
port: 80 | |
# Individual on/off sensors | |
binary_sensor: | |
# Reports when the button is pressed | |
- platform: gpio | |
pin: | |
number: D3 #"Flash" button on GPIO0 | |
mode: INPUT_PULLUP | |
inverted: True | |
name: ${friendly_name} Flash Button | |
on_press: | |
- light.toggle: led_d0 | |
- light.toggle: led_d4 | |
# Reports if this device is Connected or not | |
- platform: status | |
name: ${friendly_name} Status | |
# Individual data sensors | |
sensor: | |
# Reports the WiFi signal strength/RSSI in dB, see https://esphome.io/components/sensor/wifi_signal.html | |
- platform: wifi_signal | |
name: ${friendly_name} Signal | |
update_interval: 60s | |
# Reports the WiFi signal strength in % | |
- platform: wifi_signal | |
name: ${friendly_name} Signal Percent | |
update_interval: 60s | |
filters: | |
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); | |
unit_of_measurement: "Signal %" | |
# Reports how long the device has been powered (in minutes) | |
- platform: uptime | |
name: ${friendly_name} Uptime | |
filters: | |
- lambda: return x / 60.0; | |
unit_of_measurement: minutes | |
# Individual text sensors | |
text_sensor: | |
# Reports the ESPHome Version with compile date | |
- platform: version | |
name: ${friendly_name} ESPHome Version | |
# Output pins | |
output: | |
- platform: esp8266_pwm | |
id: led_d0_output | |
pin: D0 #blue LED inverted on NodeMCU | |
inverted: True | |
- platform: esp8266_pwm | |
id: led_d4_output | |
pin: D4 #blue LED inverted on ESP-12E module itself | |
inverted: True | |
# Light devices | |
light: | |
# blue LED inverted on NodeMCU | |
- platform: monochromatic | |
name: ${friendly_name} Blue LED D0 | |
output: led_d0_output | |
id: led_d0 | |
effects: | |
- strobe: | |
- flicker: | |
alpha: 50% #The percentage that the last color value should affect the light. More or less the “forget-factor” of an exponential moving average. Defaults to 95%. | |
intensity: 50% #The intensity of the flickering, basically the maximum amplitude of the random offsets. Defaults to 1.5%. | |
- lambda: | |
name: Throb | |
update_interval: 1s | |
lambda: |- | |
static int state = 0; | |
auto call = id(led_d0).turn_on(); | |
// Transtion of 1000ms = 1s | |
call.set_transition_length(1000); | |
if (state == 0) { | |
call.set_brightness(1.0); | |
} else { | |
call.set_brightness(0.01); | |
} | |
call.perform(); | |
state += 1; | |
if (state == 2) | |
state = 0; | |
# blue LED inverted on ESP-12E module itself | |
- platform: monochromatic | |
name: ${friendly_name} Blue LED D4 | |
output: led_d4_output | |
id: led_d4 | |
effects: | |
- strobe: | |
- flicker: | |
alpha: 50% #The percentage that the last color value should affect the light. More or less the “forget-factor” of an exponential moving average. Defaults to 95%. | |
intensity: 50% #The intensity of the flickering, basically the maximum amplitude of the random offsets. Defaults to 1.5%. | |
- lambda: | |
name: Throb | |
update_interval: 1s | |
lambda: |- | |
static int state = 0; | |
auto call = id(led_d4).turn_on(); | |
// Transtion of 1000ms = 1s | |
call.set_transition_length(1000); | |
if (state == 0) { | |
call.set_brightness(1.0); | |
} else { | |
call.set_brightness(0.01); | |
} | |
call.perform(); | |
state += 1; | |
if (state == 2) | |
state = 0; | |
# Blink a light if we aren't connected to WiFi. Could use https://esphome.io/components/status_led.html instead but then we couldn't use this light for other things as well. | |
interval: | |
- interval: 500ms | |
then: | |
- if: | |
condition: | |
not: | |
wifi.connected: | |
then: | |
- light.turn_on: | |
id: led_d4 | |
brightness: 100% | |
transition_length: 0s | |
- delay: 250ms | |
- light.turn_off: | |
id: led_d4 | |
transition_length: 250ms | |
#status_led: | |
# pin: | |
# number: D4 | |
# inverted: True | |
# id: led_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment