How do I add my things?

Hi guys,

I am in the midst of setting up my own openHAB System but I am really uncertain of how add my things to the system. As a heads up: I am very new to openHAB and fairly new to the linux landscape in general. So I don’t have a great understanding of the different mechanics of the whole system yet.

To illustrate where I am right now some keypoints:

Hardware I own: Raspberry Pi 4 Model B; CC2531 zigbee2mqtt stick; OSRAM Smart+ Plug; OSRAM Smart+ Flex 3P Multicolor; Philips Hue Dimmer Switch

As for the software, I basically followed the tutorial for beginners (had to remove the link sincy I can only have two in one post) and at this point, everything seems to be installed correctly, although I could be wrong about that.

Now, I would like to start with adding the dimmer to the system following this guide. As I dont use Home Assistant but openHAB, i have to do the manual integration right? If so, it doesn’t say where exactly to put the configuration. Should I put it in the broker.things file? If so, where should I insert it? The syntax looks very different from the syntax in the mentioned tutorial for beginners.

And is this at all what I have to do, or is there some kind of button in - say - the Paper UI that I can use instead?

[As a side question: The OSRAM Smart+ Flex 3P Multicolor is not in the list of devices supported by zigbee2mqtt. Other OSRAM Lightstrips are though. Do you think, I can still use it?]

This guy seemed to be at a similar point, and based on that thread I have changed my things file, my items file and my sitemap trying to add my Hue Dimmer.

dimmer.things:

Bridge mqtt:topic:mosquitto [ host=“localhost” secure=false ]
{
Thing topic Bedroom_Light @ “Bedroom” {
Channels:
Type switch : power “Power” [ stateTopic=“zigbee/0x001788010670863e”, transformationPattern=“JSONPATH:$.state”,
commandTopic=“zigbee/0x001788010670863e/set”, on=“ON”, off=“OFF” ]
Type dimmer : dimmer “Dimmer” [ stateTopic=“zigbee/0x001788010670863e”,
commandTopic=“zigbee/0x001788010670863e/set”, transformationPattern=“JSONPATH:$.brightness”, formatBeforePublish=“{"brightness":%s}” ]
}
}

default.items:

Switch BedroomLight “Bedroom Light” [“Lighting”] { channel=“mqtt:topic:mosquitto:zigbee2mqtt:power”, expire=“120m,command=OFF” }
Dimmer BedroomLight_Level “Bedroom Light Level [%.0f %%]” [“Lighting”] { channel=“mqtt:topic:mosquitto:zigbee2mqtt:dimmer” }

default.sitemap:

itemap default label=“My_sitemap”
{
Switch item=BedroomLight label=“Bedroom Light”
Slider item=BedroomLight_Level label=“Bedroom Light Level [%d %%]” sendFrequency=500
}

After all this, pushing buttons on my dimmer switch doesn’t seem to do anything, it at least doesn’t register in the basic ui.

I really don’t know how to proceed from here. Did I do something (or many things :sweat_smile:) wrong? Could I have chosen a more straight forward just-pressing-one-button kind of path? Or do I just have to do one or two more steps I didn’t think of yet?

Some help would be greatly appreciated!

Best and stay safe in these weird days of Corona,
David

Blockquote[quote=“davebar96, post:1, topic:95010”]
tutorial for beginners (had to remove the link sincy I can only have two in one post)
[/quote]

Hello David,

I don’t have the same Phillips Hue Dimmer switch, but I have the IKEA Remote Control which can also be used to dim the lights. The key is to understand that the command from the device is coming as a string, which then can be used to trigger a rule.

My .things for the switch looks as follows:

// Kitchen Lamp Switch (IKEA TRADFRI Remote Control)
    Thing topic Sw_Kitchen @ "Casa" {
        Channels:
            Type string : click "Acción Interruptor Cocina" [stateTopic="zigbee2mqtt/Sw_Kitchen", transformationPattern="JS:gettradfriaction.js"]
            Type number : battlevel "Batería Interruptor Cocina" [stateTopic="zigbee2mqtt/Sw_Kitchen", transformationPattern="JSONPATH:$.battery"]
    }

Transformation:

// Transforms the action received from the Tradfri Remote Switch
(function(x){
    var result = "none";
    var json = JSON.parse(x);  
   try
   {
       result = json.action;
   }
   catch(e)
   {
       result = "none";
   }
   return result;
})(input)

