diff options
| -rw-r--r-- | esphome/config/office-pc-control.yaml | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/esphome/config/office-pc-control.yaml b/esphome/config/office-pc-control.yaml new file mode 100644 index 0000000..1020dcf --- /dev/null +++ b/esphome/config/office-pc-control.yaml | |||
| @@ -0,0 +1,182 @@ | |||
| 1 | esphome: | ||
| 2 | name: office-pc-control | ||
| 3 | area: Office | ||
| 4 | on_boot: | ||
| 5 | priority: -100 | ||
| 6 | then: | ||
| 7 | - output.turn_off: pc_reset | ||
| 8 | - output.turn_off: pc_power_onoff | ||
| 9 | - light.control: | ||
| 10 | id: pc_rgb_led | ||
| 11 | brightness: 100% | ||
| 12 | red: 100% | ||
| 13 | green: 0% | ||
| 14 | blue: 0% | ||
| 15 | white: 0% | ||
| 16 | |||
| 17 | esp8266: | ||
| 18 | board: nodemcuv2 | ||
| 19 | |||
| 20 | # Enable logging | ||
| 21 | logger: | ||
| 22 | |||
| 23 | # Enable Home Assistant API | ||
| 24 | api: | ||
| 25 | encryption: | ||
| 26 | key: !secret api_encryption_key | ||
| 27 | |||
| 28 | # OTA | ||
| 29 | ota: | ||
| 30 | - platform: esphome | ||
| 31 | password: !secret ota_password | ||
| 32 | |||
| 33 | # WiFi Credentials | ||
| 34 | wifi: | ||
| 35 | domain: .lan | ||
| 36 | ssid: !secret wifi_ssid | ||
| 37 | password: !secret wifi_password | ||
| 38 | |||
| 39 | # Enable fallback hotspot (captive portal) in case wifi connection fails | ||
| 40 | ap: | ||
| 41 | ssid: "Couchlight Fallback Hotspot" | ||
| 42 | password: !secret wifi_ap_password | ||
| 43 | |||
| 44 | captive_portal: | ||
| 45 | |||
| 46 | output: | ||
| 47 | - platform: gpio | ||
| 48 | id: pc_reset | ||
| 49 | pin: | ||
| 50 | number: D2 | ||
| 51 | inverted: true # pc power/reset pins are GND activated | ||
| 52 | |||
| 53 | - platform: gpio | ||
| 54 | id: pc_power_onoff | ||
| 55 | pin: | ||
| 56 | number: D3 | ||
| 57 | inverted: true # pc power/reset pins are GND activated | ||
| 58 | |||
| 59 | button: | ||
| 60 | - platform: output | ||
| 61 | name: "Reset" | ||
| 62 | icon: "mdi:restore-alert" | ||
| 63 | output: pc_power_onoff | ||
| 64 | duration: 150ms | ||
| 65 | device_class: restart | ||
| 66 | |||
| 67 | - platform: output | ||
| 68 | name: "Power On/Off" | ||
| 69 | icon: "mdi:power" | ||
| 70 | output: pc_power_onoff | ||
| 71 | duration: 150ms | ||
| 72 | |||
| 73 | - platform: output | ||
| 74 | name: "Force Off" | ||
| 75 | icon: "mdi:power" | ||
| 76 | output: pc_power_onoff | ||
| 77 | duration: 5000ms | ||
| 78 | |||
| 79 | light: | ||
| 80 | - platform: neopixelbus | ||
| 81 | name: "RGB LED" | ||
| 82 | id: pc_rgb_led | ||
| 83 | type: GRBW | ||
| 84 | variant: WS2813 #800KBPS | ||
| 85 | num_leds: 16 | ||
| 86 | pin: D4 # GPIO2 | ||
| 87 | method: | ||
| 88 | type: esp8266_uart | ||
| 89 | bus: 1 | ||
| 90 | default_transition_length: 300ms | ||
| 91 | effects: | ||
| 92 | - pulse | ||
| 93 | - addressable_rainbow | ||
| 94 | - addressable_color_wipe | ||
| 95 | - addressable_scan | ||
| 96 | - addressable_fireworks | ||
| 97 | - addressable_random_twinkle | ||
| 98 | |||
| 99 | binary_sensor: | ||
| 100 | - platform: gpio | ||
| 101 | name: "Touch button" | ||
| 102 | id: touch_button | ||
| 103 | pin: | ||
| 104 | number: D8 | ||
| 105 | mode: INPUT | ||
| 106 | internal: true | ||
| 107 | filters: | ||
| 108 | - delayed_on: 50ms | ||
| 109 | on_state: | ||
| 110 | then: | ||
| 111 | - lambda: id(pc_power_onoff).set_state(x); | ||
| 112 | |||
| 113 | - platform: gpio | ||
| 114 | name: "Power button" | ||
| 115 | id: power_button | ||
| 116 | pin: | ||
| 117 | number: D5 | ||
| 118 | mode: INPUT_PULLUP | ||
| 119 | inverted: true | ||
| 120 | internal: true | ||
| 121 | #on_state: | ||
| 122 | # then: | ||
| 123 | # - lambda: id(pc_power_onoff).set_state(x); | ||
| 124 | on_click: | ||
| 125 | - max_length: 1s | ||
| 126 | then: | ||
| 127 | - lambda: |- | ||
| 128 | auto light = id(pc_rgb_led); | ||
| 129 | int hue, new_hue; | ||
| 130 | float saturation, value, r, g, b; | ||
| 131 | light->current_values_as_rgb(&r, &g, &b); | ||
| 132 | rgb_to_hsv(r, g, b, hue, saturation, value); | ||
| 133 | do { | ||
| 134 | new_hue = static_cast<int>(random_float() * 360.0f); | ||
| 135 | } while (abs(new_hue - hue) < 42); | ||
| 136 | hsv_to_rgb(new_hue, 1.0, 1.0, r, g, b); | ||
| 137 | light->turn_on().set_rgb(r, g, b).set_white(0).perform(); | ||
| 138 | |||
| 139 | - platform: gpio | ||
| 140 | name: "Reset button" | ||
| 141 | id: reset_button | ||
| 142 | pin: | ||
| 143 | number: D6 | ||
| 144 | mode: INPUT_PULLUP | ||
| 145 | inverted: true | ||
| 146 | internal: true | ||
| 147 | #on_state: | ||
| 148 | # then: | ||
| 149 | # - lambda: id(pc_reset).set_state(x); | ||
| 150 | on_click: | ||
| 151 | - max_length: 500ms | ||
| 152 | then: | ||
| 153 | - lambda: |- | ||
| 154 | auto light = id(pc_rgb_led); | ||
| 155 | auto nexteffect = light->get_effect_by_index(light->get_current_effect_index() + 1); | ||
| 156 | if (!light->current_values.is_on()) | ||
| 157 | nexteffect = nullptr; | ||
| 158 | auto name = (nexteffect != nullptr) ? nexteffect->get_name() : "none"; | ||
| 159 | light->turn_on().set_effect(name).perform(); | ||
| 160 | |||
| 161 | - platform: template | ||
| 162 | name: "Power/Reset button delayed" | ||
| 163 | internal: true | ||
| 164 | lambda: !lambda return id(power_button).state || id(reset_button).state; | ||
| 165 | filters: | ||
| 166 | - delayed_on: 1s | ||
| 167 | on_press: | ||
| 168 | then: | ||
| 169 | - light.turn_off: pc_rgb_led | ||
| 170 | |||
| 171 | - platform: gpio | ||
| 172 | name: "Powered" | ||
| 173 | icon: "mdi:desktop-tower" | ||
| 174 | pin: | ||
| 175 | number: D1 | ||
| 176 | mode: INPUT_PULLUP | ||
| 177 | filters: | ||
| 178 | - delayed_on: 100ms | ||
| 179 | - delayed_off: 500ms | ||
| 180 | on_release: | ||
| 181 | then: | ||
| 182 | - light.turn_off: pc_rgb_led | ||
