Deprecated: Function jetpack_form_register_pattern is deprecated since version jetpack-13.4! Use Automattic\Jetpack\Forms\ContactForm\Util::register_pattern instead. in /var/www/html/wp-includes/functions.php on line 6078
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6078) in /var/www/html/wp-includes/feed-rss2.php on line 8
Unfortunately, flashing the newer ESP32 devices is a bit more of a pain than the good ol days of the ESP8266 (RIP ). While trying to flash this device my typical go-to method was to use the recently deprecated esphome-flasher. However, it doesn’t work. Per the directions in the chart below, you should be in Device Firmware Upgrade (DFU) Mode, but this did not help me. Ultimately, I was able to flash it via CLI using the trusty esptool.py. I used a modern FW build from ESPHome. The command that worked for me was the following: Typical lighting circuits for homes in the United States are 120V AC. While this standard makes sense from a historical perspective, it’s maybe not the best idea going forward. Here I’ll outline my thoughts on why you might want to consider using Low Voltage Direct Current LV DC lighting. Prior to the proliferation of LEDs, lighting circuits used a lot of power. It was common to have high wattage circuits like 6-10x 100W can lights or a chandelier with 20x 60w candelabra bulbs. These incandescent bulbs would easily be supported by a 120V AC power over the 14 gauge wiring in the home as required by typical 15A lighting circuits. With the introduction and standardization of LEDs, the lighting loads have dropped significantly. A decrease of 90% is relatively common for a similar light output. My outdoor lights used to be 240W, and with LEDs that dropped to 12W, a reduction of 95%. Given these much lower loads, here are some reasons LV DC lighting for your home In future posts, I will go through my process for designing, building and installing LV DC lighting and controlling them through Home AssistantSuccess
esptool.py --port /dev/tty.usbmodem01 write_flash --flash_mode dio --flash_size 4MB 0x0 /path_to_file/esphome-s2-mini-test-factory.bin
]]>Back story
So?
So…?
What now?
After I updated to a more recent version of ESPHome and flashed my fan controller, it stopped being able to control the fan. After a bit of troubleshooting and searching, I found the culprit.
Clearly, I don’t read all of the release notes…
So after reading this, I was confused. And if you’re here, you are probably confused. So here’s what I did to solve it. In my case, I used the python3 command line inside of my ESPHome docker container, but this should work anywhere you have python3 installed.
python3
bin(<value>)
and replace value with the hex or decimal value.abc
becomes cba
, the 0b
stays at the front.hex(0b<value>)
and replace value with the reversed binary.command
.Below are the steps I used to convert my Fan Oscillation values:
- platform: template name: Fan Oscillation turn_on_action: remote_transmitter.transmit_nec: address: 255 command: 25245
root@cbd65cf7857e:/config# python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> bin(255)
'0b11111111'
>>> # 11111111 reversed is 11111111
>>> # 11111111 is 8 digits, so add eight zeros to the end = 1111111100000000
>>> hex(0b1111111100000000)
'0xff00'
>>>
>>>
>>>
>>>
>>> bin(25245)
'0b110001010011101'
>>> # 110001010011101 reversed is 101110010100011
>>> # 101110010100011 is 15 digits, so add one zero to the end = 1011100101000110
>>> hex(0b1011100101000110)
'0xb946'
So the new command is:
- platform: template name: Fan Oscillation turn_on_action: remote_transmitter.transmit_nec: address: 0xFF00 command: 0xB946]]>
Initially, I wanted to see how I could scale the ability of controlling LED lights. Analog LED strip lights were about 7 bucks for 15 ft from China and recessed lights were about the same. More importantly, being that these lights are LEDs, they very efficient especially when driven and 60%-80% of their max rating. So I went online and ordered a dozen LED recessed lights, LED strips, and some COB LEDs which are inside of the recessed lights.
My plan was to hook the LEDs up to 24vDC and see how they worked. For the LED strips, it was easy as you can order them in 24v flavor. But the recessed lights are all powered by little LED drivers that are 110/220 to 24v. I first started by burning up a few of the COB LEDs to see what they could take. It turns out the larger COBs did fine with 24v but the smaller ones burned up. Driving two of the smaller ones in series worked fine.
At this point, I had used and flashed a few H801‘s to control analog RGBW strips. While the H801 is nice little package, it had a habit of ringing at certain PWM frequencies. Combine that with the fact that it was using an ESP8266 software PWM to drive the FETs left room for improvement.
Since this was my first foray into controlling analog LEDs, I wanted to see what I could achieve from off-the-shelf components. The key was to drive the LED with a good PWM driver at a high enough frequency that made them work well. I already had a few dozen Wemos D1 Mini, but decided to try a servo controller for the PWM generator and tie it to a MOSFET. Here is the hardware I used:
To my surprise, this setup worked flawlessly on the workbench. For a few months, I used this in my garage to see if it was going to be short-lived, but it just kept working. Initially, I powered these via a bench power supply and later moved the setup over to the DIN Rail PS above. Keep in mind, your power supply should be sized for the load you plan on powering with some headroom.
Pulse Width Modulation allows you to control the brightness of the LEDs. The way that you control an LED’s brightness is by turning it ON and OFF, many times per second (this is called PWM frequency). The longer that the LED stays ON, compared to OFF, the brighter the LED will light (this is called PWM duty cycle). In this circuit, the PCA9685 is the PWM generator. For example, the Wemos D1 controller will tell the PCA9685 to turn on channel 1 at 50% duty cycle. The PCA will then pulse that channel at half ON and half OFF based on the frequency you’ve configured for the module. This pulse is an output from the PCA and is wired up to the gate pin of an N channel MOSFET. This device will then act as the switch that turns the LED on and off.
The key thing to understand about the wiring is that the Wemos D1 mini and PCA9685 are not 24v tolerant. If you put 24v on them, you will release the magic blue smoke. So, just make sure before you turn it on, you double-check your wiring that you’re only run 5v to these devices.
One PCA9685 has 16 channels and each MOSFET module has 4 channels. This means you can go up to 4x MOSFET modules for one PCA9685. I have some channels that are running 4 and 6 recessed LEDs, and many that are running a single recessed LED. This gives you a lot of flexibility in how you wire your lights giving you much more control of your lights.
The wire types that you use are up to you. It’s important to select the correct wire for the LEDs based on the current draw and the distance you’re running. My longest wire are about 40 feet and there I used bell wire. For shorter 20ft runs with only one light I used cheap CAT6. The wires between the Wemos, PCA, and MOSFET were either dupont or servo extension.
As you probably would have guessed, I used the trusty ESPHome project to create the firmware for the Wemos D1. This is pretty straightforward to configure. as you configure the PCA9685 as outputs per the documentation, and then just tie your lights to those outputs to lights.
substitutions: platform: ESP8266 board: d1_mini device_name: esphome_lvrc friendly_name: "LVRC" reboot_timeout_wifi: 900s reboot_timeout_api: 1800s output_power: 17dB gamma_correction: '1.6' led_max_power: '0.85' esphome: platform: ${platform} board: ${board} name: ${device_name} build_path: ./build/${device_name} wifi: ssid: !secret wifi_iot_ssid password: !secret wifi_iot_pwd fast_connect: on reboot_timeout: ${reboot_timeout_wifi} output_power: ${output_power} ap: ssid: "AP_${friendly_name}" password: !secret wifi_backup_pwd api: reboot_timeout: ${reboot_timeout_api} ota: web_server: port: 80 logger: captive_portal: switch: - platform: restart name: "${friendly_name} REBOOT" text_sensor: - platform: version name: "${friendly_name} ESPHome Version" i2c: - id: bus_a scl: D1 sda: D2 frequency: 100kHz scan: True pca9685: i2c_id: bus_a address: 0x40 frequency: 1000 output: - platform: pca9685 id: 'pca9685_output0' channel: 0 inverted: False max_power: ${led_max_power} - platform: pca9685 id: 'pca9685_output1' channel: 1 inverted: False max_power: ${led_max_power} - platform: pca9685 id: 'pca9685_output2' channel: 2 inverted: False max_power: ${led_max_power} - platform: pca9685 id: 'pca9685_output3' channel: 3 inverted: False max_power: 0.70 - platform: pca9685 id: 'pca9685_output4' channel: 4 inverted: False max_power: 0.70 light: - platform: monochromatic output: pca9685_output0 name: "Entry Outdoor" default_transition_length: 1s restore_mode: ALWAYS_OFF gamma_correct: ${gamma_correction} - platform: monochromatic output: pca9685_output1 name: "Entry Indoor" default_transition_length: 1s restore_mode: ALWAYS_OFF gamma_correct: ${gamma_correction} - platform: monochromatic output: pca9685_output2 name: "Foyer Hall" default_transition_length: 1s restore_mode: ALWAYS_OFF gamma_correct: ${gamma_correction} - platform: monochromatic output: pca9685_output3 name: "Stairs" default_transition_length: 1s restore_mode: ALWAYS_OFF gamma_correct: ${gamma_correction} - platform: monochromatic output: pca9685_output4 name: "Dining Outer" default_transition_length: 1s restore_mode: RESTORE_DEFAULT_OFF gamma_correct: ${gamma_correction}
The components above include
I did some searching and found a good write up by SparkFun that walked you through a way of achieving it. Basically, you can leverage the sin function’s smooth output and appropriately scale/offset that output to drive your LED output.
The code below is running on my dining room switch as a lighting effect on a single pixel of WS2812. I’ve included some comments to help understand some of the pieces and how you can tailor it for your application.
light: - platform: fastled_clockless chipset: WS2812B pin: GPIO2 num_leds: 1 rgb_order: GRB name: "${friendly_name} LED" id: status_led effects: - lambda: name: Pulse RED // SPEED update_interval: .05s lambda: |- static float in = 0; static float out = 0; // Scale sin output from -1/1 to 0/1 out = sin(in) * 0.5 + 0.5; auto call = id(status_led).turn_on(); call.set_transition_length(100); // COLOR + BRIGHTNESS call.set_rgb(1.0, 0.0, 0.0); call.set_brightness(out); // Do not publish state to eliminate flooding of logs call.set_publish(false); call.set_save(false); call.perform(); // RESOLUTION in += 0.314; if (in > 6.283) in = 0;
Here’s what it looks like in action:
]]>For me, most of these devices are ESP8266s in some type of smart home gadget. To identify the pins, I’ve created two firmware configs. The first has all of the pins set as binary inputs and the second has all of the pins set as switches. I’ve provided the code for the firmware and precompiled bin files.
The code below is used for both versions of the firmware, I just comment out the conflicting parts. For those that want it the easy way, here are the precompiled versions:
substitutions: platform: ESP8266 board: esp01_1m device_name: esphome_new_device_assistant friendly_name: "ESPHome New Device Assistant" reboot_timeout_wifi: 90s reboot_timeout_api: 1800s output_power: 17dB esphome: platform: ${platform} board: ${board} name: ${device_name} esp8266_restore_from_flash: true wifi: ssid: esphomeesphome password: esphomeesphome fast_connect: on reboot_timeout: ${reboot_timeout_wifi} output_power: ${output_power} ap: ssid: "ESPHome New Device Assistant" password: "esphomeesphome" api: reboot_timeout: ${reboot_timeout_api} ota: web_server: port: 80 logger: captive_portal: ################################# switch: # - platform: gpio # name: "${friendly_name} GPIO0" # pin: # number: GPIO0 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO1" # pin: # number: GPIO1 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO2" # pin: # number: GPIO2 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO3" # pin: # number: GPIO3 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO4" # pin: # number: GPIO4 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO5" # pin: # number: GPIO5 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO9 - DO NOT USE!!" # pin: # number: GPIO9 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO10 - DO NOT USE!!" # pin: # number: GPIO10 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO12" # pin: # number: GPIO12 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO13" # pin: # number: GPIO13 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO14" # pin: # number: GPIO14 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO15" # pin: # number: GPIO15 # mode: OUTPUT # inverted: True # - platform: gpio # name: "${friendly_name} GPIO16" # pin: # number: GPIO16 # mode: OUTPUT # inverted: True ## REBOOT SWITCH - platform: restart name: "${friendly_name} REBOOT" binary_sensor: - platform: gpio name: "${friendly_name} GPIO0" pin: number: GPIO0 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO1" pin: number: GPIO1 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO2" pin: number: GPIO2 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO3" pin: number: GPIO3 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO4" pin: number: GPIO4 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO5" pin: number: GPIO5 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO9 - DO NOT USE!!" pin: number: GPIO9 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO10 - DO NOT USE!!" pin: number: GPIO10 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO12" pin: number: GPIO12 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO13" pin: number: GPIO13 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO14" pin: number: GPIO14 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO15" pin: number: GPIO15 mode: INPUT_PULLUP inverted: True - platform: gpio name: "${friendly_name} GPIO16" pin: number: GPIO16 mode: INPUT_PULLUP inverted: True]]>
While my subwoofer’s power switch has an auto setting that is only supposed to turn on the amp when it’s getting signal from the receiver, this never really worked. And as we rearranged the room, it’s new location did not allow it to be wired into the receiver’s builtin switched receptacle. Thus, I needed a way to remotely control the sub being on or off.
The Sonoff Basic is perfect for this job as you are switching 120v for the subwoofer’s power. It does not matter which version of the Sonoff Basic you use (Original, R2, or R3) as they will perform the same here. I have a half dozen R2s that came as part of a bulk order, so that’s what I used. Splicing the Sonoff into the subwoofer’s power cable was very straight forward. All you have to do is cut the cable and insert the Sonoff in the middle, with the plug side of the cable wired to the input side of the Sonoff and the subwoofer side to the output side.
I chose to take a step further by disassembling my subwoofer and installing the Sonoff inside of the subwoofer. This means it’s spliced on the power cable after the cable enters the subwoofer. I used a couple of strong zip ties to mount the Sonoff, in its enclosure, to one of the sub’s metal components.
The overall process is to flash this unit with custom firmware that tightly integrated to Home Assistant. To get the unit converted from the original firmware, I used a USB FTDI converter combined with ESPHome to get this accomplished. If you are not familiar with this process, JuanMTech and many others have great detailed steps for this part. Head over to your ESPHome dashboard and create a new device. Paste the YAML below into the device configuration:
substitutions: platform: ESP8266 board: esp01_1m device_name: esphome_subwoofer friendly_name: "Subwoofer" reboot_timeout_wifi: 900s reboot_timeout_api: 1800s output_power: 17dB # <<: !include z_common.yaml esphome: platform: ${platform} board: ${board} name: ${device_name} esp8266_restore_from_flash: true wifi: ssid: !secret wifi_iot_ssid password: !secret wifi_iot_pwd fast_connect: on reboot_timeout: ${reboot_timeout_wifi} output_power: ${output_power} ap: ssid: "AP_${friendly_name}" password: !secret wifi_backup_pwd api: reboot_timeout: ${reboot_timeout_api} ota: web_server: port: 80 logger: captive_portal: binary_sensor: - platform: gpio pin: number: GPIO0 mode: INPUT_PULLUP inverted: True id: sonoff_button internal: true on_press: - switch.toggle: sonoff_relay switch: - platform: restart name: '${friendly_name} REBOOT' - platform: gpio name: "${friendly_name} Power" icon: "mdi:speaker" id: sonoff_relay pin: number: GPIO12 restore_mode: ALWAYS_ON status_led: pin: number: GPIO13 inverted: True text_sensor: - platform: version name: ${friendly_name} ESPhome Version
Now, go to the Home Assistant Integrations page (Configuration>Integrations). You should see the ESPHome device show up in the discovered section after a minute or two. Click configure, and submit, and that’s it. Alternatively, you can manually add the device by clicking “CONFIGURE” on the ESPHome integration and entering “<NODE_NAME>.local” as the host.
Once the device is added, it will be in the lower part of this page (under Configured). Clicking through to the device will show you the entity names that are auto-magically created by the ESPHome integration.
Now, you cannot be expected to have to switch on the subwoofer through Home Assistant like a barbarian! So my fix for this is to automate it with the state of my receiver’s power. This is a very easy automation to create in Node-RED, my automation engine for Home Assistant.
This automation is looking for any messages about the on/off state of my receiver (media_player.rx_v675) and then outputs that state through an on/off switch (splitter). If the receiver state becomes on, the flow calls to turn on the subwoofer switch to on. You can copy and paste the JSON flow below to import it into your Node-RED instance.
[{"id":"cf3c6f80.3beae","type":"server-state-changed","z":"57657673.d86dd8","name":"Receiver state","server":"c75798f0.9eb148","version":1,"entityidfilter":"media_player.rx_v675","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":120,"y":890,"wires":[["67b8934a.8ffaec"]]},{"id":"67b8934a.8ffaec","type":"switch","z":"57657673.d86dd8","name":"on / off","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":890,"wires":[["2e23fe27.8fa362"],["6b0f2645.bdd0a8"]]},{"id":"2e23fe27.8fa362","type":"api-call-service","z":"57657673.d86dd8","name":"Turn on sub","server":"c75798f0.9eb148","version":1,"service_domain":"homeassistant","service":"turn_on","entityId":"switch.subwoofer_power","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":580,"y":860,"wires":[[]]},{"id":"6b0f2645.bdd0a8","type":"api-call-service","z":"57657673.d86dd8","name":"Turn off sub","server":"c75798f0.9eb148","version":"1","service_domain":"homeassistant","service":"turn_off","entityId":"switch.subwoofer_power","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":580,"y":920,"wires":[[]]},{"id":"c75798f0.9eb148","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
I had some initial concerns that the Sonoff would be subjected to stress/interference that could make it work incorrectly or breakdown faster. However, after making this modification last May, I’ve had zero issues with this setup. It just works. If you’ve got any questions, feel free to ping me below.
]]>I have used a Teckin and Tunbox (white or black), but there are many manufacturers that seem to brand label the same physical product. The key is that the description needs to mention the “Smart Life” app as that means it’s using the Tuya WiFi module.
The overall process is to flash this unit with custom firmware that tightly integrated to Home Assistant. To get the unit converted from the original firmware, I used Tuya Convert combined with ESPHome to get this accomplished. If you are not familiar with these, digiblurDIY and DrZzs both have extensive videos on how to get started with these. I will cover the detailed configuration for these power strips.
The configuration I’ve set up for this device is focused on keeping the power on, as typically you do not want to shut it off accidentally. So, the physical button on the unit only toggles the USB power and all power sockets default to being ON when it’s plugged in or power is restored. The only way to control the power sockets is through the device’s webpage or Home Assistant.
Follow the guides linked above to flash your power strip via the tuya convert method. Then create a new device in ESPHome and load the YAML below to this device.
substitutions: board: esp01_1m device_name: esphome_homelab_powerstrip friendly_name: Homelab Powerstrip 1 esphome: name: ${device_name} platform: ESP8266 board: ${board} wifi: ssid: !secret wifi_iot_ssid password: !secret wifi_iot_pwd fast_connect: on ap: ssid: !secret wifi_backup_ssid password: !secret wifi_backup_pwd reboot_timeout: 0s api: ota: web_server: port: 80 logger: switch: - platform: gpio name: "${friendly_name} Socket 1" icon: mdi:power-socket-us id: relay1 pin: number: GPIO4 inverted: True restore_mode: RESTORE_DEFAULT_ON on_turn_on: - switch.turn_on: red_led on_turn_off: - if: condition: and: - switch.is_off: relay2 - switch.is_off: relay3 - switch.is_off: relay4 then: - switch.turn_off: red_led - platform: gpio name: "${friendly_name} Socket 2" icon: mdi:power-socket-us id: relay2 pin: number: GPIO13 inverted: True restore_mode: RESTORE_DEFAULT_ON on_turn_on: - switch.turn_on: red_led on_turn_off: - if: condition: and: - switch.is_off: relay1 - switch.is_off: relay3 - switch.is_off: relay4 then: - switch.turn_off: red_led - platform: gpio name: "${friendly_name} Socket 3" icon: mdi:power-socket-us id: relay3 pin: number: GPIO12 inverted: True restore_mode: RESTORE_DEFAULT_ON on_turn_on: - switch.turn_on: red_led on_turn_off: - if: condition: and: - switch.is_off: relay1 - switch.is_off: relay2 - switch.is_off: relay4 then: - switch.turn_off: red_led - platform: gpio name: "${friendly_name} Socket 4" icon: mdi:power-socket-us id: relay4 pin: number: GPIO14 inverted: True restore_mode: RESTORE_DEFAULT_ON on_turn_on: - switch.turn_on: red_led on_turn_off: - if: condition: and: - switch.is_off: relay1 - switch.is_off: relay2 - switch.is_off: relay3 then: - switch.turn_off: red_led - platform: gpio name: "${friendly_name} USB Ports" icon: mdi:usb id: relay5 pin: number: GPIO16 inverted: False restore_mode: RESTORE_DEFAULT_ON - platform: gpio internal: true id: red_led pin: number: GPIO3 inverted: True - platform: restart name: '${friendly_name} REBOOT' binary_sensor: - platform: gpio pin: number: GPIO5 mode: INPUT_PULLUP inverted: False internal: true on_press: - switch.toggle: relay5 status_led: id: blue_led pin: number: GPIO0 inverted: True text_sensor: - platform: version name: ${friendly_name} ESPhome Version
At first, I did not want to display these in my lovelace UI because I was worried about fat fingering something by accident. Then, I discovered the Toggle Lock Entity Row plugin developed by Thomas Loven. The easiest method for installing this is to utilize HACS (Home Assistant Community Store) – if you don’t have it, get it…now. This plugin prevents accidental switching by requiring a secondary click within 5 seconds in order to turn off the device.
In my instance, I have chosen to name the entities generically via the firmware and add the label in lovelace.
- type: entities show_header_toggle: false title: HomeLAB Powerstrip 1 entities: - entity: switch.homelab_powerstrip_1_socket_1 name: Modem type: custom:toggle-lock-entity-row - entity: switch.homelab_powerstrip_1_socket_2 name: UniFi USG type: custom:toggle-lock-entity-row - entity: switch.homelab_powerstrip_1_socket_3 name: UniFi Switch type: custom:toggle-lock-entity-row - entity: switch.homelab_powerstrip_1_socket_4 name: Dell R210 type: custom:toggle-lock-entity-row - entity: switch.homelab_powerstrip_1_usb_ports name: UniFi Console Pi type: custom:toggle-lock-entity-row
One of the concerns I initially had with this setup was the relays. Since these are going to be on 99.9% of their life, the coil will be energized all of that time. I couldn’t find a coil life listed anywhere from the manufacturer of the Y3F-SS-105DM. After some googling, it appears for DC coils, this is a somewhat negligible concern as they will run very cool. My power strip has been on since April 2018 without issues.
If you’ve got any questions, feel free to ping me below.
]]>Following up on my previous post of the Cheap and Easy series, I’m going to show you how you can control 8 relay channels for about 25 bucks and in about 30 minutes. If you’re not familiar with Home Assistant or ESPHome, check out my previous post.
In this project, I use a Wemos D1 Mini as the wifi enable the controller to interface with the relay module using the IO expansion shield. The magic of this setup is using the IO module and soldering it directly onto the relay board. This eliminates the narly mess you see you when would typically have 8 channels of relays. As a bonus, since you are only using 8 of the available 16 channels on the IO module, you could use the remaining 8 IO to do all sorts of other things.
You will need to provide 5v DC power to power the system. To get started, you will want to place the IO module over the pins of the relay module. Make sure to line these up correctly as I’ve indicated below. If you don’t, it’s a big pain to remove it and put it back on correctly, especially if you’ve soldered it in place. Ask me how I know.
The IO module will have a total of 4 wires connected to it: two for +5v and GND from the power supply, and two for the I2C (SDA and SCL) from the Wemos.
The IO module will have a total of 4 wires connected to it: two for +5v and GND from the power supply, and two for the I2C (SDA and SCL) from the Wemos.
That’s it!
Since it’s likely that you will want to switch/power things that are of higher voltage than the 5v rail you need to power the Wemos, I’ve included the 12v and 24v optional power supplies. Be sure that you do not connect any of these higher voltages to any of the logic pins on the Wemos or the IO, only connect them to the relay output terminals.
I created the 8 channels as output switches and for the time being omitted the remaining 8 channels which can be configured as inputs or outputs. I created a new device, named it esphome_relay_board using a D1 mini board with the following config:
esphome: name: esphome_relay_board platform: ESP8266 board: d1_mini wifi: ssid: 'insert' password: 'your_own' fast_connect: on api: ota: web_server: port: 80 logger: i2c: sda: D1 scl: D2 scan: True mcp23017: - id: 'mcp23017_hub' address: 0x20 switch: - platform: restart name: "Relay Channel Board REBOOT" - platform: gpio name: relay_channel_1 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 15 mode: OUTPUT inverted: True - platform: gpio name: relay_channel_2 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 14 mode: OUTPUT inverted: True - platform: gpio name: relay_channel_3 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 13 mode: OUTPUT inverted: True - platform: gpio name: relay_channel_4 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 12 mode: OUTPUT inverted: True - platform: gpio name: relay_channel_5 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 11 mode: OUTPUT inverted: True - platform: gpio name: relay_channel_6 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 10 mode: OUTPUT inverted: True - platform: gpio name: relay_channel_7 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 9 mode: OUTPUT inverted: True - platform: gpio name: relay_channel_8 icon: mdi:electric-switch pin: mcp23xxx: mcp23017_hub number: 8 mode: OUTPUT inverted: True status_led: id: status_led pin: number: GPIO2
The components above include
Now can compile the firmware and flash it to your Wemos D1. Again, if you’re not familiar with how to do this, reference the videos linked above. Once it’s flashed, power cycle the device. Now you should be able to open the web GUI for the device by either going to it’s IP or going to http://esphome_relay_board.local in your browser, or whatever you named it. When the page loads up, you should test out the relay switches by hitting the button next to them.
Now to integrate it into Home Assistant, you will need to go to configuration > integrations. Assuming you have discovery enabled, you will have a new ESPHome device, click configure and add it to your system. If you don’t have any existing conflicting entities, your entity names should match the ones I have. I’m using the following config for lovelace:
- type: entities title: Garage Relay Module + IO show_header_toggle: false entities: - switch.relay_channel_1 - switch.relay_channel_2 - switch.relay_channel_3 - switch.relay_channel_4 - switch.relay_channel_5 - switch.relay_channel_6 - switch.relay_channel_7 - switch.relay_channel_8 - switch.garage_relay_module_reboot
This provides you with a simple switch list. Each icon shows you the state of the relay. And lastly, you get the reset switch to reset the ESP.
]]>