Neopixels/RGB LED example

Tags: #<Tag:0x00007f014aea9528> #<Tag:0x00007f014aea93c0>

(Ben) #22

witch mqtt client do you use. mine is mqtt fx.
i have set up my openhab like
maybe there is something different

(Kees Van Gelder) #23

i use mosquito as a broker. the ESP8266 is the client. as control client or interface I use the standard openhab user interfaces
I do not know what the relationship is between openhab and mk-smarthouse is. I just have an itemfile and a sitemapfile that communicate with my broker via the mqtt binding. I have no idea if and in what way smarthouse would do that

mqtt-fx is a rather limited client, I just use the standard openhab user interfaces, so i am really not sure how you have mqtt-fx communicate with openhab, or even why you would do that.

If you just forget abt mqtt-fx for the moment but just go to yr openhab user interface, does it work then?

(Ben) #24

No, i see its on my wifi network “ota-neopixel”.
When i look on the arduino ide, and i press 'serriele monitor’
nothing shows up. i dont know if its a problem?

i have be struggeling for a few weeks now, so i have tried manny options now
i have a esp 12e nodemcu, and use the nodemcu 12e proggram in ide.
is that the problem?

(Kees Van Gelder) #25

I think we have a major misunderstanding here.
What is it that you want to see in the serial monitor? that has nothing to do with the functionality of the LEDs/Neopixel
Also, if you select the ota port, the serial monitor becomes useless

The nodemcu is not the problem, it just seems you really do not understand what you are doing, so let me try and walk you through it
1-upload the program to your esp8266 (but it seems you already did)
2-add the items, sitemap and rules filesas i described above to yr items, sitemap and rules folder in yr openhab config folder
3- go to your user interface that you will find on :8080
stands for the ip number of the machine where yr openhab is running
4 choose the Basic UI
5 choose the sitemap you used to store the neopixel description
6-should work

Look at the picture I uploaded in my first post. That is the interface you should see/use. That is where you are supposed to control the LEDstrip from. Not from the serial monitor, not from mqtt-fx

I checked thr Smarthome-mk ‘setup’ and that setsup openhab with the mosqtuitto mqtt broker.
they only use mqtt-fx to test the broker, so you dont need mqtt-fx, just forget about that one

(Ben) #26

Beste Kees, ik zal precies vertellen wat ik doe:

de esp is geupload via ide. esp12e nodemcu.

In mijn openhab ga ik naar cd items dan sudo nano home.items.
daar doe ik deze code

Group All
Color RGBLed “NeoPixel Color” (All)
String RGBLedColor (All) {mqtt=">[mosquitto:OpenHab/RGB:command:*:default]"}Number W_RSSI “RSSI [%d dbm]” {mqtt="<[mosquitto:home/nb/weer/RSSI:state:default]"}
String W_IP “IP [%s]” {mqtt="<[mosquitto:home/nb/weer/IP:state:default]"}
String W_version “Software versie [%s]” {mqtt="<[mosquitto:home/nb/weer/version:state:default]"}
String W_MAC “MAC [%s]” (Wweather) {mqtt="<[mosquitto:home/nb/weer/mac:state:default]"}
Number W_IP_Uptime “Uptime [%d min]” (Wweather) {mqtt="<[mosquitto:home/nb/weer/uptime:state:default]"}

die sluit ik af.

dan ga ik naar cd sitemaps
dan sudo nano home.sitemap

