RGB led strip – controlled by a flashed H801 and Openhab

Update with pictures of the full strip in situ..

I’ve a few RGB LED strips around the house.

The one in the living room makes for a pleasant ambiance as it goes all the way around the room and shines upwards to reflect off the ceiling.

The problem with them is that the cheap IR controller that came with them is on the same channel as the TV remote control..

20161111_110050

So every time we changed channels or changed the volume on the TV the lights came on, flashed, shifted colour or went all strange.
So in the end we stopped using them, I never gave up hope though and with my new IOT push I decided these were high on the list.ITo aid with the automation of the led strips I bought a few H801 boxes from China via aliexpress, they connect to the OpenHab running on my Pine64 (great little computer..)

I use this shop , they’ve been very reliable and sorted any issues out quickly. 

The H801 is a superb little box, at its heart is an ESP8266 chip, it also has the pin holes to enable you to solder a few pins and then flash a new firmware.

Close up of soldered pins in H801

I don’t like the idea of using any thing that I can’t read the code, I don’t want other people either using my devices for DDOS nor owning my data (if I can help it..) 

So re-flashing was a huge bonus for me as it saves me having to build a LED controller from scratch.

Now I’m a lazy*  (*efficient) person so I can’t take any credit for the following code – all I did was bring it all together.

To program the H801 I used the Arduino ide with code from this git page, this code was itself built from someone else’s code but with added MQTT service – which is what I needed..

Once this was on the H801 and tested I could then add it to my OpenHab setup..

I created an item:
 
Color RGB_1 "Living rm RGB Command"
String RGB_1_RGB {mqtt=">[localmqtt:sensors/RGB_1:command:*:default]"}

and a sitemap:

sitemap lights label="Lights"
{
Frame label="Living room RGB" {
Colorpicker item=RGB_1 icon="slider"
}
}

This looks pretty snazzy in OpenHab’s interface, the mobile version UI is even better.

Screen shot of the mobile UI - OpenHab Color picker Screen shot of the mobile UI - OpenHab Color pickerr

Finally a rule to actually send the rgb hex code to the H801 controller via mqtt:

import org.openhab.core.library.types.*
import java.awt.Color

rule “Set RGB_1 value”
when
Item RGB_1 changed
then

val Color color = (RGB_1.state as HSBType).toColor()
val String rgb = String::format(“%1$02x%2$02x%3$02x”, color.red, color.green, color.blue)
sendCommand( RGB_1_RGB, rgb )

logInfo( “RGB_1”, rgb )
end

The outcome was good – here’s a short test RGB strip, I’ll update later on with the full results.

h801 with rgb led

Lessons learned:
The rrd4j persistence doesn’t like the hex, so if you’ve got the standard rule in your rrdfj.persist file (e.g. just a * : strategy = everyMinute etc) then you’ll need to change it.
The errors look something like this:
2016-11-11 10:20:10.730 [ERROR] [.o.m.c.i.folder.FolderObserver] - An unexpected exception has occured
java.lang.NumberFormatException: Infinite or NaN
at java.math.BigDecimal.(BigDecimal.java:895) ~[na:1.8.0_101]
at java.math.BigDecimal.(BigDecimal.java:872) ~[na:1.8.0_101]
at org.openhab.core.library.types.DecimalType.(DecimalType.java:47) ~[na:na]
at org.openhab.persistence.rrd4j.internal.RRD4jService.mapToState(RRD4jService.java:320) ~[na:na]
at org.openhab.persistence.rrd4j.internal.RRD4jService.query(RRD4jService.java:191) ~[na:na]
at org.openhab.core.persistence.internal.PersistenceManager.initialize(PersistenceManager.java:369) ~[na:na]
at org.openhab.core.persistence.internal.PersistenceManrager.itemAdded(PersistenceManager.java:342) ~[na:na]
at org.openhab.core.persistence.internal.PersistenceManager.allItemsChanged(PersistenceManager.java:337) ~[na:na]
at org.openhab.core.internal.items.ItemRegistryImpl.allItemsChanged(ItemRegistryImpl.java:201) ~[na:na]
at org.openhab.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:393) ~[na:na]
at Update with pictures of the full strip in situ..org.openhab.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:159) ~[na:na]
at org.openhab.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:100) ~[na:na]
at org.openhab.model.core.internal.folder.FolderObserver.checkFolder(FolderObserver.java:142) ~[na:na]
at org.openhab.model.core.internal.folder.FolderObserver.run(FolderObserver.java:99) ~[na:na]

I created a group called gRrrdfjPersist, then added every sensor that I wanted to persist to that group and finally changed the rrd4j.persist to look like this:


Strategies{
everyDay : "0 0 0 * * ?"
everyHour : "0 0 * * * ?"
everyMinute : "0 * * * * ?"

default = everyMinute

}

Items {
gRrrdfjPersist* : strategy = everyMinute, everyChange, restoreOnStartup
}

Finally a few pictures of the room – to test them out I connected my twitter channel (@adamjennison) up to my openhab via ifttt service.

People could then tweet an RGB value to me and automatically change the lights (once the ifttt api kicked in). It kept the twitterverse amused for an evening..
🙂

cw_yldoxuaeu5sx cw_srd8xuaqj9d0 cw_s1vgxuaafkpm cw_tzicwqaamoee cw_xxi-wqaaagmq cw_xvx5wiaaxjqo

Leave a Reply

Your email address will not be published. Required fields are marked *