.items
Note that the Switch items are just virtual switches which I use to simplify my rules.

// Kitchen
String Switch_Kitchen "Interruptor Cocina" { channel="mqtt:topic:mosquitto:Sw_Kitchen:click" }
Number Batt_Switch_Kitchen "Batería Interruptor Cocina [%d %%]" (gBattery, gRestore) { channel="mqtt:topic:mosquitto:Sw_Kitchen:battlevel"}

Switch SW_Lamp_Kitchen "Iterruptor Cocina"
Switch SW_BrightUp_Kitchen "Subir Brillo Cocina"
Switch SW_BrightDown_Kitchen "Bajar Brillo Cocina"
Switch SW_cTempUp_Kitchen "Subir Color Luz Cocina"
Switch SW_cTempDown_Kitchen "Bajar Color Luz Cocina"

Sample Rule

// Rules to control kitchen lighting
import java.util.concurrent.locks.ReentrantLock

val ReentrantLock remote_Click = new ReentrantLock()
val ReentrantLock kitchen_ON = new ReentrantLock()
val ReentrantLock kitchen_OFF = new ReentrantLock()

// Rule to decide action when a button on the Tradfri remote is pressed
rule "Interruptor Cocina"
when
    Item Switch_Kitchen received update
then
    remote_Click.lock()
    logInfo ("Rule for Tradfri Switch Sw_Kitchen", "remote_Click Locked")
    try {
        var current_Action = Switch_Kitchen.state.toString
        logInfo ("Rule for Tradfri Switch Sw_Kitchen", "Switch Kitchen Action is {}", current_Action)
        switch current_Action {
            case "toggle" : {
                if(Lamp_Kitchen.state == ON) {
                    SW_Lamp_Kitchen.sendCommand(OFF)
                    logInfo ("Rule for Tradfri Switch Sw_Kitchen", "SW_Lamp_Kitchen OFF command sent")
                } 
                else {
                    SW_Lamp_Kitchen.sendCommand(ON)
                    logInfo ("Rule for Tradfri Switch Sw_Kitchen", "SW_Lamp_Kitchen ON command sent")
                }
            }
            case "brightness_up_click" : {
                SW_BrightUp_Kitchen.sendCommand(ON)
                logInfo ("Rule for Tradfri Switch Sw_Kitchen", "SW_BrightUp_Kitchen ON command sent")
            }
            case "brightness_down_click" : {
                SW_BrightDown_Kitchen.sendCommand(ON)
                logInfo ("Rule for Tradfri Switch Sw_Kitchen", "SW_BrightDown_Kitchen ON command sent")
            }
            case "arrow_right_click" : {
                SW_cTempUp_Kitchen.sendCommand(ON)
                logInfo ("Rule for Tradfri Switch Sw_Kitchen", "SW_cTempUp_Kitchen ON command sent")
            }
            case "arrow_left_click" : {
                SW_cTempDown_Kitchen.sendCommand(ON)
                logInfo ("Rule for Tradfri Switch Sw_Kitchen", "SW_cTempDown_Kitchen ON command sent")
            }
        }
    }
    finally {
        remote_Click.unlock()
        logInfo ("Rule for Tradfri Switch Sw_Kitchen", "remote_Click Unlocked")
    }
end

// Rule to increase the kitchen lamp brightness using a virtual item    
rule "Increase Brightness Kitchen Lamp"
when
    Item SW_BrightUp_Kitchen received command ON
then
    logInfo ("Kitchen Lamp Increase Brightness Rule", "Triggered")
    var current_Brightness = Dim_Kitchen.state as Number
    logInfo ("Kitchen Lamp Increase Brightness Rule", "Kitchen lamp current brightness is {}", current_Brightness)
    if (current_Brightness <= 90) {
        Dim_Kitchen.sendCommand(current_Brightness + 10)
        logInfo ("Kitchen Lamp Increase Brightness Rule", "Dim_Kitchen + 10")
    }
    else {
        Dim_Kitchen.sendCommand(100)
        logInfo ("Kitchen Lamp Increase Brightness Rule", "Dim_Kitchen is MAX")
    }
    SW_BrightUp_Kitchen.sendCommand(OFF)
end

The actual string that your dimmer will output when pressing a button can be found out easily with mosquitto_sub

Hope this helps.

1 Like