Created
November 7, 2021 11:34
-
-
Save jerkovicl/c390c53b62fad37ebd75b40a5b94e820 to your computer and use it in GitHub Desktop.
EspHome Config for Sonoff Mini
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: kitchen_sonoff_mini | |
device_friendly_name: Kitchen Sonoff Mini Switch | |
device_ip: 192.168.5.13 | |
light_id: light.kitchen_lights | |
button_gpio: GPIO00 | |
led_status_gpio: GPIO13 | |
relay_gpio: GPIO12 | |
esphome: | |
name: ${device_name} | |
platform: ESP8266 | |
board: esp01_1m # esp8285 | |
# Enable logging | |
logger: | |
# Enable Web server | |
web_server: | |
port: 80 | |
# Enable Home Assistant API | |
api: | |
# password: "!secret api_password" | |
# reboot_timeout: 15min / 0s | |
# Enable Over The Air update | |
ota: | |
# password: !secret ota_password | |
wifi: | |
ssid: !secret wifi_ssid | |
password: !secret wifi_password | |
#reboot_timeout: 0s # Disable reboots for when Home Assistant is offline for an extended time. | |
manual_ip: | |
static_ip: ${device_ip} | |
gateway: 192.168.5.1 | |
subnet: 255.255.255.0 | |
#domain: .localdomain | |
# Enable fallback hotspot (captive portal) in case wifi connection fails | |
ap: | |
ssid: "Kitchen-Sonoff-Mini" | |
password: !secret ap_password | |
captive_portal: | |
# the web_server & sensor components can be removed without affecting core functionaility. | |
#time: | |
# - platform: homeassistant | |
# id: homeassistant_time | |
sensor: | |
# Extra sensor to keep track of uptime | |
- platform: uptime | |
name: ${device_name} Uptime Sensor | |
filters: | |
- lambda: return x / 3600; | |
unit_of_measurement: "hours" | |
accuracy_decimals: 2 | |
# Extra sensor for WiFi signal | |
- platform: wifi_signal | |
name: ${device_name} Wifi Signal Strength | |
update_interval: 900s | |
####################################### | |
# Device specific Config Begins Below # | |
###################################### | |
binary_sensor: | |
# the lines below define the reset button | |
- platform: gpio | |
pin: $button_gpio | |
id: ${device_name}_button | |
internal: true | |
filters: | |
- invert: | |
- delayed_off: 10ms | |
on_press: | |
- switch.toggle: | |
id: relay_1 | |
# the lines below toggle the main relay on command | |
- platform: gpio | |
name: ${device_name}_status | |
pin: GPIO04 | |
id: switch_1 | |
on_state: | |
- script.execute: hass_light_toggle | |
#on_press: | |
# then: | |
# - switch.toggle: | |
# id: relay_1 | |
#on_release: | |
# then: | |
# - switch.toggle: | |
# id: relay_1 | |
switch: | |
- platform: gpio | |
name: ${device_friendly_name} | |
icon: "mdi: lightbulb_outline" | |
pin: $relay_gpio | |
id: relay_1 | |
restore_mode: restore_default_off #ALWAYS_ON | |
status_led: | |
pin: | |
number: $led_status_gpio | |
inverted: true | |
output: | |
- platform: esp8266_pwm | |
id: blue_led | |
pin: $led_status_gpio | |
inverted: true | |
light: | |
# the 4 lines below define the Blue LED light on Sonoff Mini, to expose in HomeAssistant remove line "internal: true" | |
- platform: monochromatic | |
name: ${device_name}_blueled | |
output: blue_led | |
internal: true # hides the Blue LED from HomeAssistant | |
script: | |
- id: hass_light_toggle | |
then: | |
if: | |
condition: | |
api.connected: | |
then: | |
- if: | |
condition: | |
switch.is_off: relay_1 | |
then: | |
# Turn the relay back on and turn on the light. | |
- switch.turn_on: relay_1 | |
- homeassistant.service: | |
service: light.turn_on | |
data: | |
entity_id: $light_id | |
else: | |
# Have Home Assistant toggle the light. | |
- homeassistant.service: | |
service: light.toggle | |
data: | |
entity_id: $light_id | |
else: | |
# When HA is unavailable, toggle the relay. | |
- switch.toggle: relay_1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment