Skip to content

Instantly share code, notes, and snippets.

@aver-ua
Created March 9, 2024 18:46
Show Gist options
  • Select an option

  • Save aver-ua/c8eb9f45ca7d2a91ba212d2da3de61d3 to your computer and use it in GitHub Desktop.

Select an option

Save aver-ua/c8eb9f45ca7d2a91ba212d2da3de61d3 to your computer and use it in GitHub Desktop.
ESPHome config for Sonoff B1 Lamp
esphome:
name: sonoff-b1-lamp
friendly_name: Sonoff-B1-Lamp
substitutions:
device_description: "Sonoff B1 LED Lamp"
device_name: "sonoff-b1-lamp"
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: !secret api_encryption_key
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Sonoff-B1-Lamp Fallback Hotspot"
password: !secret hotspot_password
captive_portal:
text_sensor:
# Uptime Human Readable
- platform: template
name: Uptime HR
id: uptime_human
icon: mdi:clock-start
my9231:
data_pin: GPIO12 # GPIO13 for AiLight
clock_pin: GPIO14 # GPIO15 for AiLight
num_channels: 6
num_chips: 2
bit_depth: 8
output:
- platform: my9231
id: output_blue
channel: 0
- platform: my9231
id: output_red
channel: 1
- platform: my9231
id: output_green
channel: 2
- platform: my9231
id: output_warm_white
channel: 4
- platform: my9231
id: output_cold_white
channel: 5
light:
- platform: rgbww
name: Light
red: output_red
green: output_green
blue: output_blue
cold_white: output_cold_white
warm_white: output_warm_white
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2800 K
sensor:
# WiFi Signal sensor.
- platform: wifi_signal
name: "WiFi Signal dB"
id: wifi_signal_db
entity_category: "diagnostic"
update_interval: 60s
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "Signal %"
entity_category: "diagnostic"
device_class: ""
# Uptime sensor.
- platform: uptime
id: esp_uptime
name: Uptime
entity_category: "diagnostic"
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(esp_uptime).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m " : "") +
(String(seconds) + "s")
).c_str();
# Enable Web server.
web_server:
port: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment