Skip to content

Instantly share code, notes, and snippets.

@clydebarrow
Last active May 27, 2023 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clydebarrow/da53095b9e6d643b25a07a98b11b17ea to your computer and use it in GitHub Desktop.
Save clydebarrow/da53095b9e6d643b25a07a98b11b17ea to your computer and use it in GitHub Desktop.
Libretiny/ESPHome config for Deta 6922HA Series 2 smart dual outlet
# Note that the passwords etc. in this example are completely bogus.
substitutions:
name: "deta-6922ha-01"
friendly_name: "Dual outlet"
project_name: "DETA.6922HA"
project_version: "1.0"
device_description: "Indoor 2 gang outlet"
esphome:
name: "${name}"
comment: "${device_description}"
project:
name: "${project_name}"
version: "${project_version}"
libretiny:
board: wb3s
framework:
version: dev
# Enable logging
logger:
wifi:
ssid: "YourWiFiHere"
password: "makeUpYourOwn"
# Enable fallback hotspot in case wifi connection fails
ap:
ssid: "Fallback Hotspot"
password: "thisIsNotMine"
# Enable Home Assistant API
api:
encryption:
key: "3G75RRso25WauylmKAP4jVn+SATtafIvwkeOtATcxro="
ota:
password: "Outlet"
captive_portal:
sensor:
- platform: wifi_signal
name: "${friendly_name} wifi signal"
update_interval: 600s
- platform: uptime
name: Uptime Sensor
id: uptime_sensor
update_interval: 60s
disabled_by_default: true
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).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 ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
status_led:
pin:
number: GPIO9
inverted: True
switch:
# left socket relay
- platform: gpio
pin: GPIO6
id: relay1
# Right relay
- platform: gpio
pin: GPIO26
id: relay2
- platform: template
name: "${friendly_name} Left Socket"
id: relay_template1
lambda: |-
if (id(relay1).state) {
return true;
} else {
return false;
}
turn_on_action:
- switch.turn_on: relay1
turn_off_action:
- switch.turn_off: relay1
- platform: template
name: "${friendly_name} Right Socket"
id: relay_template2
lambda: |-
if (id(relay2).state) {
return true;
} else {
return false;
}
turn_on_action:
- switch.turn_on: relay2
turn_off_action:
- switch.turn_off: relay2
binary_sensor:
- platform: gpio
pin:
number: GPIO14
mode: INPUT
inverted: True
id: button1
name: "${friendly_name} Left Button"
on_click:
- min_length: 300ms
max_length: 1000ms
then:
- switch.toggle: relay_template1
internal: True
- platform: gpio
pin:
number: GPIO24
mode: INPUT
inverted: True
id: button2
name: "${friendly_name} Right Button"
on_click:
- min_length: 300ms
max_length: 1000ms
then:
- switch.toggle: relay_template2
internal: True
button:
- platform: restart
id: restart_button
name: "${friendly_name} Restart"
disabled_by_default: true
text_sensor:
- platform: wifi_info
ip_address:
name: "${friendly_name} IP Address"
disabled_by_default: true
bssid:
name: "${friendly_name} BSSID"
disabled_by_default: true
- platform: template
name: Uptime
id: uptime_human
icon: mdi:clock-start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment