Created
October 26, 2023 01:42
-
-
Save kunaalm/6505546a957eae421154f6d455f244cf to your computer and use it in GitHub Desktop.
Homeassistant / ESPHome Smart Light Automation
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
| # WiFi credentials | |
| wifi: | |
| ssid: ${ssid} | |
| password: ${password} | |
| ap: | |
| ssid: ${devicename} | |
| password: ${password} | |
| manual_ip: | |
| static_ip: ${ipaddr} | |
| gateway: ${gateway} | |
| subnet: ${subnet} | |
| captive_portal: | |
| # Enable logging | |
| logger: | |
| # Enable Home Assistant API with encryption | |
| api: | |
| encryption: | |
| key: ${api_key} | |
| # Enable OTA updates | |
| ota: | |
| password: ${ota_password} | |
| safe_mode: True | |
| # Get time from Home Assistant | |
| time: | |
| - platform: homeassistant |
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
| esphome: | |
| name: ${devicename} | |
| friendly_name: ${friendlyname} | |
| on_boot: | |
| priority: -100 | |
| then: | |
| - lambda: |- | |
| id(soft_switch).publish_state(id(connected_lights).state); | |
| platform: ESP8266 | |
| board: esp01_1m | |
| switch: | |
| # Relay connected to GPIO05 | |
| - platform: gpio | |
| name: "Relay" | |
| pin: GPIO05 | |
| id: relay | |
| restore_mode: RESTORE_DEFAULT_ON | |
| internal: True | |
| # action when relay is on | |
| on_turn_on: | |
| - text_sensor.template.publish: | |
| id: relay_state | |
| state: "ON" | |
| # action when relay is off | |
| on_turn_off: | |
| - text_sensor.template.publish: | |
| id: relay_state | |
| state: "OFF" | |
| # Red led connected to GPIO12 | |
| - platform: gpio | |
| pin: GPIO12 | |
| id: red_led | |
| # Blue led connected to GPIO14 | |
| - platform: gpio | |
| pin: GPIO14 | |
| id: blue_led | |
| # Soft switch, toggles light (imported from HA) and leds | |
| - platform: template | |
| name: "Switch" | |
| id: soft_switch | |
| optimistic: true | |
| on_turn_on: | |
| - switch.turn_on: blue_led | |
| - switch.turn_off: red_led | |
| - homeassistant.service: | |
| service: light.turn_on | |
| data_template: | |
| entity_id: ${light_entity} | |
| on_turn_off: | |
| - switch.turn_on: red_led | |
| - switch.turn_off: blue_led | |
| - homeassistant.service: | |
| service: light.turn_off | |
| data_template: | |
| entity_id: ${light_entity} | |
| binary_sensor: | |
| # Button connected to GPIO03 | |
| - platform: gpio | |
| pin: | |
| number: GPIO03 | |
| mode: INPUT_PULLUP | |
| inverted: True | |
| id: button_input | |
| internal: True | |
| # Toggle soft switch when button is clicked | |
| on_click: | |
| min_length: 50ms | |
| max_length: 350ms | |
| then: | |
| - lambda: |- | |
| id(soft_switch).publish_state(!id(soft_switch).state); | |
| # Toggle relay when button is double clicked | |
| on_double_click: | |
| min_length: 300ms | |
| max_length: 500ms | |
| then: | |
| - switch.toggle: relay | |
| # Import light entity from Home Assistant | |
| - platform: homeassistant | |
| entity_id: ${light_entity} | |
| id: connected_lights | |
| on_state: | |
| then: | |
| - lambda: |- | |
| id(soft_switch).publish_state(id(connected_lights).state); | |
| text_sensor: | |
| # Expose relay state to Home Assistant | |
| - platform: template | |
| name: "Relay State" | |
| id: relay_state | |
| - platform: version | |
| name: ESPHome Version | |
| # Expose WiFi information as sensors. | |
| - platform: wifi_info | |
| ip_address: | |
| name: IP Address | |
| ssid: | |
| name: SSID | |
| bssid: | |
| name: BSSID | |
| mac_address: | |
| name: "MAC Address" | |
| # Sensors with general information. | |
| sensor: | |
| - platform: wifi_signal | |
| name: "WiFi Signal" | |
| update_interval: 60s | |
| - platform: uptime | |
| name: "Uptime" | |
| update_interval: 60s | |
| # Expose restart button to Home Assistant | |
| button: | |
| - platform: restart | |
| name: "Restart" | |
| id: restart_button | |
| entity_category: diagnostic |
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
| # Device Specific Configuration | |
| substitutions: | |
| # Common defines across all devices | |
| ssid: !secret wifi_ssid | |
| password: !secret wifi_password | |
| gateway: !secret gateway | |
| subnet: !secret subnet | |
| api_key: !secret api_encryption_key | |
| ota_password: !secret ota_password | |
| # Device specific defines | |
| devicename: swt-mjsp-familyroom-outlet | |
| friendlyname: "Switch: MJSP Familyroom Outlet" | |
| ipaddr: 192.168.x.x | |
| # Class specific defines | |
| light_entity: light.grp_familyroom_lights | |
| # Common Config | |
| <<: !include includes/base-config.yaml | |
| <<: !include includes/mj-us-ss01-smart-light.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment