WLED with Smarthings

Been reading up a lot on w2812 light strips and watched a few great videos where people have used a NODEMCU running WLED (https://github.com/Aircoookie/WLED/releases) to control many different varations.

Just wondered if anyone else is using this and managed to get it hooked up to ST?

Copy/paste into your IDE…
I made it very simple, on/off, level and color.
I personally do not need all the effects etc…I just needed WLED to be controlled from Google Home and Home Assistant! Works perfectly.

   metadata {
	definition (name: "WLED", namespace: "Damien", author: "Damien") {
		capability "Switch"
		capability "Switch Level"
		capability "Light"
		capability "Color Control"
		
        command "on"
		command "off"
        command "setColor"
		command "setLevel"

		attribute "color", "String"
		attribute "level", "Number"

	}

	simulator {

	}
	
	tiles (scale: 2) { 
    // void controlTile(String tileName, String attributeName, String controlType [, Map options, Closure closure])
            standardTile("switch", "device.switch", width: 3, height: 2, canChangeIcon: true) {
            state "on", label:'${name}', action:"off", icon:"st.switches.light.on", backgroundColor:"#00a0dc"
            state "off", label:'${name}', action:"on", icon:"st.switches.light.off", backgroundColor:"#ffffff"
		}
		//BRIGHTNESS
     		controlTile("level", "level", "slider",  width: 3, height: 2, inactiveLabel: false,range:"(0..255)" ) {
			state "level", action:"setLevel", label: "Level"
		}
        
		//COLOR
		 controlTile("rgbSelector", "color", "color", width: 6, height: 6, inactiveLabel: false) {
         state "color", action:"setColor"
        }
		
		main "switch"
		details([
		"switch","levelLabel", "level","rgbSelector" 
         
        ])
	}
	
	preferences {
        input name: "internal_ip", type: "text", title: "Internal IP", required: true
		input name: "internal_port", type: "text", title: "Internal Port", defaultValue: 80, required: true   	      
	}
}

/*
=============================================
ON/OFF
=============================================
*/
def off() {
	sendEvent(name: "switch", value: "off", isStateChange: true)
    //log.debug("Turn OFF")
	
    return sendGetRequest("/win&T=0")
} 
def on() {
    sendEvent(name: "switch", value: "on", isStateChange: true)
	//log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
	
    return sendGetRequest("/win&T=1&FX=0" )
}

/*
=============================================
BRIGHTNESS LEVEL
=============================================
*/
def setLevel(Integer value,rate=0) {
    state.SavedLevel = value
    
    sendEvent(name: "switch", value: "on", isStateChange: true)
    sendEvent(name: "level", value: state.SavedLevel, isStateChange: true)
    
	//log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
	
    return sendGetRequest("/win&A=${value}")
}

/*
=============================================
COLOR
=============================================
*/ 

def setColor(value) {

	state.SavedColor = value
    
    //log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
	//sendEvent(name: "switch", value: "on", isStateChange: true)
    
    //log.debug("Set Color:${value}")
	def h = (value.hue)*65535/100
    def s = (value.saturation)*255/100
    
    return sendGetRequest("/win&HU=${h}&SA=${s}")
    
}

/*
=============================================
HTTP SEND
=============================================
*/ 

private sendGetRequest(String url) {
	log.debug("${internal_ip}:${internal_port}${url}")
    
    def result = new physicalgraph.device.HubAction(
        method: "GET",
		path: "${url}",
        headers: [
            HOST: "${internal_ip}:${internal_port}" 
			]
        )
    //return result;
}
3 Likes

Thank you, that’s brilliant :grin:

I am using the WLED HTTP API to control my lights with webCoRE. Here is a tutorial I completed today because of the lack of information I found on the subject. Hopefully someone finds it useful.

3 Likes

I got WLED to work with smartthings by accident. I was trying to reconnect a Sylvania color bulb using the newer smartthings app so when it started searching my Sylvania color bulb came up of course and then a hue Hub bridge and a color rgbw bulb showed up. So after I started to turn on and off that bulb and it was turning off my WLED!! It gives you controls for color brightness and on and off. But unfortunately no FX’s. So far I got 2 working just have to have them on different udp ports so they don’t sync. I looked all over the internet for a way to get them to work then before and gave up then this happens…

It’s working with the lan hue bridge DTH not sure how it’s working but working great and with all automations too. Hope this helps someone.

WLED has support for MQTT as well. Any of us that are already running the MQTT Bridge and a Broker could also interact with WLED that way.

The device handler works perfect. But how do I add my presets into it?

1 Like

Hi, Finally setting this up and wondering if you could help.

I’ve created a new device handler using the code you kidnly posted. What do I do now to access this in the ST app?

In your ST IDE, create a new device under “My devices”. You’ll have a few mandatory fields, device type select WLED.
Then the device will simply appear into your devices on the app. Select it, click the settings, enter the IP address of the ESP, done!

1 Like

As I said in my original post, I only coded on/off/color/brightness.
I have no need for more personally…
The code is fairly easy, you’d have to create more button with their associated commands, and the urls going to the ESP.

Many thanks for that, so far so good, got it showing up in my smart things app! The part where I think i’m going wrong as it’s not turning the lights on or off ( I have added the IP address in settings) is that i’m stuck with what to put in the “Device Network Id” - Any help on what needs to go in there please?

Struggling to see where I might be going wrong! Hopefully someone will spot a glaring error i’ve made!

  1. Created a new device handler and insterted this code. (Had to remove the < at the start of each line)

    metadata {

 	definition (name: "WLED_Beta", namespace: "Damien", author: "Damien") {
 		capability "Switch"
 		capability "Switch Level"
 		capability "Light"
 		capability "Color Control"
 		
         command "on"
 		command "off"
         command "setColor"
 		command "setLevel"
 
 		attribute "color", "String"
 		attribute "level", "Number"
 
 	}
 
 	simulator {
 
 	}
 	
 	tiles (scale: 2) { 
     // void controlTile(String tileName, String attributeName, String controlType [, Map options, Closure closure])
             standardTile("switch", "device.switch", width: 3, height: 2, canChangeIcon: true) {
             state "on", label:'${name}', action:"off", icon:"st.switches.light.on", backgroundColor:"#00a0dc"
             state "off", label:'${name}', action:"on", icon:"st.switches.light.off", backgroundColor:"#ffffff"
 		}
 		//BRIGHTNESS
      		controlTile("level", "level", "slider",  width: 3, height: 2, inactiveLabel: false,range:"(0..255)" ) {
 			state "level", action:"setLevel", label: "Level"
 		}
         
 		//COLOR
 		 controlTile("rgbSelector", "color", "color", width: 6, height: 6, inactiveLabel: false) {
          state "color", action:"setColor"
         }
 		
 		main "switch"
 		details([
 		"switch","levelLabel", "level","rgbSelector" 
          
         ])
 	}
 	
 	preferences {
         input name: "internal_ip", type: "text", title: "Internal IP", required: true
 		input name: "internal_port", type: "text", title: "Internal Port", defaultValue: 80, required: true   	      
 	}
 }
 
 /*
 =============================================
 ON/OFF
 =============================================
 */
 def off() {
 	sendEvent(name: "switch", value: "off", isStateChange: true)
     //log.debug("Turn OFF")
 	
     return sendGetRequest("/win&T=0")
 } 
 def on() {
     sendEvent(name: "switch", value: "on", isStateChange: true)
 	//log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
 	
     return sendGetRequest("/win&T=1&FX=0" )
 }
 
 /*
 =============================================
 BRIGHTNESS LEVEL
 =============================================
 */
 def setLevel(Integer value,rate=0) {
     state.SavedLevel = value
     
     sendEvent(name: "switch", value: "on", isStateChange: true)
     sendEvent(name: "level", value: state.SavedLevel, isStateChange: true)
     
 	//log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
 	
     return sendGetRequest("/win&A=${value}")
 }
 
 /*
 =============================================
 COLOR
 =============================================
 */ 
 
 def setColor(value) {
 
 	state.SavedColor = value
     
     //log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
 	//sendEvent(name: "switch", value: "on", isStateChange: true)
     
     //log.debug("Set Color:${value}")
 	def h = (value.hue)*65535/100
     def s = (value.saturation)*255/100
     
     return sendGetRequest("/win&HU=${h}&SA=${s}")
     
 }
 
 /*
 =============================================
 HTTP SEND
 =============================================
 */ 
 
 private sendGetRequest(String url) {
 	log.debug("${internal_ip}:${internal_port}${url}")
     
     def result = new physicalgraph.device.HubAction(
         method: "GET",
 		path: "${url}",
         headers: [
             HOST: "${internal_ip}:${internal_port}" 
 			]
         )
     //return result;
 }
  1. Created a New Device with the following required fields
  • Name: WLED Front Window
  • Device Network ID - wled-front
  • Type - WLED_Beta
  • Version: Published
  • Location: Home
  • Hub: Home Hub
  1. Repeated step 2 to create another entry for the bedroom window
  2. Both devices now showing in the ST app. Added their individual IP address via settings

However neither the on/off seem to send any command to the lights.

I’ve also tried it with no success. Possibly a formatting error?

Just connect the wled to your Wi-Fi then search for new light with the Samsung connect app should pop up with a new color light and a hue hub for every nodemcu. I have 4 working perfectly with on/off, color, and brightness. And it works locally! Found this by accident. Just need to change udp port for each nodemce in the wled app so they don’t sync. Hope this helps someone.

Here are screen shots

I get an error when I try to save this as a new DH.

Got it figured out. Thanks. How can we update the code to add some of the effects like Merry Christmas?

@DaveUK83 I was having the same issue. My fix was to have the NodeMCU and Smart things Hub on the same network. I originally had the smart things hub on my modem and my nodemcu was connected to a google WIFI mesh.

Hey i was wondering where exactly do I put this and what do I do? Arduino IDE? Smartthings IDE? Sorry very big noob here. Need exact steps to do this. Already have WLED on ESP8266 and works properly. Now I just want Google home automation

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.