[OH3] Ikea Tradfri LED1649C5 e14 dimming bulb via zigbee2mqtt

Foreword

This tutorial is for openHAB3. If you are on openHAB2 you will need to use my older tutorial .

We have an Ikea Tradfri e14 400lm dimmable bulb.

Here is how I integrated into openHAB, via zigbee2mqtt and Mosquitto .

This tutorial was written with openHAB3 running on a headless Raspberry Pi 3B with Raspberry Pi OS, with SSH access.

Overview

This tutorial assumes you have openHAB3 installed.

This tutorial will show you how to:

  1. Install an MQTT broker, install the MQTT binding, and connect the two
  2. Setup bulb with zigbee2mqtt
  3. Configure openHAB3 to ‘connect’ to the bulb
  4. Configure openHAB3 to control the bulb

Method

1. Install an MQTT broker, install the MQTT binding, and connect the two

In order to use MQTT devices, the following is required:

  1. An MQTT broker installed
  2. MQTT Binding installed in openHAB
  3. MQTT Bridge Thing configured in openHAB

Follow the steps in this tutorial to achieve the above three goals.

2. Setup bulb with zigbee2mqtt

It is assumed that you already have zigbee2mqtt installed and running.

Pair the device with zigbee2mqtt as described here. Ensure that you are able to pair devices by setting permit_join to true in configuration.yaml (usually in /opt/zigbee2mqtt/data)

Once paired, adjust the zigbee2mqtt configuration.yaml (usually in /opt/zigbee2mqtt/data) to:

Here is my configuration.yaml - your device ID is likely to be different. I have given my device the friendly name bPorchLight :

homeassistant: false
permit_join: true
mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://localhost'
serial:
  port: /dev/ttyACM0
  disable_led: false
advanced:
  log_level: error
  availability_timeout: 5
devices:
  '0x086bd7fffe210efc':
    friendly_name: bPorchLight
experimental:
  output: attribute

3. Configure openHAB3 to ‘connect’ to the bulb

To control the bulb, we need to configure a Generic MQTT Thing

  • Settings -> Things -> Blue + -> MQTT Binding -> Generic MQTT Thing

Enter the initial configuration information:

  • Unique ID: You can leave this default, or provide a more convenient ID. Once created, the ID cannot be changed.
  • Label: Friendly name for your device
  • Location: Physical location of your device
  • Bridge: Select your Bridge Thing to your MQTT Broker

In Show advanced:

  • Availability Topic: zigbee2mqtt/<FRIENDLYNAME>/availability
    • Adjust to use your friendly name
  • Device Available Payload: online
  • Device Unavailable Payload: offline

Click Create Thing. Your Generic MQTT Thing will be created and appear in your list of Things. After a couple of seconds, it will appear as ONLINE (assuming your bulb is connected to zigbee2mqtt, and zigbee2mqtt is connected to your MQTT Broker).

4. Configure openHAB3 to control the bulb

To control the bulb we will need to create

  1. Thing Channels
  2. Items

4.1 Thing Channels

Channels enable us to capture data from the bulb, and send commands to the bulb. We will create 2 Channels:

  • Power: bulb on/off
  • Dimmer: bulb dimming

4.1.1 Power: bulb on/off

Click the Channels tab in your Generic MQTT Thing, followed by Add Channel.

Configure the Channel:

  • Channel Identifier: Channel ID used internally by openHAB. No spaces allowed.
  • Label: Friendly name for the Channel. Spaces allowed.
  • Channel type: On/Off Switch

Continue the configuration of the Channel:

  • MQTT State Topic: Assuming default zigbee2mqtt setup, the State Topic will be zigbee2mqtt/<FRIENDLYNAME>/state.
  • MQTT Command Topic: Assuming default zigbee2mqtt setup, the State Topic will be zigbee2mqtt/<FRIENDLYNAME>/set.
  • Custom On/Open Value: ON
  • Custom Off/Closed Value: OFF

Click Create. The Channel will appear in the Channels tab of your Generic MQTT Thing.

4.1.2 Dimmer: bulb dimming

Click the Channels tab in your Generic MQTT Thing, followed by Add Channel. Configure the Channel:

  • Channel Identifier: Channel ID used internally by openHAB. No spaces allowed.
  • Label: Friendly name for the Channel. Spaces allowed.
  • Channel type: Percentage Value
  • MQTT State Topic: Assuming default zigbee2mqtt setup, the State Topic will be zigbee2mqtt/<FRIENDLYNAME>/brightness.
  • MQTT Command Topic: Assuming default zigbee2mqtt setup, the State Topic will be zigbee2mqtt/<FRIENDLYNAME>/set/brightness.
  • Absolute Minimum: 0
  • Absolute Maximum: 255

