diff options
Diffstat (limited to 'esphome/config/bedlight.yaml')
| -rw-r--r-- | esphome/config/bedlight.yaml | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/esphome/config/bedlight.yaml b/esphome/config/bedlight.yaml new file mode 100644 index 0000000..81392b0 --- /dev/null +++ b/esphome/config/bedlight.yaml | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | esphome: | ||
| 2 | name: bedlight | ||
| 3 | platform: ESP8266 | ||
| 4 | board: esp01_1m | ||
| 5 | |||
| 6 | # light default values | ||
| 7 | on_boot: | ||
| 8 | then: | ||
| 9 | - light.control: | ||
| 10 | id: bed | ||
| 11 | state: off | ||
| 12 | brightness: 50% | ||
| 13 | color_temperature: 3000 K | ||
| 14 | |||
| 15 | # Enable logging | ||
| 16 | logger: | ||
| 17 | # make RXD / TXD available | ||
| 18 | baud_rate: 0 | ||
| 19 | |||
| 20 | # Enable Home Assistant API | ||
| 21 | api: | ||
| 22 | password: !secret api_password | ||
| 23 | |||
| 24 | # OTA | ||
| 25 | ota: | ||
| 26 | password: !secret ota_password | ||
| 27 | |||
| 28 | # WiFi Credentials | ||
| 29 | wifi: | ||
| 30 | domain: .lan | ||
| 31 | ssid: !secret wifi_ssid | ||
| 32 | password: !secret wifi_password | ||
| 33 | |||
| 34 | # Enable fallback hotspot (captive portal) in case wifi connection fails | ||
| 35 | ap: | ||
| 36 | ssid: "Bedlight Fallback Hotspot" | ||
| 37 | password: !secret wifi_ap_password | ||
| 38 | |||
| 39 | captive_portal: | ||
| 40 | |||
| 41 | light: | ||
| 42 | - id: bed | ||
| 43 | platform: cwww | ||
| 44 | name: "Bed" | ||
| 45 | cold_white: pwm_w_t | ||
| 46 | warm_white: pwm_b_t | ||
| 47 | cold_white_color_temperature: 6536 K | ||
| 48 | warm_white_color_temperature: 2000 K | ||
| 49 | restore_mode: RESTORE_AND_OFF | ||
| 50 | |||
| 51 | output: | ||
| 52 | - id: gpio_r | ||
| 53 | platform: gpio | ||
| 54 | pin: GPIO12 | ||
| 55 | |||
| 56 | - id: gpio_g | ||
| 57 | platform: gpio | ||
| 58 | pin: GPIO15 | ||
| 59 | |||
| 60 | - id: pwm_b | ||
| 61 | platform: esp8266_pwm | ||
| 62 | pin: GPIO14 | ||
| 63 | |||
| 64 | - id: pwm_b_t | ||
| 65 | platform: template | ||
| 66 | type: float | ||
| 67 | write_action: | ||
| 68 | - output.set_level: | ||
| 69 | id: pwm_b | ||
| 70 | level: !lambda |- | ||
| 71 | // limit min power | ||
| 72 | if (state > 0.0 && state < 0.0006) | ||
| 73 | return 0.0006; | ||
| 74 | if (state <= 0.0002) | ||
| 75 | return 0.0002; | ||
| 76 | return state; | ||
| 77 | |||
| 78 | - id: pwm_w | ||
| 79 | platform: esp8266_pwm | ||
| 80 | pin: GPIO4 | ||
| 81 | |||
| 82 | - id: pwm_w_t | ||
| 83 | platform: template | ||
| 84 | type: float | ||
| 85 | write_action: | ||
| 86 | - output.set_level: | ||
| 87 | id: pwm_w | ||
| 88 | level: !lambda |- | ||
| 89 | // limit min power | ||
| 90 | if (state > 0.0 && state < 0.0006) | ||
| 91 | return 0.0006; | ||
| 92 | if (state <= 0.0002) | ||
| 93 | return 0.0002; | ||
| 94 | return state; | ||
| 95 | |||
| 96 | - id: gpio0 | ||
| 97 | platform: gpio | ||
| 98 | pin: GPIO0 | ||
| 99 | |||
| 100 | - id: gpio_txd | ||
| 101 | platform: gpio | ||
| 102 | pin: GPIO1 | ||
| 103 | |||
| 104 | - id: gpio_rxd | ||
| 105 | platform: gpio | ||
| 106 | pin: GPIO3 | ||
| 107 | |||
| 108 | globals: | ||
| 109 | - id: g_dim_level | ||
| 110 | type: float | ||
| 111 | initial_value: '0.02' | ||
| 112 | - id: g_min_dim_level | ||
| 113 | type: float | ||
| 114 | initial_value: '0.02' | ||
| 115 | |||
| 116 | script: | ||
| 117 | - id: reset_dim_direction | ||
| 118 | mode: restart | ||
| 119 | then: | ||
| 120 | - delay: 10s | ||
| 121 | - lambda: 'id(g_dim_level) = abs(id(g_dim_level));' | ||
| 122 | |||
| 123 | binary_sensor: | ||
| 124 | - id: user_button | ||
| 125 | platform: gpio | ||
| 126 | pin: GPIO5 | ||
| 127 | filters: | ||
| 128 | - delayed_on: 30ms | ||
| 129 | on_click: | ||
| 130 | min_length: 30ms | ||
| 131 | max_length: 350ms | ||
| 132 | then: | ||
| 133 | - logger.log: "on_click" | ||
| 134 | # TODO: if brightness is low, turn on + transition is also slow | ||
| 135 | - light.toggle: bed | ||
| 136 | # dim up per default unless brightness is 95% | ||
| 137 | - lambda: |- | ||
| 138 | id(g_dim_level) = abs(id(g_dim_level)); | ||
| 139 | if (id(bed).current_values.get_brightness() >= 0.95) | ||
| 140 | id(g_dim_level) *= -1; | ||
| 141 | on_press: | ||
| 142 | then: | ||
| 143 | - delay: 500ms | ||
| 144 | - if: | ||
| 145 | condition: | ||
| 146 | # make sure button is still pressed | ||
| 147 | binary_sensor.is_on: user_button | ||
| 148 | then: | ||
| 149 | - while: | ||
| 150 | condition: | ||
| 151 | binary_sensor.is_on: user_button | ||
| 152 | then: | ||
| 153 | - logger.log: "on_press" | ||
| 154 | - light.dim_relative: | ||
| 155 | id: bed | ||
| 156 | relative_brightness: !lambda |- | ||
| 157 | auto brightness = id(bed).current_values.get_brightness(); | ||
| 158 | // start dimming at this value | ||
| 159 | if (!id(bed).current_values.is_on()) | ||
| 160 | return abs(id(g_min_dim_level)); | ||
| 161 | // don't dim to zero | ||
| 162 | if (id(g_dim_level) < 0 && brightness + id(g_dim_level) <= id(g_min_dim_level)) | ||
| 163 | return 0.0; | ||
| 164 | return id(g_dim_level); | ||
| 165 | transition_length: 100ms | ||
| 166 | - delay: 0.1s | ||
| 167 | # reverse dim direction | ||
| 168 | - lambda: 'id(g_dim_level) = id(g_dim_level) * -1;' | ||
| 169 | - script.execute: reset_dim_direction | ||
| 170 | on_double_click: | ||
| 171 | then: | ||
| 172 | - homeassistant.event: | ||
| 173 | event: esphome.double_click | ||
