Migrate more blog posts
After Width: | Height: | Size: 55 KiB |
@ -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.
|
||||||
|
|
||||||
|
<!-- truncate -->
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Let’s draw!
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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.
|
After Width: | Height: | Size: 594 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 135 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 142 KiB |
After Width: | Height: | Size: 198 KiB |
After Width: | Height: | Size: 424 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 400 KiB |
After Width: | Height: | Size: 202 KiB |
@ -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.
|
||||||
|
|
||||||
|
<!-- truncate -->
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Now we will take a look at our TV from the inside.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
You need to be careful detecting 5V and Ground pins on the USB port. Here is a little help:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Our power supply is ready:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### The board
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
:::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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
Also, we don’t need such long pin legs so we can shorten it with wire cutters.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
So the overall picture is looking like this:
|
||||||
|
|
||||||
|

|
After Width: | Height: | Size: 198 KiB |
After Width: | Height: | Size: 337 KiB |
After Width: | Height: | Size: 270 KiB |
After Width: | Height: | Size: 893 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 344 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 215 KiB |
After Width: | Height: | Size: 152 KiB |
After Width: | Height: | Size: 179 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 965 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 7.7 MiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 679 KiB |
After Width: | Height: | Size: 424 KiB |
After Width: | Height: | Size: 139 KiB |
After Width: | Height: | Size: 424 KiB |
@ -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.
|
||||||
|
|
||||||
|
<!-- truncate -->
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Now lets put the board into the housing with cable connected and glue it all:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Then put the shield on top:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Finally, close the housing:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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).
|
After Width: | Height: | Size: 177 KiB |
After Width: | Height: | Size: 133 KiB |
After Width: | Height: | Size: 462 KiB |
After Width: | Height: | Size: 418 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 2.5 MiB |
After Width: | Height: | Size: 182 KiB |
@ -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.
|
||||||
|
|
||||||
|
<!-- truncate -->
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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
|
||||||
|
```
|
After Width: | Height: | Size: 134 KiB |
After Width: | Height: | Size: 203 KiB |
After Width: | Height: | Size: 383 KiB |
After Width: | Height: | Size: 148 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/001.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/002.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/003.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/004.png
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/005.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/006.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/007.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/008.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/009.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/010.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/011.png
Normal file
After Width: | Height: | Size: 27 KiB |
122
blog/2023-10-31-hosting-ghost-blog-on-synology-nas/index.md
Normal file
@ -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.
|
||||||
|
|
||||||
|
:::
|
||||||
|
<!-- truncate -->
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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":
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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`
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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".
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Then "Get a certificate from Let's Encrypt" and fill in some fields:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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!
|
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 37 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 17 KiB |
@ -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.
|
||||||
|
|
||||||
|
<!-- truncate -->
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Also, you need to click the _"Permitted Synology NAS Devices"_ button and add your Home Assistant local IP address there:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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)"_.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
@ -58,6 +58,8 @@ const config = {
|
|||||||
type: ['rss', 'atom'],
|
type: ['rss', 'atom'],
|
||||||
xslt: true,
|
xslt: true,
|
||||||
},
|
},
|
||||||
|
blogSidebarTitle: 'Timeline',
|
||||||
|
blogSidebarCount: 'ALL',
|
||||||
// Useful options to enforce blogging best practices
|
// Useful options to enforce blogging best practices
|
||||||
onInlineTags: 'warn',
|
onInlineTags: 'warn',
|
||||||
onInlineAuthors: 'warn',
|
onInlineAuthors: 'warn',
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
--ifm-code-font-size: 95%;
|
--ifm-code-font-size: 95%;
|
||||||
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
|
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
|
||||||
--ifm-footer-link-hover-color: #b07ab0;
|
--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. */
|
/* For readability concerns, you should choose a lighter palette in dark mode. */
|
||||||
@ -28,4 +29,5 @@
|
|||||||
--ifm-color-primary-lighter: #c196c1;
|
--ifm-color-primary-lighter: #c196c1;
|
||||||
--ifm-color-primary-lightest: #d1b2d1;
|
--ifm-color-primary-lightest: #d1b2d1;
|
||||||
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
|
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
|
||||||
|
--ifm-link-color: var(--ifm-color-primary-darker);
|
||||||
}
|
}
|
BIN
static/img/blog/2021/01/ext.jpg
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
static/img/blog/2021/01/shield.jpg
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
static/img/blog/2021/01/tv_project.png
Normal file
After Width: | Height: | Size: 893 KiB |
BIN
static/img/blog/2023/10/synonas.webp
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
static/img/blog/2023/12/upsha.png
Normal file
After Width: | Height: | Size: 13 KiB |