I set up an esp8266 with @matt1’s EspMilightHub firmware. Now I’m trying (and for now, failing) to connect the hub to openHAB (which is running on an openhabian raspi).
First, I installed mosquitto via openhabian-config. Then, as instructed in the linked repo, I copied the jar files for the milight hub binding from here into the addons folder. This binding is based on the paho mqtt client. But now I receive a MqttSecurityException every 10 seconds in the log file, stating that I am not authorized to connect:
20:13:00.781 [ERROR] [ub.handler.EspMilightHubBridgeHandler] - Error: Could not connect to MQTT broker.{}
org.eclipse.paho.client.mqttv3.MqttSecurityException: Not authorized to connect
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28) ~[?:?]
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:1040) ~[?:?]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:151) ~[?:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]
Where do I have to set which connection options? I tried the following variants:
stored mosquitto password for the user openhabian in the /etc/openhab2/services/mqtt.cfg file
stored password for the milight hub in the /etc/openhab2/services/mqtt.cfg file
no mqtt.cfg at all.
Nothing of the above helped.
However, from my naive point of view, it looks as if the broker is running. At least I could do mosquitto_pub in one shell and receive the message from a second shell with mosquitto_sub …
It would be great if you could help me!
+++ newbie disclaimer: please forgive me any stupid questions +++
(Question was asked here before.)
Hi opus, you can find a detailed explanation in the repo. I carefully tried not to deviate from these instructions.
Do you speak of a thing in terms of openHAB? I did not yet create a thing file for the milight devices - first, I should get mqtt running, shouldn’t I?
The ESPMilightHub binding runs it’s own MQTT client. You don’t need to install the MQTT binding to run it.
These are all for MQTT V1
After adding the ESPMilightHUB biding, you need to add a ESPMilightHub Bridge thing
In the configutation for the thing you need to add the MQTT broker address and password.
Did you install an MQTT broker? If yes, which one, I recommend Mosquitto.
If not, do it.
After adding the ESPMilightHUB biding, you need to add a ESPMilightHub Bridge thing
In the configutation for the thing you need to add the MQTT broker address and password.
I did not realize I had to do this before using the broker. Makes sense …
Now I added the EspMilightHub and thing and entered user:password. And the errors in the log have disappeared!
Now I need to connect my milight remote (that’s why I set up the hub). Unfortunately, running mosquitto_sub -u openhabian -P mymosquittopassword -p 1883 -v -t 'milight/#' does not show any messages when I press a key at the remote. The milight hub web interface, however, logs each keypress when sniffing is activated.
Do I first need to add a thing for the remote? How could I find out its device ID?
The ESPMilightHub binding runs it’s own MQTT client. You don’t need to install the MQTT binding to run it.
I did not install the MQTT binding. That is, I had installed it by accident but then uninstalled it again.
Did you install an MQTT broker? If yes, which one, I recommend Mosquitto.
But still, mosquitto_sub does not list any messages when I use the remote.
Is fut089 actually the right thingTypeId? I did not buy any milight bulbs, only the remote.
Is 0x24FB2 actually the right deviceId? This is an example package sniffed from the bridge:
The problem is, my remote can control eight groups and there are also some master keys that yield the group 00. Do I need to create nine separate things? And neither 0x24FB2 nor 0x24FB02 nor 0x24FB gave me any hits in mosquitto_sub …
Wow, that linked thread is really long (estimated reading time: 2 hours) But my use case appears to be quite rare: Setting up the milight remote without possessing any milight bulb at all …
However, Google, try & error helped me to figure out the following:
I needed to fill in the following fields in the milight hub’s MQTT settings:
Next problem is to connect these MQTT updates to openHAB items. I added items for level and color of the remote via PaperUI, but they don’t refresh when I use the remote. There are also no matching log items. Any idea what I could be missing now or where to start searching for an error?
log:tail in the Karaf console does not give me any relevant log item (the only kind of lines appearing is 18:53:48.402 [INFO ] [smarthome.event.ItemStateChangedEvent] - Sensor_OpenHabPi_Temperature changed from 61.8 to 62.8).
rule "Remote_C1_Generic"
when
Item Remote_C1_Master changed
then
val String json = (Remote_C1_Master.state as StringType).toString
{
val sBrightness = transform("JSONPATH", "$.brightness", json)
if (sBrightness != json) {
val Number brightness = Math.round(Integer::parseInt(sBrightness) / 255.0 * 100)
Strip_C_CouchBackground_Dimmer.sendCommand(brightness)
}
}
{
val sHue = transform("JSONPATH", "$.hue", json)
if (sHue != json) {
val hue = new DecimalType(Integer::parseInt(sHue))
var color = Strip_C_CouchBackground_Color.state as HSBType
color = new HSBType(hue, color.saturation, color.brightness)
Strip_C_CouchBackground_Color.sendCommand(color)
}
}
{
val sSaturation = transform("JSONPATH", "$.saturation", json)
if (sSaturation != json) {
val saturation = new PercentType(Integer::parseInt(sSaturation))
var color = Strip_C_CouchBackground_Color.state as HSBType
color = new HSBType(color.hue, saturation, color.brightness)
Strip_C_CouchBackground_Color.sendCommand(color)
}
}
{
val sState = transform("JSONPATH", "$.state", json)
if (sState != json) {
var state = if (sState == "OFF") OFF else ON
Strip_C_CouchBackground_Color.sendCommand(state)
}
}
end
To me, this feels very hacky, but at least it works. Any hints how to improve code quality or design are highly welcome