substitutions:
devicename: qia-smart-switch
friendly_name: QIA Smart switch
esphome:
name: ${devicename}
bk72xx:
board: generic-bk7231n-qfn32-tuya
ota:
- platform: esphome
wifi:
ap:
logger:
api:
captive_portal:
time:
- platform: homeassistant
id: homeassistant_time
webserver:
sensor:
- platform: uptime
name: Uptime Sensor
id: uptime_sensor
update_interval: 60s
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();
light:
- platform: status_led
name: "led"
internal: true
id: led
pin:
number: P10
inverted: true
binary_sensor:
- platform: status
name: ${friendly_name} status
- platform: gpio
pin:
number: P7
mode: INPUT_PULLUP
inverted: true
name: ${friendly_name} button
internal: true
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_press:
- switch.toggle: relay
switch:
- platform: gpio
id: relay
name: ${friendly_name} relay
pin: P8
icon: mdi:electric-switch
on_turn_on:
- light.turn_on: led
on_turn_off:
- light.turn_off: led
button:
- platform: restart
id: restart_button
name: ${friendly_name} restart
entity_category: diagnostic