summaryrefslogtreecommitdiffstats
path: root/esphome/config/couchlight.yaml
blob: 1cdf58295a6e0c865129eb5193046108facd4c28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
esphome:
  name: couchlight
  on_boot:
    then:
      - lock.template.publish:
          id: child_lock
          state: UNLOCKED

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_encryption_key

# OTA
ota:
  - platform: esphome
    password: !secret ota_password

# WiFi Credentials
wifi:
  domain: .lan
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Couchlight Fallback Hotspot"
    password: !secret wifi_ap_password

captive_portal:

light:
  - id: light1
    platform: binary
    name: "Couch 1"
    output: relay_light1

  - id: light2
    platform: binary
    name: "Couch 2"
    output: relay_light2

output:
  - id: relay_light1
    platform: gpio
    pin: D1

  - id: relay_light2
    platform: gpio
    pin: D2

script:
  - id: reset_child_lock
    mode: restart
    then:
      - delay: 30min
      - lock.template.publish:
          id: child_lock
          state: UNLOCKED

binary_sensor:
  - id: button_light1
    name: "Couch 1 PushButton"
    platform: gpio
    pin:
      number: D7
      mode: INPUT_PULLUP
    filters:
      - invert
      - delayed_on: 50ms
    on_press:
      then:
        - if:
            condition:
              lock.is_unlocked: child_lock
            then:
              - light.toggle: light1
    internal: true # hide from UI

  - id: button_light2
    name: "Couch 2 PushButton"
    platform: gpio
    pin:
      number: D6
      mode: INPUT_PULLUP
    filters:
      - invert
      - delayed_on: 50ms
    on_press:
      then:
        - if:
            condition:
              lock.is_unlocked: child_lock
            then:
              - light.toggle: light2
    internal: true # hide from UI

lock:
  - id: child_lock
    platform: template
    name: "Child Lock"
    optimistic: true
    on_lock:
      - script.execute: reset_child_lock
    on_unlock:
      - script.stop: reset_child_lock