diff options
Diffstat (limited to 'esphome/config/office-desk-control.yaml')
| -rw-r--r-- | esphome/config/office-desk-control.yaml | 290 |
1 files changed, 290 insertions, 0 deletions
diff --git a/esphome/config/office-desk-control.yaml b/esphome/config/office-desk-control.yaml new file mode 100644 index 0000000..1d4dcba --- /dev/null +++ b/esphome/config/office-desk-control.yaml | |||
| @@ -0,0 +1,290 @@ | |||
| 1 | substitutions: | ||
| 2 | device_name: office-desk-control | ||
| 3 | friendly_name: "Office Desk Control" | ||
| 4 | min_height: "65.5" # cm | ||
| 5 | max_height: "131" # cm | ||
| 6 | tx_pin: GPIO1 # TX | ||
| 7 | rx_pin: GPIO3 # RX | ||
| 8 | #tx_pin: GPIO15 # D7/TXD2 | ||
| 9 | #rx_pin: GPIO13 # D8/RXD2 | ||
| 10 | screen_pin: GPIO12 # D6 | ||
| 11 | |||
| 12 | external_components: | ||
| 13 | source: github://iMicknl/LoctekMotion_IoT | ||
| 14 | components: [ loctekmotion_desk_height ] | ||
| 15 | |||
| 16 | esphome: | ||
| 17 | name: ${device_name} | ||
| 18 | friendly_name: ${friendly_name} | ||
| 19 | |||
| 20 | # Delay UART interaction on boot to give the desk controller time to initialize. | ||
| 21 | # After the delay, wake the desk by sending the "M" command to request the current height. | ||
| 22 | on_boot: | ||
| 23 | priority: -100 | ||
| 24 | then: | ||
| 25 | - delay: 10s | ||
| 26 | - button.press: button_wake_screen | ||
| 27 | - delay: 300ms | ||
| 28 | - button.press: button_m | ||
| 29 | |||
| 30 | esp8266: | ||
| 31 | board: d1_mini | ||
| 32 | |||
| 33 | # Enable logging | ||
| 34 | logger: | ||
| 35 | |||
| 36 | # Enable Home Assistant API | ||
| 37 | api: | ||
| 38 | encryption: | ||
| 39 | key: !secret api_encryption_key | ||
| 40 | |||
| 41 | # OTA | ||
| 42 | ota: | ||
| 43 | - platform: esphome | ||
| 44 | password: !secret ota_password | ||
| 45 | |||
| 46 | # WiFi Credentials | ||
| 47 | wifi: | ||
| 48 | domain: .lan | ||
| 49 | ssid: !secret wifi_ssid | ||
| 50 | password: !secret wifi_password | ||
| 51 | power_save_mode: LIGHT | ||
| 52 | |||
| 53 | # Enable fallback hotspot (captive portal) in case wifi connection fails | ||
| 54 | ap: | ||
| 55 | ssid: "${device_name} Hotspot" | ||
| 56 | password: !secret wifi_ap_password | ||
| 57 | |||
| 58 | captive_portal: | ||
| 59 | |||
| 60 | uart: | ||
| 61 | - id: desk_uart | ||
| 62 | baud_rate: 9600 | ||
| 63 | tx_pin: ${tx_pin} | ||
| 64 | rx_pin: ${rx_pin} | ||
| 65 | # debug: | ||
| 66 | |||
| 67 | sensor: | ||
| 68 | - platform: uptime | ||
| 69 | name: Uptime | ||
| 70 | |||
| 71 | - platform: loctekmotion_desk_height | ||
| 72 | id: "desk_height" | ||
| 73 | name: Desk height | ||
| 74 | on_value_range: | ||
| 75 | - below: ${min_height} | ||
| 76 | then: | ||
| 77 | - switch.turn_off: switch_down | ||
| 78 | - button.press: button_wake_screen | ||
| 79 | - above: ${max_height} | ||
| 80 | then: | ||
| 81 | - switch.turn_off: switch_up | ||
| 82 | - button.press: button_wake_screen | ||
| 83 | on_value: | ||
| 84 | then: | ||
| 85 | - cover.template.publish: | ||
| 86 | id: desk_cover | ||
| 87 | position: !lambda |- | ||
| 88 | // The sensor outputs values from min_height (cm) to max_height (cm) | ||
| 89 | // We need to translate this to 0 - 1 scale. | ||
| 90 | float position = (float(x) - float(${min_height})) / (float(${max_height}) - float(${min_height})); | ||
| 91 | return position; | ||
| 92 | - component.update: set_desk_height | ||
| 93 | |||
| 94 | switch: | ||
| 95 | - platform: gpio | ||
| 96 | name: "Virtual screen" # PIN20 | ||
| 97 | pin: | ||
| 98 | number: ${screen_pin} | ||
| 99 | mode: OUTPUT | ||
| 100 | restore_mode: ALWAYS_ON | ||
| 101 | entity_category: "config" | ||
| 102 | internal: true | ||
| 103 | |||
| 104 | - platform: uart | ||
| 105 | name: "Up" | ||
| 106 | id: switch_up | ||
| 107 | icon: mdi:arrow-up-bold | ||
| 108 | data: [0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d] | ||
| 109 | uart_id: desk_uart | ||
| 110 | send_every: 108ms | ||
| 111 | internal: true | ||
| 112 | on_turn_on: | ||
| 113 | - button.press: button_wake_screen | ||
| 114 | - delay: 200ms | ||
| 115 | |||
| 116 | - platform: uart | ||
| 117 | name: "Down" | ||
| 118 | id: switch_down | ||
| 119 | icon: mdi:arrow-down-bold | ||
| 120 | data: [0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d] | ||
| 121 | uart_id: desk_uart | ||
| 122 | send_every: 108ms | ||
| 123 | internal: true | ||
| 124 | on_turn_on: | ||
| 125 | - button.press: button_wake_screen | ||
| 126 | - delay: 200ms | ||
| 127 | |||
| 128 | # - platform: uart | ||
| 129 | # name: "Alarm off" | ||
| 130 | # id: switch_alarm | ||
| 131 | # icon: mdi:alarm | ||
| 132 | # data: [0x9b, 0x06, 0x02, 0x40, 0x00, 0xAC, 0x90, 0x9d] | ||
| 133 | # uart_id: desk_uart | ||
| 134 | # send_every: 108ms | ||
| 135 | # on_turn_on: | ||
| 136 | # - delay: 3000ms | ||
| 137 | # - switch.turn_off: switch_alarm | ||
| 138 | # entity_category: "config" | ||
| 139 | |||
| 140 | - platform: uart | ||
| 141 | name: "Child lock" | ||
| 142 | id: switch_child_lock | ||
| 143 | icon: mdi:account-lock | ||
| 144 | data: [0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d] | ||
| 145 | uart_id: desk_uart | ||
| 146 | send_every: 108ms | ||
| 147 | on_turn_on: | ||
| 148 | - delay: 5000ms | ||
| 149 | - switch.turn_off: switch_child_lock | ||
| 150 | entity_category: "config" | ||
| 151 | |||
| 152 | button: | ||
| 153 | - platform: template | ||
| 154 | name: "Preset 1" | ||
| 155 | icon: mdi:numeric-1-box | ||
| 156 | on_press: | ||
| 157 | - button.press: button_wake_screen | ||
| 158 | - delay: 200ms | ||
| 159 | - uart.write: | ||
| 160 | id: desk_uart | ||
| 161 | data: [0x9b, 0x06, 0x02, 0x04, 0x00, 0xac, 0xa3, 0x9d] | ||
| 162 | |||
| 163 | - platform: template | ||
| 164 | name: "Preset 2" | ||
| 165 | icon: mdi:numeric-2-box | ||
| 166 | on_press: | ||
| 167 | - button.press: button_wake_screen | ||
| 168 | - delay: 200ms | ||
| 169 | - uart.write: | ||
| 170 | id: desk_uart | ||
| 171 | data: [0x9b, 0x06, 0x02, 0x08, 0x00, 0xac, 0xa6, 0x9d] | ||
| 172 | |||
| 173 | - platform: template | ||
| 174 | name: "Sit" # Preset 3 on some control panels | ||
| 175 | icon: mdi:chair-rolling | ||
| 176 | on_press: | ||
| 177 | - button.press: button_wake_screen | ||
| 178 | - delay: 200ms | ||
| 179 | - uart.write: | ||
| 180 | id: desk_uart | ||
| 181 | data: [0x9b, 0x06, 0x02, 0x00, 0x01, 0xac, 0x60, 0x9d] | ||
| 182 | |||
| 183 | - platform: template | ||
| 184 | name: "Stand" # Preset 4 on some control panels | ||
| 185 | icon: mdi:human-handsup | ||
| 186 | on_press: | ||
| 187 | - button.press: button_wake_screen | ||
| 188 | - delay: 200ms | ||
| 189 | - uart.write: | ||
| 190 | id: desk_uart | ||
| 191 | data: [0x9b, 0x06, 0x02, 0x10, 0x00, 0xac, 0xac, 0x9d] | ||
| 192 | |||
| 193 | - platform: template | ||
| 194 | name: "Memory" | ||
| 195 | id: button_m | ||
| 196 | icon: mdi:alpha-m-box | ||
| 197 | entity_category: "config" | ||
| 198 | on_press: | ||
| 199 | - uart.write: | ||
| 200 | id: desk_uart | ||
| 201 | data: [0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d] | ||
| 202 | |||
| 203 | - platform: template | ||
| 204 | name: "Wake screen" | ||
| 205 | id: button_wake_screen | ||
| 206 | icon: mdi:gesture-tap-button | ||
| 207 | entity_category: "config" | ||
| 208 | on_press: | ||
| 209 | - uart.write: | ||
| 210 | id: desk_uart | ||
| 211 | data: [0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d] | ||
| 212 | |||
| 213 | # - platform: template | ||
| 214 | # name: "Alarm" | ||
| 215 | # id: button_alarm | ||
| 216 | # icon: mdi:alarm | ||
| 217 | # on_press: | ||
| 218 | # - uart.write: | ||
| 219 | # id: desk_uart | ||
| 220 | # data: [0x9b, 0x06, 0x02, 0x40, 0x00, 0xAC, 0x90, 0x9d] | ||
| 221 | |||
| 222 | - platform: restart | ||
| 223 | name: "Restart" | ||
| 224 | entity_category: "config" | ||
| 225 | |||
| 226 | cover: | ||
| 227 | - platform: template | ||
| 228 | id: "desk_cover" | ||
| 229 | icon: mdi:desk # or mdi:human-male-height-variant | ||
| 230 | name: "Desk" | ||
| 231 | device_class: blind # makes it easier to integrate with Google/Alexa | ||
| 232 | has_position: true | ||
| 233 | position_action: | ||
| 234 | - if: | ||
| 235 | condition: | ||
| 236 | - lambda: !lambda |- | ||
| 237 | return pos > id(desk_cover).position; | ||
| 238 | then: | ||
| 239 | - cover.open: desk_cover | ||
| 240 | - wait_until: | ||
| 241 | lambda: |- | ||
| 242 | return id(desk_cover).position >= pos; | ||
| 243 | - cover.stop: desk_cover | ||
| 244 | else: | ||
| 245 | - cover.close: desk_cover | ||
| 246 | - wait_until: | ||
| 247 | lambda: |- | ||
| 248 | return id(desk_cover).position <= pos; | ||
| 249 | - cover.stop: desk_cover | ||
| 250 | stop_action: | ||
| 251 | - switch.turn_off: switch_up | ||
| 252 | - switch.turn_off: switch_down | ||
| 253 | - button.press: button_wake_screen | ||
| 254 | open_action: | ||
| 255 | - switch.turn_off: switch_down | ||
| 256 | - switch.turn_on: switch_up | ||
| 257 | close_action: | ||
| 258 | - switch.turn_off: switch_up | ||
| 259 | - switch.turn_on: switch_down | ||
| 260 | optimistic: false | ||
| 261 | |||
| 262 | number: | ||
| 263 | - platform: template | ||
| 264 | name: "Desk height" | ||
| 265 | id: set_desk_height | ||
| 266 | min_value: ${min_height} | ||
| 267 | max_value: ${max_height} | ||
| 268 | icon: "mdi:counter" | ||
| 269 | unit_of_measurement: "cm" | ||
| 270 | device_class: "distance" | ||
| 271 | step: 0.1 | ||
| 272 | lambda: !lambda |- | ||
| 273 | return id(desk_height).state; | ||
| 274 | set_action: | ||
| 275 | - if: | ||
| 276 | condition: | ||
| 277 | - lambda: !lambda |- | ||
| 278 | return x > id(desk_height).state; | ||
| 279 | then: | ||
| 280 | - cover.open: desk_cover | ||
| 281 | - wait_until: | ||
| 282 | lambda: |- | ||
| 283 | return id(desk_height).state >= x; | ||
| 284 | - cover.stop: desk_cover | ||
| 285 | else: | ||
| 286 | - cover.close: desk_cover | ||
| 287 | - wait_until: | ||
| 288 | lambda: |- | ||
| 289 | return id(desk_height).state <= x; | ||
| 290 | - cover.stop: desk_cover | ||
