From 523258cc7165b302ed83bd7fe2502edd23dc9070 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 16 Oct 2025 22:01:12 +0200 Subject: office-pc-control: initial commit --- esphome/config/office-pc-control.yaml | 182 ++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 esphome/config/office-pc-control.yaml (limited to 'esphome') 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 @@ +esphome: + name: office-pc-control + area: Office + on_boot: + priority: -100 + then: + - output.turn_off: pc_reset + - output.turn_off: pc_power_onoff + - light.control: + id: pc_rgb_led + brightness: 100% + red: 100% + green: 0% + blue: 0% + white: 0% + +esp8266: + board: nodemcuv2 + +# 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: + +output: + - platform: gpio + id: pc_reset + pin: + number: D2 + inverted: true # pc power/reset pins are GND activated + + - platform: gpio + id: pc_power_onoff + pin: + number: D3 + inverted: true # pc power/reset pins are GND activated + +button: + - platform: output + name: "Reset" + icon: "mdi:restore-alert" + output: pc_power_onoff + duration: 150ms + device_class: restart + + - platform: output + name: "Power On/Off" + icon: "mdi:power" + output: pc_power_onoff + duration: 150ms + + - platform: output + name: "Force Off" + icon: "mdi:power" + output: pc_power_onoff + duration: 5000ms + +light: + - platform: neopixelbus + name: "RGB LED" + id: pc_rgb_led + type: GRBW + variant: WS2813 #800KBPS + num_leds: 16 + pin: D4 # GPIO2 + method: + type: esp8266_uart + bus: 1 + default_transition_length: 300ms + effects: + - pulse + - addressable_rainbow + - addressable_color_wipe + - addressable_scan + - addressable_fireworks + - addressable_random_twinkle + +binary_sensor: + - platform: gpio + name: "Touch button" + id: touch_button + pin: + number: D8 + mode: INPUT + internal: true + filters: + - delayed_on: 50ms + on_state: + then: + - lambda: id(pc_power_onoff).set_state(x); + + - platform: gpio + name: "Power button" + id: power_button + pin: + number: D5 + mode: INPUT_PULLUP + inverted: true + internal: true + #on_state: + # then: + # - lambda: id(pc_power_onoff).set_state(x); + on_click: + - max_length: 1s + then: + - lambda: |- + auto light = id(pc_rgb_led); + int hue, new_hue; + float saturation, value, r, g, b; + light->current_values_as_rgb(&r, &g, &b); + rgb_to_hsv(r, g, b, hue, saturation, value); + do { + new_hue = static_cast(random_float() * 360.0f); + } while (abs(new_hue - hue) < 42); + hsv_to_rgb(new_hue, 1.0, 1.0, r, g, b); + light->turn_on().set_rgb(r, g, b).set_white(0).perform(); + + - platform: gpio + name: "Reset button" + id: reset_button + pin: + number: D6 + mode: INPUT_PULLUP + inverted: true + internal: true + #on_state: + # then: + # - lambda: id(pc_reset).set_state(x); + on_click: + - max_length: 500ms + then: + - lambda: |- + auto light = id(pc_rgb_led); + auto nexteffect = light->get_effect_by_index(light->get_current_effect_index() + 1); + if (!light->current_values.is_on()) + nexteffect = nullptr; + auto name = (nexteffect != nullptr) ? nexteffect->get_name() : "none"; + light->turn_on().set_effect(name).perform(); + + - platform: template + name: "Power/Reset button delayed" + internal: true + lambda: !lambda return id(power_button).state || id(reset_button).state; + filters: + - delayed_on: 1s + on_press: + then: + - light.turn_off: pc_rgb_led + + - platform: gpio + name: "Powered" + icon: "mdi:desktop-tower" + pin: + number: D1 + mode: INPUT_PULLUP + filters: + - delayed_on: 100ms + - delayed_off: 500ms + on_release: + then: + - light.turn_off: pc_rgb_led -- cgit v1.2.3