Last active
August 31, 2024 19:21
-
-
Save aver-ua/5d920a7b47565f5fd71a05f582b8ce9e to your computer and use it in GitHub Desktop.
ESPHome config for Sonoff Basic Relay + BME280 Sensor I2C
This file contains hidden or 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_description: "Sonoff Basic with BME280 Outdoor" | |
| device_name: "sonoff-sw1" | |
| esphome: | |
| name: ${device_name} | |
| comment: "${device_description}" | |
| friendly_name: Sonoff SW1 | |
| esp8266: | |
| board: esp8285 | |
| # Enable logging | |
| logger: | |
| # Enable Home Assistant API | |
| api: | |
| encryption: | |
| key: !secret api_encryption_key | |
| ota: | |
| platform: esphome | |
| 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-Sw1-Bme Fallback Hotspot" | |
| password: !secret ota_password | |
| captive_portal: | |
| text_sensor: | |
| # Uptime Human Readable | |
| - platform: template | |
| name: Uptime HR | |
| entity_category: "diagnostic" | |
| id: uptime_human | |
| icon: mdi:clock-start | |
| binary_sensor: | |
| - platform: gpio | |
| pin: | |
| number: GPIO0 | |
| mode: | |
| input: true | |
| pullup: true | |
| inverted: true | |
| name: "Button" | |
| on_press: | |
| - switch.toggle: relay | |
| switch: | |
| - platform: gpio | |
| name: "Relay" | |
| pin: GPIO12 | |
| id: relay | |
| status_led: | |
| pin: | |
| number: GPIO13 | |
| inverted: yes | |
| i2c: | |
| sda: GPIO3 | |
| scl: GPIO1 | |
| scan: True | |
| sensor: | |
| - platform: bme280_i2c | |
| temperature: | |
| name: "BME280 Temperature" | |
| id: bme280_temperature | |
| pressure: | |
| name: "BME280 Pressure" | |
| id: bme280_pressure | |
| humidity: | |
| name: "BME280 Relative Humidity" | |
| id: bme280_humidity | |
| address: 0x76 | |
| update_interval: 60s | |
| - platform: absolute_humidity | |
| name: "Absolute Humidity" | |
| temperature: bme280_temperature | |
| humidity: bme280_humidity | |
| - platform: template | |
| name: "Dew Point" | |
| lambda: |- | |
| return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/ | |
| (243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)- | |
| ((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state)))); | |
| unit_of_measurement: °C | |
| icon: 'mdi:thermometer-alert' | |
| # Uptime sensor. | |
| - platform: uptime | |
| name: "Uptime" | |
| entity_category: "diagnostic" | |
| update_interval: 300s | |
| id: esp_uptime | |
| 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(); | |
| # 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: "%" | |
| entity_category: "diagnostic" | |
| # 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