Led strips are really cool. There is something about the light and the thing that you are in control of 60 small leds. And they are very inexpensive now to. I wanted to try them together with home assistant. I have based this post on the work done by Bruh. However some things has changed since he did his video. I had problems to get this working and it was hard to find the needed information on one place on the internet. Therefor I wrote this.
The original video is found here
When done you will have a ledstrip connected with MQTT and it is controlled within Home Assistant.
So lets get started. I have used the following:
Hardware
Software
- Cloud MQTT broker
- Home Assistant
- Arduino sketch
Start by connecting the hardware. I have connected it like below. Note that I am no expert whatsoever in electronics. The colors may be wrong. You may also want to use a resistor before the first led in order to prevent spikes.
I had huge problems understanding why it behaved so strange with all the colors first. It was connected to my computer USB then. After putting a cable to GRN from the NodeMcu and using a separate power supply instead of it beeing conncted to my computer solved the problems.
It might also be possible to convert the 5v to 3v and power the nodemcu by the 5v adapter but I am happy with two power supplies.
Next up is the software and setting up the Nodemcu. The first thing you will have to do is to download the Arduino software. This is described in many places but there are some things you should do.
- Check The board
- Check the PORT (check your devicemanager)
- Check the libraries in the top of the code. Choose tools-manage libraries and add them. I had problems with some new libraries and used some older. Test.
I have modified some things and used this sketch. The thing you should change is:
WIFI and MQTT Information (type your info here)
define NUM_LEDS 120 (Count your leds)
define DATA_PIN 5 (The datapin on your Nodemcu)
define CHIPSET WS2812B (This is the model of your ledstrip. Migt be WS2811 or similar)
define COLOR_ORDER GRB (This will cause confusion and strange behavior if wrong. Try RGB, BRG or GRB)
Ok, On to Home Assistant. Add the following to your configuration.yaml
mqtt: broker: m11.cloudmqtt.com port: 11111 username: !secret mqttcloud_user password: !secret mqttcloud_password light: - platform: mqtt_json name: "Led Strip" state_topic: "planet4/led" command_topic: "planet4/led/set" effect: true effect_list: - bpm - candy cane - confetti - cyclon rainbow - dots - fire - glitter - juggle - lightning - noise - police all - police one - rainbow - rainbow with glitter - ripple - sinelon - solid - twinkle brightness: true flash: true rgb: true optimistic: false qos: 0 input_number: led_animation_speed: name: Led Animation Speed initial: 150 min: 1 max: 150 step: 10 automation: - alias: "Led Animation Speed" initial_state: True hide_entity: False trigger: - platform: state entity_id: input_number.led_animation_speed action: - service: mqtt.publish data_template: topic: "planet4/led/set" payload: '{"transition":{{ trigger.to_state.state | int }}}'
Depending if you use groups.yaml you may want to add the entities here as well-
Now restart Home Assistant. If successfull you should be able to control the leds like below!