sitemap NeoPixel label=“NeoPixel”
Frame label=“NeoPixel” {
Colorpicker item=RGBLed icon="slider"
Text item=W_RSSI
Text item=W_IP
Text item=W_version
Text item=W_MAC
Text item=W_IP_Uptime

die sluit ik af

cd rules
sudo nano home.rules

import org.openhab.core.library.types.*

rule "Set HSB value of item RGBLed to RGB color value"
Item RGBLed changed
val hsbValue = RGBLed.state as HSBType

val brightness = hsbValue.brightness.intValue 
val redValue = (((( * 255) / 100) *brightness) /100).toString
val greenValue = (((( * 255) / 100) *brightness) /100).toString
val blueValue = (((( * 255) / 100) *brightness) /100).toString

val color = redValue + "," + greenValue + "," + blueValue

sendCommand( RGBLedColor, color)


//part of Neopixel conf files

die sluit ik af.
en dan gebeurt er niets…

(Kees Van Gelder) #27

What interface are you using to address openhab?

(Kees Van Gelder) #28

As this seemed to be an openhab operational issue and nit related to the program presented here and as Ben’ s english might hamper might hamper the communication, we have taken it off-line.

… and it turned out to be an mqtt.cfg broker naming issue
glad i could stop someone from giving up

(Kim Skatun) #29

What version of the pubsubclient are you using, now I got this compile error

sketch\pubsubclient\tests\src\connect_spec.cpp:2:24: fatal error: ShimClient.h: No such file or directory

 #include "ShimClient.h"

(William Hedrick) #30

I have openHab controlling my Christmas lights, which are WS2812 variants I purchased off Aliexpress last year. My OH setup is running on an Rpi and I originally used an ESP8266 to control the lights. This year I’ve revamped everything on the lights side and upgraded to a Rpi 0 W.

On the OH side, I have selections for various things like Colors, Patterns, quantity, etc. Then there is a switch for “Update”, which is set to “ON” when you’re done making your changes. On the lights side, there is a pyhton script running that at regular intervals checks (via REST) to see if that switch is set to “ON”. If it isn’t, it continues the animation. If it is, it pulls all the variables and updates the animation, then changes the update switch back to “OFF”.

So really, OH isn’t actually controlling the lights at all, it’s where the settings are changed. So far, I’ve been really pleased with this setup. If anyone is interested, I can post more info when I’m not working.

Edit: I also have scripts running for some old DSP Wifi power switches. OH sends the signal to turn them on, which provides the power to the lights and Rpi 0 W, which boots and runs the python script to display the lights. At the scheduled time, OH changes the lights style to “Off”, which the pyhton script reads and shuts down the Rpi 0 W. When OH can no longer ping the Rpi 0 W, I assume it shut down and then OH sends the signal to the DSP power switch and kills the power until it’s time to turn them back on.

(Kees Van Gelder) #31

William, thanks for your addition. That is definitely a possibility too though in fact not much different from mine, as all my openhab does is send a command. It is thus in fact only the controller.
that you have it on an RPi rather than on an ESP is surely interesting to know a bit more about. I am just starting with using the RPi for anything else but to run OpenHab and Mosquitto. Would be good to see waht you do to actually control things on the RPi rather than the ESP

On a more general side: In many instances I use OpenHAB as an interface for things that are actually controlled by either an arduino or an ESP8266, which means that if openhab fails, things will still be running

(Kees Van Gelder) #32

Kim, apologies for my late reply, sadly I was unexpectedly hospitalised.
I am using this one:
But as said it is the Imroy fork of the Oleary PubSub
I am not entirely sure why you got that message as it seems to come from one of the knolleary test programs.
Shim client.h is called from several of these programs, but it is not part of the pubsub library.
As far as I could check it also isnt called from either the Pubsubclient.h or .cpp file

(William Hedrick) #33

I also use my OH setup as basically an interface for everything else. I like having a central place for everything with a uniform look across devices.

I started w/ the ESP8266, because it was cheap and I could use the Arduino libraries. Since I’m running a few hundred lights, I found that the ESP quickly ran out of memory for some more complex animations, and I think I had a memory leak somewhere, because it would crash after an hour or two. Last year, I had it set to reboot every hour to try to avoid the crashing, but occasionally I’d find it was stuck anyway and would have to manually power cycle it.

The Rpi (and subsequently Rpi 0 W) use the same Adafruit library as the ESP, but uses python instead of C. It wasn’t too much work to switch to python and a 0W is only about $10. The biggest thing to remember is that you have to shut down the Rpi before powering it off, or else you risk corrupting the SD card and losing all your work. Another major benefit is that I can update the code via SSH without having to physically access the controller and flash it with new code.

This is a little dated, but it’s a good jumping off point for using an Rpi to control WS2812/NeoPixels.

Overall I’m happy with where my lights are at this year. I have more animations, color combinations, and less crashes.

(Kees Van Gelder) #34

I already suspected it was abt x-mas lights when I read ‘few hundred’.
Will have a look at the link
proper shut down of RPi indeed is always essential
With ESP i usually use OTA for uploads but surely with memory hungry neopixels there might be a clash :slight_smile:
have to get myself an RPI 0W, but have not found it at that price yet

(Kim Skatun) #35

How does your arduino librry folder look like?

I see that I am at version 2.1 for the ESP, could this be the issue?

And it will not update…

(Kees Van Gelder) #36


The picture from the Library manager may suggest it is the original Nick O’leary PubsubClient, but it isnt. Obviously when I installed it teh IDE could nots ee the difference and I noticed that when i updated it, it updated to the O’leary one instead of the Imroy library.
Judging from your screenshot, that seems to be fixed now.

However, it is very well possible that on compilation, the IDE still chooses the wrong PubSubClient.h, if you have both installed. After all, how is it supposed to know if they both have the same name.

What I suggest is that IF you have both installed, you temporarily rename the O’leary files.
Also, whit verbose output (check in your preferences) you can see if it chooses the right library.

I do not think the ESp8266 firmware version has anything to do with it. I have always been at the latest version and that has included 2.1.
It is odd though that you cannot update.Nevertheless, I have has problems downloading too from the ‘official’ relase page. From the error message I understand that it is actually trying to download version 2.2.
You may want to try this link:

(Kim Skatun) #37

it seems like you are using the orignal pubsubclient and the Imroy one in your arduino enviroment, I will try to do the same…

(Kees Van Gelder) #38

It may ‘seem’ so, but I do not

(Kim Skatun) #39

Final question, you downloaded this zip file?

(Kees Van Gelder) #40


(Kees Van Gelder) #41

Kim, if you have trouble (re)installing the ESP8266 board or trouble compiling after installing and the new link I gave doesnt help much, please let me know. It might be necessary to completely remove your old ESP8266 install (by deleting the old files) and try again