diff --git a/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/amp_diagram.png b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/amp_diagram.png new file mode 100644 index 0000000..443dbd4 Binary files /dev/null and b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/amp_diagram.png differ diff --git a/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/index.md b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/index.md new file mode 100644 index 0000000..3552419 --- /dev/null +++ b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/index.md @@ -0,0 +1,107 @@ +--- +slug: adding-wifi-power-control-to-an-integrated-amplifier +title: "DIY Smart Appliance: Adding WiFi power control to an integrated amplifier" +tags: [smart home, Home Assistant, DIY, ESP8266, Wemos D1 Mini, WiFi, ESPHome] +image: /img/blog/2021/01/ext.jpg +--- +Previously I was using JBL Bar connected to a TV in my living room. It was controlled with WiFi IR bridge, so whenever my Chromecast or PS4 was in playing state, the Bar was turned on and ready. + +Now I have passive speakers with a simple integrated amplifier, and it can’t be turned on or off without physical interaction. You need to press and release the button on the front panel to toggle amplifier power. So today we will add WiFi power control to Cambridge Audion AXA25 integrated amplifier. + + + +It is not a complex task to simulate button pressing. We just need a relay and a delay. But we also need to detect the amplifier state because there are no differences in turning on and turning off actions. Fortunately, my amplifier has a USB port on the back to power some USB devices. Putting something with an LED indicator in this port helped me to detect that the port is powered only when the amplifier is on. Digital pins of ESP8266 boards are good tools to detect the current presence on a USB port. We will need a 5V power line and a ground line from the port. Here is a pinout of the USB port: + +![USB pins](usb_pinout.png) + +Let’s draw! + +![](amp_diagram.png) + +## Components + +1. LOLIN (Wemos) D1 mini ([wemos.cc](https://www.wemos.cc/en/latest/d1/d1_mini.html)) +1. 5V Relay Brick by Itead ([itead.com](https://www.itead.cc/electronic-brick-5v-relay.html)) +1. AC-DC 220V to 5V Step-Down Mini Power Supply ([amazon](https://www.amazon.com/HLK-PM01-supply-module-intelligent-household/dp/B07G5GL4B8)) + +Wemos has a [relay shield](https://www.wemos.cc/en/latest/d1_mini_shield/relay.html) as well but it can commutate up to 10A current so the electromagnet consumes more power. It is better to use some low-current relay for low-current circuits. + +As you can see I’m taking 220V AC power from the amplifier and converting it to 5V DC because we need to power the relay even when the amplifier is off. There is an always-powered low-current circuit that exists in the amplifier, but we can’t use it because of…. well, low current. Connecting a WiFi module and a relay to it will definitely destroy our amplifier. + +![Amplifier internals](int.png) + +## Firmware +### MQTT +If you want to use Arduino IDE to develop and flash the firmware to your Wemos D1 Mini board you’ll need to add an ESP8266 board manager and tools for Arduino. You can do this by performing [several simple steps from the official ESP8266 repository](https://github.com/esp8266/Arduino?ref=blog.yevi.org#installing-with-boards-manager). Then you can see the [MQTT-based firmware sources](https://github.com/estevez-dev/edwin-home/tree/master/devices/amplifier_mqtt) I was using before migrating to ESPHome. It could be an example, or you can just use it all. + +### ESPHome +[ESPHome](https://esphome.io) actually makes such projects much easier to implement, improve and support. It also has a very reliable [Home Assistant plugin](https://github.com/esphome/hassio) and integration. That is why I moved all my DIY projects to ESPHome and here is a configuration file of my amplifier: + +```yaml +esphome: + name: amplifier + platform: ESP8266 + board: d1_mini + +wifi: + ssid: "****" + password: "**************" + + # Enable fallback hotspot (captive portal) in case wifi connection fails + ap: + ssid: "Cambridge AXA25" + password: "*******" + +captive_portal: + +# Enable logging +logger: + +# Enable Home Assistant API +api: + password: "******" + +ota: + password: "******" + +binary_sensor: + - platform: gpio + id: amplifier_power + internal: true + pin: + number: D2 + mode: INPUT_PULLDOWN_16 + +switch: + - platform: gpio + id: relay + pin: D1 + restore_mode: ALWAYS_OFF + - platform: template + name: "Amplifier" + id: amplifier + lambda: |- + if (id(amplifier_power).state) { + return true; + } else { + return false; + } + turn_on_action: + - if: + condition: + binary_sensor.is_off: amplifier_power + then: + - switch.turn_on: relay + - delay: 300ms + - switch.turn_off: relay + turn_off_action: + - if: + condition: + binary_sensor.is_on: amplifier_power + then: + - switch.turn_on: relay + - delay: 300ms + - switch.turn_off: relay +``` + +That’s it for today. Thanks for reading. diff --git a/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/int.png b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/int.png new file mode 100644 index 0000000..a536a23 Binary files /dev/null and b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/int.png differ diff --git a/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/usb_pinout.png b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/usb_pinout.png new file mode 100644 index 0000000..feb1efe Binary files /dev/null and b/blog/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/usb_pinout.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ac_power_contacts.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ac_power_contacts.jpg new file mode 100644 index 0000000..322d051 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ac_power_contacts.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ac_wires.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ac_wires.jpg new file mode 100644 index 0000000..b9f262d Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ac_wires.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/change_wires.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/change_wires.jpg new file mode 100644 index 0000000..093aa5f Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/change_wires.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d1_mini_and_shield.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d1_mini_and_shield.jpg new file mode 100644 index 0000000..9d8ca51 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d1_mini_and_shield.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d1_power-2048x1159.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d1_power-2048x1159.jpg new file mode 100644 index 0000000..0dfe27d Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d1_power-2048x1159.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d4_ir_recv.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d4_ir_recv.png new file mode 100644 index 0000000..a6bbf8b Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/d4_ir_recv.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/diagram.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/diagram.png new file mode 100644 index 0000000..e4c9206 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/diagram.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/factory_usb.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/factory_usb.png new file mode 100644 index 0000000..4c40ce7 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/factory_usb.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/factory_usb_pins.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/factory_usb_pins.jpg new file mode 100644 index 0000000..c16a070 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/factory_usb_pins.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/index.md b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/index.md new file mode 100644 index 0000000..f4e0391 --- /dev/null +++ b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/index.md @@ -0,0 +1,240 @@ +--- +slug: building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome +title: "Building WiFi IR remote control for any TV with ESP8266 Wemos D1 mini and ESPHome" +tags: [smart home, Home Assistant, DIY, ESP8266, Wemos D1 Mini, WiFi, ESPHome] +image: /img/blog/2021/01/tv_project.png +--- +Many modern TVs can be controlled not only with an IR remote. Many could be easily integrated with Home Assistant or any other smart home solution. Samsung smart TVs, LG with WebOS… But what if your TV is so dumb it even don’t have WiFi or Bluetooth? Today we’ll add WiFi control to an old and dumb Samsung TV with a little help from ESPHome. + + + +## Components and planning + +The base of our project would be [Wemos D1 mini](https://www.wemos.cc/en/latest/d1/d1_mini.html) – an ESP8266-based development board. Actually, it is possible to use any other WiFi development board you’d like, for example, NodeMCU. I choose the D1 mini because of its size and the nice [IR shield](https://www.wemos.cc/en/latest/d1_mini_shield/ir.html) it has. So the Wemos IR shield is the second part of our future IoT device. The main goal of the project is to receive commands through WiFi and transmit them to the TV using IR LED. So basically we want to build an IR remote where the buttons are replaced with commands through the WiFi. + +Also, we will need 5V DC power for our board. We can’t use a factory USB port on our TV because it is not powered when TV is off. I really like to use mini [AC-DC converters from Hi-Link](https://www.google.com/search?q=hi-link+mini+ac+dc+converter) in my projects and I really recommend it, but today I’ll need more power because I want to constantly power my Chromecast from the same power source. Because why not. So I found an old power supply that can handle up to 1.2A of current. Should be enough for a WiFi board and Chromecast. + +![Power supply](power_supply.jpg) + +Finally, we will also connect to the factory USB port of our TV. It is the best way to detect TV state (is it on or off currently). + +In general, the parts of the project should be connected like this: + +![Diagram](diagram.png) + +Now we will take a look at our TV from the inside. + +![Inside TV](inside_tv_1.jpg) + +## Build +### Power Supply +First of all, I removed the housing from my power supply. You don’t need to do this when using a Hi-Link power converter because it has places to solder the wires. + +![Power supply internals](power_supply_internals.jpg) + +I’ll use a USB port to connect Chromecast to it. Also, I’ll use USB port pins to take power for my WiFi board. + +![USB power pins](usb_power_pins.png) + +You need to be careful detecting 5V and Ground pins on the USB port. Here is a little help: + +![USB pinout](usb_pinout.png) + +From the other side of the power supply board, we have contact plates for AC power. That’s the place where we will solder AC power wires. + +![AC power contacts](ac_power_contacts.jpg) + +Our power supply is ready: + +![Power supply](power_supply_ready.jpg) + +### The board +![D! min and shield](d1_mini_and_shield.jpg) + +We are ready to build the mainboard now. Wemos D1 mini and its shields come separately from the pin legs. It is a good opportunity to make our device as small as possible. + +![](pin_legs.jpg) + +But first, we need to solder some contacts on the IR shield. It has several IR LEDs as well as several options for a send pin. We will use only one IR LED – `IR4`, and `D3` digital pin for sending IR signal, so we need to solder contact plates on the IR shield like this: + +![Shield contacts](shield_contacts.png) + +![](ir4_led.png) + +![](micro_usb.png) + +:::tip + +You can use the same board and shield to get IR codes from your TV remote, or build a separate [IR receiver](/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/index.md). If you will use the same board, you need also to enable receiving LED on the IR shield by soldering the corresponding contact plates. For example, to enable the IR receiver on the `D4` pin: + +![](d4_ir_recv.png) + +::: + +Also, we don’t need such long pin legs so we can shorten it with wire cutters. + +![](short_legs.jpg) + +And solder the legs finally. + +Now the wires. We need 5V and ground from our power supply to be connected to 5V and ground pins of the WiFi board. + +![D1 power](d1_power-2048x1159.jpg) + +Also, we will need the wires to the factory USB port to detect the state of our TV. According to our plan, the 5V from the TV USB port will go to the `D2` pin of the Wemos board, and the ground should go to the ground pin. + +![USB power](usb_power.jpg) + +### The firmware + +We can make it ourselves. That is what I’ve done in the past. It was a solution that takes BASE64 encoded IR data through MQTT protocol, decodes it, and sends it to the IR led. ~~You can check it on my GitHub~~. I also had a [separate IR receiver](/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/index.md) to read IR codes from IR remotes and encode them using BASE64. You don’t need all these sources if you are using ESPHome. With ESPHome we will have a simple YAML config for our device: + +```yaml +esphome: + name: living_room_tv + platform: ESP8266 + board: d1_mini + +wifi: + ssid: "WiFi" + password: "************" + + # Enable fallback hotspot (captive portal) in case wifi connection fails + ap: + ssid: "Living Room TV" + password: "************" + +captive_portal: + +# Enable logging +logger: + +# Enable Home Assistant API +api: + password: "************" + services: + - service: volume_up + then: + - remote_transmitter.transmit_samsung: + data: 0xE0E0E01F + - service: volume_down + then: + - remote_transmitter.transmit_samsung: + data: 0xE0E0D02F + - service: switch_source + then: + - remote_transmitter.transmit_samsung: + data: 0xE0E0807F + - service: hdmi1 + then: + - remote_transmitter.transmit_raw: + carrier_frequency: 38029 + code: [+4497,-4497,+552,-1657,+552,-1657,+552,-1657,+552,-552,+552,-552,+552,-552,+552,-552,+552,-552,+552,-1657,+552,-1657,+552,-1657,+552,-552,+552,-552,+552,-552,+552,-552,+552,-552,+552,-1657,+552,-552,+552,-552,+552,-1657,+552,-552,+552,-1657,+552,-1657,+552,-1657,+552,-552,+552,-1657,+552,-1657,+552,-552,+552,-1657,+552,-552,+552,-552,+552,-552,+552,-47858] + - service: hdmi2 + then: + - remote_transmitter.transmit_raw: + carrier_frequency: 38029 + code: [+4523,-4497,+552,-1709,+552,-1709,+552,-1709,+552,-579,+552,-579,+552,-579,+552,-579,+552,-579,+552,-1709,+552,-1709,+552,-1709,+552,-579,+552,-579,+552,-579,+552,-579,+552,-579,+552,-579,+552,-1709,+552,-1709,+552,-1709,+552,-1709,+552,-1709,+552,-579,+552,-1709,+552,-1709,+552,-579,+552,-579,+552,-579,+552,-579,+552,-579,+552,-1709,+552,-579,+552,-43993] + +ota: + password: "************" + +remote_transmitter: + pin: D3 + carrier_duty_percent: 50% + +binary_sensor: + - platform: gpio + id: tv_power + internal: true + pin: + number: D2 + mode: INPUT_PULLDOWN_16 + +switch: + - platform: template + name: "Living Room TV" + id: living_room_tv + lambda: |- + if (id(tv_power).state) { + return true; + } else { + return false; + } + turn_on_action: + - if: + condition: + binary_sensor.is_off: tv_power + then: + - remote_transmitter.transmit_samsung: + data: 0xE0E040BF + turn_off_action: + - if: + condition: + binary_sensor.is_on: tv_power + then: + - remote_transmitter.transmit_samsung: + data: 0xE0E040BF +``` + +`remote_transmitter` is a part where we are declaring our [IR transmitter](https://esphome.io/components/remote_transmitter.html). + +`binary_sensor` is a sensor that will read the voltage from the TV USB port to tell its current state. + +`switch` section is our main functionality. It will be exposed as an entity in Home Assistant and will allow us to control our TV. As you can see from `lambda` it takes the state from `binary_sensor` and uses an IR transmitter to send IR “power” command to the TV when turned on or off. It also checks the state of `binary_sensor` before sending IR command to avoid turning off the TV when it was turned on several times, for example, from automation or service. + +`data` field for `remote_transmitter.transmit_samsung` can be discovered using a simple ESPHome [IR Receiver](/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/index.md) built with the same Wemos D1 mini and IR shield. You can even do it with the same board we are using for this project as was mentioned before. + +I also want to be able to control TV volume and switch input sources through WiFi. So I’ve added a `services` section in `api`. All those `services` would be exposed as `esphome` in Home Assistant. + +You can see `hdmi1` and `hdmi2` services have `transmit_raw` instead of `transmit_samsung`. This is because I don’t have such buttons on my TV remote to discover the codes so I found the codes in pronto hex format and was able to convert it to raw data with frequency detection using [IrScrutinizer](https://github.com/bengtmartensson/IrScrutinizer). + +That’s it. Compile it and flash it with [ESPHome Flasher](https://github.com/esphome/esphome-flasher?ref=blog.yevi.org). + +## TV +### Placing the board +Let’s find our TV IR receiver. Usually, it is where the red light is flashing on it. Disassembled my TV more I found it on the bottom edge. We need to put our WiFi board as close as possible to the TV IR receiver pointing our sending IR LED (`IR4`) in the direction of IR receiver. + +![The board placed inside TV](place-2048x1206.jpg) + +While the power from the power supply is not connected yet, we can power the board from a micro USB, power our TV and make the first test. + +:::danger + +You need to be extremely careful when powering on the appliance without its housing! Avoid touching the boards and other internal parts of the appliance because it can lead to appliance damage or your death! + +::: + +![Test run](test.gif) + +When trying to put the TV housing back on with the WiFi board inside I discovered that I need to make the device even smaller. So I removed IR receiving LED as I have an IR receiver as a separate device. Also, I was forced to solder all wires on the same side of the board. + +![Removed IR receiver](remove_receiver.jpg) + +![Change wires side](change_wires.jpg) + +Now we are ready to use our favorite tool – double-sided adhesive tape, to put the board in its constant living place. + +### Factory USB port + +Here it is on the factory board: + +![Factory USB port](factory_usb.png) + +On the other side of this board, we can find the pins where we will solder the wires from the WiFi board – one from `D2`, and the other from the ground. + +![Factory USB pins](factory_usb_pins.jpg) + +### Power + +Now let’s take a look at the AC power connector on the TV. We can find the pins on the opposite side of the board and solder AC wires from our power supply to it. + +![AC wires](ac_wires.jpg) + +Before placing our power supply inside the TV we need to make sure it is isolated from its metal body. I’ve put a layer of plastic under it. + +![Plastic film](plastic.jpg) + +So the overall picture is looking like this: + +![](overview.png) \ No newline at end of file diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/inside_tv_1.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/inside_tv_1.jpg new file mode 100644 index 0000000..f7e0a1d Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/inside_tv_1.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ir4_led.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ir4_led.png new file mode 100644 index 0000000..2a41753 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/ir4_led.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/micro_usb.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/micro_usb.png new file mode 100644 index 0000000..ad3caf0 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/micro_usb.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/overview.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/overview.png new file mode 100644 index 0000000..262824d Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/overview.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/pin_legs.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/pin_legs.jpg new file mode 100644 index 0000000..d08ac0f Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/pin_legs.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/place-2048x1206.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/place-2048x1206.jpg new file mode 100644 index 0000000..cb9f628 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/place-2048x1206.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/plastic.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/plastic.jpg new file mode 100644 index 0000000..79f0370 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/plastic.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply.jpg new file mode 100644 index 0000000..261a816 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply_internals.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply_internals.jpg new file mode 100644 index 0000000..a4bcbea Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply_internals.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply_ready.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply_ready.jpg new file mode 100644 index 0000000..3a6edcd Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/power_supply_ready.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/remove_receiver.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/remove_receiver.jpg new file mode 100644 index 0000000..26d4a63 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/remove_receiver.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts.png new file mode 100644 index 0000000..43c8b70 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/short_legs.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/short_legs.jpg new file mode 100644 index 0000000..187c728 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/short_legs.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/test.gif b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/test.gif new file mode 100644 index 0000000..713671c Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/test.gif differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_pinout.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_pinout.png new file mode 100644 index 0000000..feb1efe Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_pinout.png differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_power.jpg b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_power.jpg new file mode 100644 index 0000000..17656f5 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_power.jpg differ diff --git a/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_power_pins.png b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_power_pins.png new file mode 100644 index 0000000..6714577 Binary files /dev/null and b/blog/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/usb_power_pins.png differ diff --git a/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/d1_mini.jpg b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/d1_mini.jpg new file mode 100644 index 0000000..9111e62 Binary files /dev/null and b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/d1_mini.jpg differ diff --git a/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/d4_ir_recv.png b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/d4_ir_recv.png new file mode 100644 index 0000000..a6bbf8b Binary files /dev/null and b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/d4_ir_recv.png differ diff --git a/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/index.md b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/index.md new file mode 100644 index 0000000..73d3d1b --- /dev/null +++ b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/index.md @@ -0,0 +1,88 @@ +--- +slug: ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome +title: "IR code reader with ESP8266 Wemos D1 mini and ESPHome" +tags: [smart home, Home Assistant, DIY, ESP8266, Wemos D1 Mini, WiFi, ESPHome, IR] +image: /img/blog/2021/01/shield.jpg +--- +Quick step-by-step guide on assembling an IR receiver for reading IR codes from your remotes based on Wemos D1 mini, Wemos IR shield, and using ESPHome. + + + +## Components used + +1. The housing from Broadling RM Pro+ +1. [Wemos D1 mini](https://www.wemos.cc/en/latest/d1/d1_mini.html) development board +1. [Wemos IR shield](https://www.wemos.cc/en/latest/d1_mini_shield/ir.html) +1. USB to micro-USB cable + +## Assembling +First of all, we need to make our shield work with all transmitting LEDs and the pins we need. In this example, we will use `D3` for sending and `D4` for receiving. + +![](d4_ir_recv.png) + +![](shield_contacts_2.png) + +![](shield_contacts_1.png) + +Now lets put the board into the housing with cable connected and glue it all: + +![](d1_mini.jpg) + +Then put the shield on top: + +![](shield.jpg) + +Finally, close the housing: + +![](ready.jpg) + +## Using + +In ESPHome let’s create a config: + +```yaml +esphome: + name: ir_receiver + platform: ESP8266 + board: d1_mini + +wifi: + ssid: "WiFi" + password: "************" + + # Enable fallback hotspot (captive portal) in case wifi connection fails + ap: + ssid: "IR Receiver" + password: "************" + +captive_portal: + +# Enable logging +logger: + level: DEBUG + +# Enable Home Assistant API +api: + password: "************" + +ota: + password: "************" + +remote_receiver: + pin: + number: D4 + inverted: true + dump: + - samsung +``` + +As you can see it is set up to dump only Samsung-specific codes. You can read more about reading other codes on [esphome.io](https://esphome.io/components/remote_receiver.html). Also pay attention on `logger` section. It is set to `DEBUG` level. + +Compile, flash, open logs and start firing into our device with your IR remote. You’ll see something like this: + +``` +[17:34:48][D][remote.samsung:055]: Received Samsung: data=0xE0E007F8 +[17:34:51][D][remote.samsung:055]: Received Samsung: data=0xE0E020DF +``` + +You can now use this data with the ESPHome [Remote Transmitter](https://esphome.io/components/remote_transmitter.html) component to build, for example, something like [this](/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/index.md). \ No newline at end of file diff --git a/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/ready.jpg b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/ready.jpg new file mode 100644 index 0000000..45bf7b7 Binary files /dev/null and b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/ready.jpg differ diff --git a/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield.jpg b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield.jpg new file mode 100644 index 0000000..7b0d827 Binary files /dev/null and b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield.jpg differ diff --git a/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts_1.png b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts_1.png new file mode 100644 index 0000000..c835165 Binary files /dev/null and b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts_1.png differ diff --git a/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts_2.png b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts_2.png new file mode 100644 index 0000000..7249e0c Binary files /dev/null and b/blog/2021-01-15-ir-code-reader-with-esp8266-wemos-d1-mini-and-esphome/shield_contacts_2.png differ diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/action.png b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/action.png new file mode 100644 index 0000000..adc3918 Binary files /dev/null and b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/action.png differ diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/gif.gif b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/gif.gif new file mode 100644 index 0000000..465d772 Binary files /dev/null and b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/gif.gif differ diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/hole.jpg b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/hole.jpg new file mode 100644 index 0000000..c5a3b5d Binary files /dev/null and b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/hole.jpg differ diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/index.md b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/index.md new file mode 100644 index 0000000..26a383a --- /dev/null +++ b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/index.md @@ -0,0 +1,123 @@ +--- +slug: using-stepper-motor-to-control-amplifier-volume-knob-with-esp8266-and-esphome +title: "Using stepper motor to control amplifier volume knob with ESP8266 and ESPHome" +tags: [smart home, Home Assistant, DIY, ESP8266, Wemos D1 Mini, WiFi, ESPHome] +image: /img/blog/2021/01/ext.jpg +--- +My living room multimedia setup consists of numerous devices with varying degrees of stupidity. I’m chasing to improve it adding additional DIY hardware and functionality not always because of hate of TV remotes but also because I’m in love with IoT and soldering. First, I’ve added [WiFi power control to my Cambridge Audio amplifier](/2021-01-13-adding-wifi-power-control-to-an-integrated-amplifier/index.md), then I’ve implemented [WiFi-to-IR remote control to the TV](/2021-01-13-building-wifi-ir-remote-control-for-any-tv-with-esp8266-wemos-d1-mini-and-esphome/index.md). Then I decided to improve sound quality from TV and added a [DAC](https://wikipedia.org/wiki/Digital-to-analog_converter) between the TV and the amplifier. It is connected to the TV via [Toslink](https://wikipedia.org/wiki/TOSLINK) optical cable. And it broke my volume control because you can’t change the volume on a digital output port on a TV, you forced to rotate the knob on amplifier instead. + + + + saw several solutions to this problem. + +1. The easiest, but boring and expensive, is to purchase an improved model of my amplifier with IR remote control. +2. Сheap and the one that looks right is to add a digital potentiometer to the amplifier input and control it with Wemos D1 mini I already have in my amp. +3. Most inaccurate but fancy and the one you will use to impress your family and friends is to add a stepper motor that will rotate the knob for you. + +I think you already guessed the way I choose, so let’s see how I achieved this. + +![](gif.gif) + +## Components +As I already have Wemos D1 mini and a relay in my amplifier, you could see more components than you expect on photos, but, for simplicity, I’ll list only those components used to control the knob in this article. + +1. WEMOS (LOLIN) D1 mini WiFi board ([wemos.cc](https://www.wemos.cc/en/latest/d1/d1_mini.html)) +2. AC-DC 220V to 5V Step-Down Mini Power Supply ([amazon](https://www.amazon.com/HLK-PM01-supply-module-intelligent-household/dp/B07G5GL4B8)) +3. ULN2003 stepper motor driver +4. 5V 28BYJ-48 stepper motor + +### Connections + +- 5V DC power from power supply, 5V pin of Wemos D1 mini and +5V input of motor driver are connected together. +- Ground of the power supply, GND pin of Wemos D1 mini and -5V (ground) of motor driver are also connected together. +- IN1 of motor driver -> D5 on Wemos +- IN2 of motor driver -> D6 on Wemos +- IN3 of motor driver -> D7 on Wemos +- IN4 of motor driver -> D8 on Wemos + +:::note + +At the moment of writing ESPHome supported only two types of stepper motor drivers. See ESPHome [documentation](https://esphome.io/components/stepper/index.html) for more info. + +::: + +## Building +The AC-DC power supply was connected to the AC power input of the amplifier. + +![Power connection](power.png) + +Now to the knob. The knob actually rotates an analog [potentiometer](https://wikipedia.org/wiki/Potentiometer) – a mechanical component with variable resistance. On my amplifier, all potentiometers have a hexagonal-shaped hole on the other side of the rotating element: + +![](hole.jpg) + +This made the connection of the motor as easy as a couple of rasp strokes. I mean the shaft of my motor was slightly bigger than the hole on the potentiometer so I took a rasp and made it smaller. Then I used a couple of plastic racks with nuts and a bunch of hot glue to anchor the motor on amp housing. + +![](shaft.jpg) + +![](motor_top.jpg) + +![](motor_side.jpg) + +I know it is not the best binding but it works. I don’t think this solution is permanent because I relay want to use digital potentiometers instead. I made this more for fun, but currently, this is the only way to remotely control the volume in my living room. Just to give you an opportunity to change your mind before you start a similar project (or, who knows, maybe to improve it) here is a list of issues it currently has: + +- It is impossible to determine the current motor position because its position resets on each boot. +- It is easy to brake reduction gears in motor and even the amp when rotating the potentiometer further than it could. +- It is hard to rotate the knob manually because you need to rotate the motor as well. + +If you are still here lats go to the software part. + +## ESPHome + +ESPHome could rotate your stepper motors with [Stepper Component](https://esphome.io/components/stepper/index.html). Here is my stepper config in ESPHome: + +```yaml +stepper: + - platform: uln2003 + id: volume_motor + pin_a: D5 + pin_b: D6 + pin_c: D7 + pin_d: D8 + sleep_when_done: true + max_speed: 250 steps/s + acceleration: inf + deceleration: inf +``` + +The idea is to change the volume on a given relative amount of motor steps. This will simplify the adjustment to find the right volume step for you. I declared a new service in `api` section of my `amplifier.yaml`: + +```yaml +api: + password: "*************" + services: + - service: set_volume + variables: + target: int + then: + - stepper.report_position: + id: volume_motor + position: 0 + - stepper.set_target: + id: volume_motor + target: !lambda 'return target;' +``` + +It would be exposed in Home Assistant as `esphome.amplifier_set_volume` service and will take the only parameter `target`. So in automation action increasing the volume in my case is looking like this: + +![Automation action](action.png) + +Or in YAML: + +```yaml +service: esphome.amplifier_set_volume +data: + target: 50 +``` + +Decreasing the volume action is the same, but with negative `target`: + +```yaml +service: esphome.amplifier_set_volume +data: + target: -50 +``` \ No newline at end of file diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/motor_side.jpg b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/motor_side.jpg new file mode 100644 index 0000000..22db811 Binary files /dev/null and b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/motor_side.jpg differ diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/motor_top.jpg b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/motor_top.jpg new file mode 100644 index 0000000..7e8fd7b Binary files /dev/null and b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/motor_top.jpg differ diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/power.png b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/power.png new file mode 100644 index 0000000..37dea2c Binary files /dev/null and b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/power.png differ diff --git a/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/shaft.jpg b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/shaft.jpg new file mode 100644 index 0000000..20a11e3 Binary files /dev/null and b/blog/2021-01-15-using-stepper-motor-to-control-amplifier-volume-knob/shaft.jpg differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/001.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/001.png new file mode 100644 index 0000000..ac21288 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/001.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/002.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/002.png new file mode 100644 index 0000000..ea6d80c Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/002.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/003.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/003.png new file mode 100644 index 0000000..e2a47c2 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/003.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/004.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/004.png new file mode 100644 index 0000000..e79cf9d Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/004.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/005.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/005.png new file mode 100644 index 0000000..0595f23 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/005.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/006.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/006.png new file mode 100644 index 0000000..d2216a8 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/006.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/007.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/007.png new file mode 100644 index 0000000..f08ad14 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/007.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/008.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/008.png new file mode 100644 index 0000000..f7752a8 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/008.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/009.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/009.png new file mode 100644 index 0000000..3286ba9 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/009.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/010.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/010.png new file mode 100644 index 0000000..f56ea83 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/010.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/011.png b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/011.png new file mode 100644 index 0000000..f461d55 Binary files /dev/null and b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/011.png differ diff --git a/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/index.md b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/index.md new file mode 100644 index 0000000..e3c708c --- /dev/null +++ b/blog/2023-10-31-hosting-ghost-blog-on-synology-nas/index.md @@ -0,0 +1,122 @@ +--- +slug: hosting-ghost-blog-on-synology-nas +title: Hosting Ghost Blog On Synology NAS +tags: [self-hosting, homelab, Synology NAS, Ghost] +image: /img/blog/2023/10/synonas.webp +--- +Do you want to know how and where RandomPlace is hosted? Or do you just want to know how to host a [Ghost](https://ghost.org) blog on your Synology NAS? I'm here today to answer both questions. + +:::info + +This post is from the past. From far away times when this website had another domain, another name and another hosting place. For current setup, please see [HomeLab](/docs/homelab). + +Still, this guide can be useful. + +::: + + +It's been a long way to my current home lab configuration. There were several Intel NUCs, Nextcloud, and so on, but at the end (or just for now) I have Synology NAS and it allows me to host not only my personal cloud but other services as well. This blog is one of them. + +RandomPlace blog is running in the Docker container. In Synology DSM it is a [Container Manager](https://www.synology.com/en-us/dsm/feature/container-manager) package. To be honest, I'm not a big fan of the everything-in-containers approach. Bare-metal installation is much better in terms of maintainability and flexibility, but it is clear why Docker containers become so popular across our home labs. It is much easier to get something up and running with a single command instead of resolving dependencies and configuring your OS. So when this blog was hosted on Intel NUC with Ubuntu OS, it was not in containers. Now, with a new-for-me DSM software, it is easier to get something up and running with a single command instead of resolving dependencies and configuring my OS =) + +I know there is a way to run NodeJS apps on Synology DSM, but this is something I need to discover. I'm also not sure I'm ready to SSH to my NAS and start to edit system files. Stability is the main reason why I'm currently with Synology. + +Let's get back to our main topic. All further instructions are from DS423+ and DSM 7.2. But I'm sure it would be the same for many other NASes. + +## Prepare + +First of all, we will need a **Container Manager** package to be installed from the Package Center + +![](001.png) + +Then we will need some folders to be created. After installing a Container Manager, you will have a new shared folder created for you: `docker`. A good place to put all your container's data in. We should create a new directory there with any name you want. For example `blog`. This would be the root of our future project. Then, let's create a `content` directory inside it: + +![](002.png) + +Lastly, we will need to know the volume number where our directories are placed. For this open **File Station**, right-click on the docker folder and choose **Properties**. The **Location** property in my case tells me that the docker folder is placed on a `volume1`. + +![](003.png) + +## The Database + +The Ghost requires the MySQL database to work. For the database, we have two options. The first is to have a database as a separate docker container. This option is the simplest. Another one is to use the **MariaDB** Synology package to have a single database service for all your projects. This will require us to install the **phpMyAdmin** as well to create and manage databases and users. This option enables the ability for a simple database backup solution because the **MariaDB** package with all data and settings could be included in **Hyper Backup**. Also, we will avoid having several containers with the same database service in the future. + +With the second option, after installing **MariaDB** and **phpMyAdmin** from the **Package Center** on our NAS, let's log in to **phpMyAdmin** with the root user and password we set upon installation and create a new database for our blog and name it, for example, "my_blog": + +![](004.png) + +Now we will need to create a user for this database. Choose your newly created database on the left and navigate to the **Privileges** tab. You can find the "Add user account" link there. + +Selecting "Any host" for the "Host name" field upon user creation will allow the Ghost container to connect to the database even from the bridged network. But also allows connection from any host within your local network (assuming that you didn't open MySQL port to the public internet which you shouldn't do in any case). + +Don't forget to tick "Grant all privileges on database my\_blog." on the same user creation page. + +![](005.png) + +Hit **Go** in the bottom and we are done here. + +## Create + +Now the time has come to create a new project in **Container Manager**. Launch it, open the **Projects** view from the left, and hit the **Create** button. + +Here we need to give our project a name, choose a previously created path for it, and provide a `docker-compose.yml`. + +![](006.png) + +And here is our `docker-compose.yml`: + +```yaml +version: '3.1' + +services: + ghost: + image: ghost:5.71.0 # Choose the version here: https://hub.docker.com/_/ghost/ + container_name: the_blog_ghost + restart: unless-stopped + ports: + - 43332:2368 # Some random port mapped to a default Ghost port inside container + volumes: + # This is the path to our directory created at the beginning, mapped to a content directory inside the container + - /volume1/docker/blog/content:/var/lib/ghost/content + environment: + database__client: mysql + database__connection__host: 192.168.1.2 #This should be the local IP address of your NAS + database__connection__user: blog_ghost #Database user we've created previously + database__connection__password: '12345' #The strongest password you can imagine + database__connection__database: my_blog #Database name we've created previously + url: https://blog.randomplace.online #Your future blog domain, you definitely already bought +``` + +The next step will allow us to create a web portal for our container on a port we mentioned in `docker-compose.yml` + +![](007.png) + +We should accept this option and hit **Next** and then **Done** to start the container and navigate to a **Web Station** to configure a Web Portal: + +![](008.png) + +Here we need to create a Name-based portal and use our domain as a Hostname. Also, we should force HTTPS (redirect all HTTP requests to a secure HTTPS connection) with the HSTS option: + +![](009.png) + +The last thing we should do is generate a new SSL certificate to serve our blog through HTTPS. + +:::info + +Your domain name should already be pointed to your NAS's public IP address for the certificate generation. + +::: + +Go to **Control Panel - Security** and choose the **Certificate** tab. Here we can request a new free SSL certificate by clicking the Add button and choosing "Add new certificate". + +![](010.png) + +Then "Get a certificate from Let's Encrypt" and fill in some fields: + +![](011.png) + +You'll get an email notification on the address added here when there will be time to renew your free certificate. + +After certificate generation, we should open Settings on the same Certificates tab, find our domain service, and choose the newly generated certificate for it. + +That's it! \ No newline at end of file diff --git a/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/001.png b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/001.png new file mode 100644 index 0000000..524eb83 Binary files /dev/null and b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/001.png differ diff --git a/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/002.png b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/002.png new file mode 100644 index 0000000..684515a Binary files /dev/null and b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/002.png differ diff --git a/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/003.png b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/003.png new file mode 100644 index 0000000..282daec Binary files /dev/null and b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/003.png differ diff --git a/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/004.png b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/004.png new file mode 100644 index 0000000..c8048d7 Binary files /dev/null and b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/004.png differ diff --git a/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/005.png b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/005.png new file mode 100644 index 0000000..5309310 Binary files /dev/null and b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/005.png differ diff --git a/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/index.md b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/index.md new file mode 100644 index 0000000..e025fd6 --- /dev/null +++ b/blog/2023-12-19-monitor-usb-ups-connected-to-synology-nas-in-home-assistant/index.md @@ -0,0 +1,46 @@ +--- +slug: monitor-usb-ups-connected-to-synology-nas-in-home-assistant +title: "Monitor USB UPS connected to Synology NAS in Home Assistant" +tags: [self-hosting, homelab, Synology NAS, UPS, Smart Home, Home Assistant] +image: /img/blog/2023/12/upsha.png +--- +There is a lot of automation you can do with this data, but today I want to write up a short guide on how to safely get the information from the UPS connected to your NAS via USB into the Home Assistant. + + + +There is a lot of automation you can do with this data, but today I want to write up a short guide on how to safely get the information from the UPS connected to your NAS via USB into the Home Assistant. + +:::info + +Your Synology NAS and Home Assistant should be in the same local network, or you'll need an additional network configuration that is not a subject of this post + +::: + +## UPS server +After connecting the UPS to the NAS we need to enable Synology NAS UPS server that will allow other machines to get UPS information over the local network. In your Synology DSM go to _Control Panel -> Hardware & Power -> UPS_ tab. Here you can set up a UPS connected to your NAS via USB (or via SNMP protocol if you have enterprise-grade UPS for data centers). Assuming you did that, it is time to enable the UPS server by checking the _"Enable network UPS server"_ checkbox. + +![](001.png) + +Also, you need to click the _"Permitted Synology NAS Devices"_ button and add your Home Assistant local IP address there: + +![](002.png) + +After that, you need to make sure the port for the UPS server is open in the firewall on your NAS. Go to _Control Panel -> Security -> Firewall_ tab and click the _"Edit rules"_ button. Here you need to edit an existing rule for the _TCP_ protocol that has a list of apps in the _Ports_ column: + +![](003.png) + +In the editing window click the Select button near _"Select from a list of built-in applications"_ and make sure the _UPS server_ is selected: + +![](004.png) + +## Home Assistant integration + +The integration that will allow us to connect to the UPS server on Synology NAS is [Network UPS Tools](https://www.home-assistant.io/integrations/nut/). + +In your Home Assistant go to _Settings -> Devices & services_ and click the _"Add integration"_ button. Search for "nut" there and choose _"Network UPS Tools (NUT)"_. + +![](005.png) + +In the configuration window that appeared you need to set your NAS's local IP address as a _Host_ and leave the _Port_ number unchanged. + +Hit _Submit_ and you are done. \ No newline at end of file diff --git a/docusaurus.config.js b/docusaurus.config.js index 323a523..7c8d67d 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -58,6 +58,8 @@ const config = { type: ['rss', 'atom'], xslt: true, }, + blogSidebarTitle: 'Timeline', + blogSidebarCount: 'ALL', // Useful options to enforce blogging best practices onInlineTags: 'warn', onInlineAuthors: 'warn', diff --git a/src/css/custom.css b/src/css/custom.css index 75f86e2..655e0ae 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -16,6 +16,7 @@ --ifm-code-font-size: 95%; --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1); --ifm-footer-link-hover-color: #b07ab0; + --ifm-link-color: var(--ifm-color-primary-lightest) } /* For readability concerns, you should choose a lighter palette in dark mode. */ @@ -28,4 +29,5 @@ --ifm-color-primary-lighter: #c196c1; --ifm-color-primary-lightest: #d1b2d1; --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3); + --ifm-link-color: var(--ifm-color-primary-darker); } \ No newline at end of file diff --git a/static/img/blog/2021/01/ext.jpg b/static/img/blog/2021/01/ext.jpg new file mode 100644 index 0000000..f490d63 Binary files /dev/null and b/static/img/blog/2021/01/ext.jpg differ diff --git a/static/img/blog/2021/01/shield.jpg b/static/img/blog/2021/01/shield.jpg new file mode 100644 index 0000000..355cec8 Binary files /dev/null and b/static/img/blog/2021/01/shield.jpg differ diff --git a/static/img/blog/2021/01/tv_project.png b/static/img/blog/2021/01/tv_project.png new file mode 100644 index 0000000..262824d Binary files /dev/null and b/static/img/blog/2021/01/tv_project.png differ diff --git a/static/img/blog/2023/10/synonas.webp b/static/img/blog/2023/10/synonas.webp new file mode 100644 index 0000000..a9d467c Binary files /dev/null and b/static/img/blog/2023/10/synonas.webp differ diff --git a/static/img/blog/2023/12/upsha.png b/static/img/blog/2023/12/upsha.png new file mode 100644 index 0000000..ea534a7 Binary files /dev/null and b/static/img/blog/2023/12/upsha.png differ