I’m often looking back at the previous projects thinking, what improvements I could make. I actually have one article about controlling Yeelight Smart Bulb with Amazon Dash button, but it uses a Python script. Since the Amazon Dash button and NodeRED integration is possible, I thought I would rewrite it again, making it much more user-friendly! Oh, and if you are new to NodeRED – Check the Guide for Beginners!
Control Yeelight Smart Bulb with Amazon Dash buttons
First, a quick overview. If you did not use the Amazon Buttons for anything, please know you can intercept the button’s signal and use it for your own purposes. All this as long as you don’t mind about 6 sec delay and a10 sec overall cooldown. I found it to be acceptable as a light toggle. Suits best for a secondary light, like a lamp or similar.
Like previously, I will show you three different control variants. Before I jump to different scenarios let’s establish the lightbulb control in the NodeRED. To control the Yeelight Smart WiFi lights we will need a node:
npm install yeelight-compat-hue-state
Download it via terminal or palette manager. If you want to know more about how to install nodes – see part 2 of my NodeRED guide.
You will notice 2 new nodes. These will work with Philips Hue and Yeelight. Win, win! One node can be used to obtain the current status of the bulb, the other one is used to send the new values to the light bulb. As we are going to create the toggles, we will only focus on sending ON/OFF information.
To send the information to Yeelight lightbulb, you have to open the app and enable the LAN control. This way the lightbulb can receive the commands via the local network. While you at it, check the lightbulb IP address, as this information is needed to configure the Yeelight nodes.
The commands go to the port 55443 then use the IP of the bulb to point the commands to the right direction, add the name for each bulb and the config part is done. Remember, that you will have to do this for each bulb you have.
One Amazon Dash button, one Yeelight bulb
This is the most popular setup. A single Amazon Dash button controls one of the Yeelight bulbs.I’m going to start with obtaining the Yeelight Bulb state every 5 seconds. When the inject node triggers the Yeelight status node, the information about the current values will be updated and sent to the function node. In this example, I’m only interested in the status (on/off) of the lightbulb.
The function node will save the status as a global variable – and I will be able to always retrieve the current state of the bulb. This information will be used later to toggle the opposite state.
global.set("Yeelight", msg.payload.state.on); return msg;
Amazon Dash toggle
When the button is pressed, I’m checking the current status of the light using the function node:
var x = global.get("Yeelight"); msg.yeelight = x; return msg;
The value stored (true/false) can be used in combination with the switch node to send the payload with the opposite value. In the two templates nodes I’m sending the:
{"on":false} /*if true is received*/ {"on":true} /*if false is received*/
This is the format that Yeelight node is expecting.
Multiple Amazon Dash buttons, one Yeelight bulb
If you want to have two toggles placed at the opposite ends of rooms this the way you want to hook up your Amazon Dash buttons with Yeelight Smart bulb. The situation is exactly the same as in the setup above, but this time I have 2 or more Amazon Dash buttons linked to the “Get Last Yeelight state” node. There is no need for other changes.
One Amazon Dash button, multiple Yeelight bulbs
If you have a group, or the room contains more than one Yeelight Bulb you can use the Amazon Dash to toggle more than one bulb at the same time.To complete this setup we have to add 2 more Yeelight nodes. One to read the status, one to control the second light bulb. There are no other changes in the code. The status of both bulbs is written to the global variable, so the Amazon Dash will toggle both lights based on the last performed action. If one of the bulbs has been turned off lately, the button will light both bulbs up.
Conclusion
As you can see, linking multiple buttons is super easy. You could also use the Amazon Dash button so preset specific colour, state and brightness if you prefer. Just change up the message submitted to the node.
Project Download
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.