├── .gitattributes ├── images ├── D1-Mini-pinout.webp ├── 3d-model-with-desk.jpeg ├── soldered-switches.jpeg ├── 3d-model-without-desk.jpeg ├── rotary-encoder-pinout.jpeg ├── media-controller-mounted.jpeg ├── soldered-switches-inserted.jpeg └── everything-soldered-together.jpeg ├── stl └── ESPHome-Media-controller.stl ├── ESPHome-media-controller.yaml └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /images/D1-Mini-pinout.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/D1-Mini-pinout.webp -------------------------------------------------------------------------------- /images/3d-model-with-desk.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/3d-model-with-desk.jpeg -------------------------------------------------------------------------------- /images/soldered-switches.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/soldered-switches.jpeg -------------------------------------------------------------------------------- /images/3d-model-without-desk.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/3d-model-without-desk.jpeg -------------------------------------------------------------------------------- /images/rotary-encoder-pinout.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/rotary-encoder-pinout.jpeg -------------------------------------------------------------------------------- /stl/ESPHome-Media-controller.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/stl/ESPHome-Media-controller.stl -------------------------------------------------------------------------------- /images/media-controller-mounted.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/media-controller-mounted.jpeg -------------------------------------------------------------------------------- /images/soldered-switches-inserted.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/soldered-switches-inserted.jpeg -------------------------------------------------------------------------------- /images/everything-soldered-together.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florisvandesande/ESPHome-media-controller/HEAD/images/everything-soldered-together.jpeg -------------------------------------------------------------------------------- /ESPHome-media-controller.yaml: -------------------------------------------------------------------------------- 1 | # ESPHome Media Controller 2 | # Change the substitutions below to fit your own Home Assistant setup 3 | # You can generate an api_key at https://esphome.io/components/api.html 4 | # Projectpage: https://florisvandesande.com/project/esphome-media-controller 5 | 6 | substitutions: 7 | device_name: media-controller-desk 8 | friendly_name: "Media Controller desk" 9 | media_player: media_player.your_media_player 10 | api_key: "dLrgP/XXOWI6qTfe0hOdBA9ojg8e1GELX4w4tMtpNWo=" 11 | ap_password: !secret captive-portal # set in secrets.yaml or change me! 12 | wifi_ssid: !secret wifi_ssid # set in secrets.yaml or change me! 13 | wifi_password: !secret wifi_password # set in secrets.yaml or change me! 14 | 15 | 16 | esphome: 17 | name: ${device_name} 18 | friendly_name: ${friendly_name} 19 | comment: ESPHome ${friendly_name} 20 | name_add_mac_suffix: true 21 | platform: ESP8266 22 | board: d1_mini 23 | 24 | # This will allow for (future) project identification, configuration and updates. 25 | project: 26 | name: esphome.media-controller-desk 27 | version: "1.0" 28 | 29 | # To be able to get logs from the device via serial and api. 30 | logger: 31 | 32 | # API is a requirement of the dashboard import. 33 | api: 34 | encryption: 35 | key: ${api_key} 36 | 37 | # OTA is required for Over-the-Air updating 38 | ota: 39 | 40 | # Network settings 41 | wifi: 42 | ssid: ${wifi_ssid} 43 | password: ${wifi_password} 44 | 45 | # Enable fallback hotspot (captive portal) in case wifi connection fails 46 | ap: 47 | ssid: "${device_name}" 48 | password: ${ap_password} 49 | 50 | captive_portal: 51 | 52 | web_server: 53 | port: 80 54 | 55 | 56 | binary_sensor: 57 | 58 | # Key switches 59 | - platform: gpio 60 | pin: 61 | number: D5 62 | mode: INPUT_PULLUP 63 | inverted: True 64 | name: "Left Button" 65 | filters: 66 | - delayed_on: 10ms 67 | - platform: gpio 68 | pin: 69 | number: D6 70 | mode: INPUT_PULLUP 71 | inverted: True 72 | name: "Middle Button" 73 | filters: 74 | - delayed_on: 10ms 75 | - platform: gpio 76 | pin: 77 | number: D7 78 | mode: INPUT_PULLUP 79 | inverted: True 80 | name: "Right Button" 81 | filters: 82 | - delayed_on: 10ms 83 | 84 | # Rotary Encoder 85 | - platform: gpio 86 | pin: 87 | number: D2 88 | mode: INPUT_PULLUP 89 | inverted: true 90 | name: "Rotary Encoder Button" 91 | on_press: 92 | - homeassistant.service: 93 | service: media_player.media_play_pause 94 | data: 95 | entity_id: ${media_player} 96 | 97 | sensor: 98 | - platform: rotary_encoder 99 | name: "Rotary Encoder" 100 | pin_a: 101 | number: D3 102 | mode: INPUT 103 | pin_b: 104 | number: D4 105 | mode: INPUT 106 | on_clockwise: 107 | - homeassistant.service: 108 | service: media_player.volume_up 109 | data: 110 | entity_id: ${media_player} 111 | - logger.log: "Turned Clockwise" 112 | on_anticlockwise: 113 | - homeassistant.service: 114 | service: media_player.volume_down 115 | data: 116 | entity_id: ${media_player} 117 | - logger.log: "Turned Anti Clockwise" 118 | 119 | 120 | # Network details 121 | text_sensor: 122 | - platform: wifi_info 123 | ip_address: 124 | name: ${device_name} IP 125 | icon: mdi:ip-network 126 | ssid: 127 | name: ${device_name} SSID 128 | icon: mdi:wifi 129 | mac_address: 130 | name: "${device_name} MAC" 131 | icon: mdi:identifier -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESPHome media controller for Home Assistant 2 | [ESPHome](https://esphome.io/) media controller is made by [Floris van de Sande](https://florisvandesande.com/) and is meant to be used with [Home Assistant](https://www.home-assistant.io). 3 | 4 | ![media controller](images/3d-model-with-desk.jpeg) 5 | 6 | ## Features 7 | - Three buttons which you can use in your [Home Assistant](https://www.home-assistant.io) automations 8 | - Rotary knob to Play/Pause your music and adjust the Volume 9 | - Minimal design 10 | - Easy to make and install 11 | 12 | _You can use the buttons to do anything in Home Assistant, the aren't programmed in the yaml-code._ 13 | 14 | 15 | ## Hardware 16 | 17 | | Part list | Amount | 18 | | --------------- | --------- | 19 | | D1 Mini ESP8266 | 1 | 20 | | Rotary Encoder | 1 | 21 | | Key Switches | 3 | 22 | | Key Caps | 3 | 23 | | Electrical wire | ± 100 cm | 24 | | Screws 50 mm | 3 | 25 | | 5v power supply | optional | 26 | 27 | #### Other hardware 28 | - 3D printer with filament of your choice 29 | - Soldering iron 30 | 31 | You can find the STL files for the case and the knob here: 32 | - [Case and knob on Github](stl/ESPHome-Media-controller.stl) 33 | - [Case and knob on Printables](https://www.printables.com/model/551624-esphome-media-controller) 34 | - [Case and knob on Thingiverse](https://www.thingiverse.com/thing:6167722) 35 | 36 | ![3D model of the media controller](images/3d-model-without-desk.jpeg) 37 | 38 | 39 | ## Wiring 40 | | D1 Mini ESP8266 | Rotary Encoder | Switches | Cable color | 41 | | --------------- | -------------- | ------------ | ----------- | 42 | | D2 / GPIO4 | Switch | | White | 43 | | D3 / GPIO0 | PIN Out A | | Black | 44 | | D4 / GPIO2 | Pin Out B | | Black | 45 | | G / GND | GND and GND | Button 1/2/3 | Yellow | 46 | | D5 / GPIO14 | | Button 1 | Blue | 47 | | D6 / GPIO12 | | Button 2 | Green | 48 | | D7 / GPIO13 | | Button 3 | Red | 49 | 50 | | D1 mini ESP8266 | Rotary encoder | 51 | | ------------------------------- | -------------------------------------- | 52 | | ![](images/D1-Mini-pinout.webp) | ![](images/rotary-encoder-pinout.jpeg) | 53 | 54 | ## Code 55 | At the top of the [yaml](ESPHome-media-controller.yaml) are the **substitutions** which are used througout the code which you can easily change. The main one to change is the **media_player** substitution, as you won't be able to use the Rotary encoder for Play/Pause otherwise. 56 | Of course your could go down to the **sensor** part of the code to change the behavior of the rotary encoder; for example to use it to dim your lights. 57 | 58 | 59 | ## Assembly 60 | - Print the case and the knob 61 | - Solder the wires to the switches and the rotary encoder 62 | - Insert the switches and rotary knob in the printed case 63 | - Solder the wires from the switches and rotary encoder to the D1 mini 64 | - Flash the D1 mini and test if everything works as expected 65 | - Screw the case to the underside of your desk / table 66 | 67 | ![switches and rotary encoder soldered](images/soldered-switches.jpeg) 68 | 69 | ![switches and rotary encoder inserted into case](images/soldered-switches-inserted.jpeg) 70 | 71 | ![everything soldered together](images/everything-soldered-together.jpeg) 72 | 73 | ![media controller mounted under desk](images/media-controller-mounted.jpeg) 74 | 75 | 76 | ## Thank you 77 | - [Adamaze](https://github.com/adamaze) for his work on the [ESPHome Volume Knob](https://github.com/adamaze/esphome_volume_knob) 78 | - [Peter Remøy Paulsen](https://github.com/petrepa) for his work on the [Deskcontroller for ESPHome](https://github.com/petrepa/ESPHome-Desk-Controller/tree/main) 79 | - [Lars Ahlzen](https://www.thingiverse.com/sebajom/designs) for his [knob designs](https://www.thingiverse.com/thing:4807288) 80 | --------------------------------------------------------------------------------