4.1.3 YAML code

Below is the YAML code for the complete Thing with its Channels.

UID: mqtt:topic:MosquittoMqttBroker:bPorchLight
label: Porch Light
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  availabilityTopic: zigbee2mqtt/bPorchLight/availability
  payloadAvailable: online
bridgeUID: mqtt:broker:MosquittoMqttBroker
location: Porch
channels:
  - id: power
    channelTypeUID: mqtt:switch
    label: Power
    description: ""
    configuration:
      commandTopic: zigbee2mqtt/bPorchLight/set
      stateTopic: zigbee2mqtt/bPorchLight/state
      off: OFF
      on: ON
  - id: dimmer
    channelTypeUID: mqtt:dimmer
    label: Dimmer
    description: ""
    configuration:
      commandTopic: zigbee2mqtt/bPorchLight/set/brightness
      min: 0
      stateTopic: zigbee2mqtt/bPorchLight/brightness
      max: 255

4.2 Items

We will create an Equipment group which will contain the Channels via respective Items.

Click Add Equipment to Model from within the Channels tab.

Configuration will depend on how your Model is setup:

  • Parent Group: Choose a Group from your Model to suit
  • Category: lightbulb
  • Semantic Class: Lightbulb

Continue configuration by selecting the Power and Dimmer Channels:

  • Category: lightbulb
  • Semantic Class: switch for Power and control for Dimmer

Click Add to Model.

We have to make one small adjustment to the Item created for the Dimmer Channel:

Items -> PorchLight_Dimmer -> Add Metadata -> State Description

  • Min: 0
  • Max: 100

Click Save top-right.

From the Equipment tab you can now control the bulb!

4.2.1 JSON Code

The following is the JSON for the Items and Links, queried from the API Explorer

Items
{
  "members": [
    {
      "stateDescription": {
        "minimum": 0,
        "maximum": 100,
        "step": 1,
        "pattern": "%s %%",
        "readOnly": false,
        "options": []
      },
      "type": "Dimmer",
      "name": "PorchLight_Dimmer",
      "label": "Dimmer",
      "category": "lightbulb",
      "tags": [
        "Control"
      ],
      "groupNames": [
        "PorchLight"
      ]
    },
    {
      "stateDescription": {
        "pattern": "%s",
        "readOnly": false,
        "options": []
      },
      "type": "Switch",
      "name": "PorchLight_Power",
      "label": "Power",
      "category": "lightbulb",
      "tags": [
        "Switch"
      ],
      "groupNames": [
        "PorchLight"
      ]
    }
  ],
  "editable": true,
  "type": "Group",
  "name": "PorchLight",
  "label": "Porch Light",
  "category": "lightbulb",
  "tags": [
    "Lightbulb"
  ],
  "groupNames": []
}
Links
  {
    "channelUID": "mqtt:topic:MosquittoMqttBroker:bPorchLight:power",
    "configuration": {},
    "itemName": "PorchLight_Power"
  }
  {
    "channelUID": "mqtt:topic:MosquittoMqttBroker:bPorchLight:dimmer",
    "configuration": {},
    "itemName": "PorchLight_Dimmer"
  }
4 Likes

hello hafniumzinc,

i’m currently in a learning phase, trying to get the gist of zigbee2mqtt interaction with openhab3, and btw a forum newbie. so i re-enacted your tutorial with a similar zigbee-standard dimmable bulb. I was able to create the things, items and links, and in prinicple got it to work as described, so thanks, this has really been of great help!!

however, I ran into two problems I cannot understand so far, and I was wondering if you would have some hints/general directions on what might be the problem, since I found nothing in the zigbee2mqtt docs or in the openhab docs:

  1. If I start the openhab interface, the bulb switch and dimmer slider on the overview/equipment page are always off and zero, respectively, regardless of the state(s) sent in the get topics on mosquitto.
  2. on the overview/equipment page, i can dim the bulb and switch it on from off state, but I can’t switch it off from the on state !?

any ideas would be very much welcome!

Not sure on the first issue for the moment, but for this one:

Try viewing the UI on a different device/browser and see what behaviour you get. Then report your findings on that issue too!

thanks for your quick reply, this is indeed the problem. on firefox, switching off does not produce a karaf log. when trying on android/chrome, exactly every other switch-off produces a log AND really switches the bulb off. With MSedge (that I never use anyhow), i don’t even get to see the controls overview/devices page, it stays empty


The other option is to leave the status of each item zigbeetomqtt/[friendlyname]
and then use json transformation in the incoming transformation.
and having your configuration.yaml set to

# Optional: experimental options
experimental:
  # Optional: MQTT output type: json, attribute or attribute_and_json (default: shown below)
  # Examples when 'state' of a device is published
  # json: topic: 'zigbee2mqtt/my_bulb' payload '{"state": "ON"}'
  # attribute: topic 'zigbee2mqtt/my_bulb/state' payload 'ON"
  # attribute_and_json: both json and attribute (see above)
  output: 'json'

This minimises the MQTT messages received when states updated from about 5-6 to 1-2

The trick for setting the THING to min:0, max: 255
and the ITEM to state transformation min:0, max:100 i didn’t know about. Thanks for that.

JSONPATH:$.brightness
JSONPATH:$.state

etc

Same for me, works perfectly !
Thanks for sharing the tip

Thanks for the above. That works brilliantly.

Now, here comes the culprit: i’m adjusting the dimmer via a rule by sending it the command “DECREASE” and “INCREASE”, but that only happens in 1% steps.

I tried to enter “10” in Step on the dimmer metadata, but that seems to do nothing. Is there any other way to do this ?

/M

I haven’t tried this, but I think you need to set the step on the Thing Channel, not the Item.

Hi,

I must have been tired yesterday. You are right in the sense, that it needs to be set on the channel, but it’s called the “Delta” value there. It even says in the description on the page, that it’s for the INCREASE/DECREASE commands.

Sorted now.

/M

Little update to the above.

While that all works brilliantly, it does not read the brightness of the bulb. That’s fine, as long as one only toggles the dimmer.

If you change the bulb using INCREASE/DECREASE, the dimmer will not be updated and doesn’t know, what percentage the bulb actually is at.

To fix that, edit the channel, check “Show advanced” and set the following values:
MQTT State Topic: zigbee2mqtt/FRIENDLYNAME
Incoming Value Transformation: JSONPATH:$.brightness

You will need to have to the Add-on JSONPath Transformations installed, for this to work.

After those modification, the dimmer is updated, when the bulb is changed by other means.

/M

If this was the fix then your setup didn’t follow the tutorial:

This step changes the configuration of zigbee2mqtt so it outputs attributes on their own topics. You shouldn’t have had to change anything else in the Channel after modifying the Delta value if this was the case.

Either way, glad it’s working for you!!

1 Like

You are right. I omitted that bit, as I had a working (well, sort of) zigbee2mqtt setup already.

Learned something again. I will try your approach and see, if that makes things easier. Both ways work, though.

/M

Yeah, to be honest if it’s working for you I’d be inclined not to change it. Nothing wrong with JSON strings!

Actually, it’s easier without JSON. But I literally installed OpenHAB 3.0.1 only 2 days ago on a new box, because my 2.5 setup runs on Ubuntu 14.04, I don’t want to break it, nodejs only is max v8 for 14.04 (so no zigbee2mqtt possible) and the USB dongle I got on Friday doesn’t have the firmware for the Zigbee Binding, nor do I have the programmer. (First world problems, I know).

So I’ve been playing around with getting things like the Lidl powerstrip and the Ikea remote to work on a fresh system using zigbee2mqtt. OH3 is such a progress from OH1 and OH2. Loving it.

/M

The dimmer is working correctly, but i do get a error inside the openhab.log:

2021-02-28 20:37:29.010 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command 'NaN' not supported by type 'PercentageValue': Unknown String!

I also get this message when i set the percentage to 20 (value 51)
Is this a problem with OH3.1?

Hi. This tutorial will integrate the ss 2538 stick. If so what needs to be changed in the instructions? or nothing needs to be changed?

I’ve not come across this, but if the zigbee2mqtt firmware works on it then I don’t think anything changes as far as this tutorial is concerned.

Thanks for your tutorial!
My setup is slightly different:
Zigbee2mqtt has Home Assistant support enabled, so that it will create auto configuration description in mqtt topic “homeassistant” for each thing.
Things are auto discovered in OH3. Instead of Generic MQTT things, these are Home Assistant MQTT things.

Advantage: state topic, command topic and so on are already contained in thing descriptions coming from mqtt homeassistant/device_label/config

For switch items it’s easy to connect them to a channel of a thing.

But I am not able to connect a dimmer item to an Home Assistant MQTT auto discovered thing.

Do you have experience with it?

I’m afraid I don’t. I suggest you start a new topic, but show your full configurations for your Item and Thing so that others can try to help.

Hi, tell me.I have configured the zigbeetomqtt binding there is one problem.after the reboot, the sensors that I connected go offline. at the same time, the broker itself is in the online mode.when I go to the broker’s thing and click on save, the sensors connect to the broker.how do I make sure that the sensors are online after a reboot?