Fibaro Home Center 3 / Yubii Home: Integrating the KL MZ multi-zone presence sensor

Learn how to integrate the KL MZ multi-zone presence sensor into Fibaro Home Center 3 / Yubii Home, with all settings on the sensor and on the hub.

Applies to KL MZ · Sensor firmware 1.4.3 and newer · As of 11/30/2026

Contents

The Home Center integrates the sensor through a small Quick App (Lua). The sensor and the Quick App are connected to the same MQTT broker. The sensor reports every change in presence immediately, and the Quick App passes it on to the Home Center without delay. The Quick App itself is a device of the type motion sensor for presence in the whole room. For each detection zone for which an area has been drawn on the sensor, it creates a child device “Zone …”, also as a motion sensor. If you like, the number of people, brightness, temperature, humidity and air pressure are added as child devices of their own.

In this guide, <Hauptthema> stands for whatever is entered on the sensor under Connections → Main topic. Enter your own, without the angle brackets.

Requirements

  • Home Center 3, Home Center 3 Lite or Yubii Home with firmware 5.030 or newer (child devices).
  • An MQTT broker on the network, e.g. Mosquitto on a NAS. The Fibaro hub itself is not a broker.
  • KL MZ multi-zone presence sensor with firmware 1.4.3 or newer.

Setting up the sensor

  1. In the sensor's web interface under Zones → Zone names, name the detection zones you use before you create the Quick App (short, only letters, digits and _, no spaces or umlauts, e.g. Sofa). The Quick App takes the name for its child device as the sensor sends it: in capital letters (SOFA). Do not rename the zones afterwards (see Limitations).

  2. Sensor web interface → Connections:

    Field Value
    Connection type MQTT Broker
    Server Name or IP address of the broker
    Port 1883
    Login / password only if the broker requires them
    Client id unique for each sensor, e.g. wohnzimmer
    Main topic freely selectable, only letters, digits and _

    Save. After a short while, the bottom of the page shows “connected”.

How long presence continues after the last detection is set on the sensor (main page, Room timeout and Timeout per zone), not in the Quick App.

Setup

  1. In the hub's web interface, open the device list (Devices), click the plus to add a device and select Other Device and then Quick App (names as shown in the English interface).

  2. Fill in the dialog:

    Field Value
    Name Anwesenheit (freely selectable)
    Room as you like
    Device type Motion sensor (com.fibaro.motionSensor)
  3. Open the new Quick App, tab Edit & Preview, replace the existing code completely with this one and adjust the lines marked with <<<:

    -- SENVOLON multi-zone presence sensor KL MZ -> Fibaro HC3 / Yubii Home (MQTT)
    local BROKER   = "<IP des Brokers>"  -- <<< ANPASSEN: Name oder IP-Adresse des Brokers
    local PORT     = 1883                -- <<< ANPASSEN, falls abweichend
    local USER     = ""                  -- <<< nur wenn der Broker eine Anmeldung verlangt
    local PASSWORD = ""                  -- <<< nur wenn der Broker eine Anmeldung verlangt
    local TOPIC    = "<Hauptthema>"      -- <<< ANPASSEN: Hauptthema des Sensors
    local ZONES    = true                -- <<< true: je Erkennungszone ein Bewegungsmelder
    local VALUES   = false               -- <<< true: Personen, Helligkeit, Temperatur, Luftfeuchte, Luftdruck
    local RETRY    = 30                  -- seconds until a new connection attempt
    
    -- Value children: field, name and device type
    local FIELDS = {
      {field = "detection",   name = "Personen",    type = "com.fibaro.multilevelSensor"},
      {field = "brightness",  name = "Helligkeit",  type = "com.fibaro.lightSensor"},
      {field = "temperature", name = "Temperatur",  type = "com.fibaro.temperatureSensor"},
      {field = "humidity",    name = "Luftfeuchte", type = "com.fibaro.humiditySensor"},
      {field = "pressure",    name = "Luftdruck",   type = "com.fibaro.multilevelSensor", unit = "hPa"},
    }
    
    local STAT  = "stat/" .. TOPIC .. "/"
    local TELE  = "tele/" .. TOPIC .. "/"
    local ZONE_ = STAT .. "ZONES/"
    
    -- "True"/"False" from the sensor; anything else (empty message) is nil
    local function bool(payload)
      if payload == "True" then return true end
      if payload == "False" then return false end
      return nil
    end
    
    class 'Zone' (QuickAppChild)
    function Zone:__init(device) QuickAppChild.__init(self, device) end
    function Zone:show(on)
      if on ~= self.last then
        self.last = on
        self:updateProperty("value", on)
      end
    end
    
    class 'Value' (QuickAppChild)
    function Value:__init(device) QuickAppChild.__init(self, device) end
    function Value:show(v)
      if type(v) == "number" then self:updateProperty("value", v) end
    end
    
    function QuickApp:onInit()
      self:initChildDevices({
        ["com.fibaro.motionSensor"] = Zone,
        ["com.fibaro.multilevelSensor"] = Value,
        ["com.fibaro.lightSensor"] = Value,
        ["com.fibaro.temperatureSensor"] = Value,
        ["com.fibaro.humiditySensor"] = Value,
      })
      if VALUES then
        for _, f in ipairs(FIELDS) do
          if not self:child("field", f.field) then
            local c = self:createChildDevice({name = f.name, type = f.type}, Value)
            c:setVariable("field", f.field)
            if f.unit then c:updateProperty("unit", f.unit) end
          end
        end
      end
      self:connect()
    end
    
    function QuickApp:child(key, value)
      for _, c in pairs(self.childDevices) do
        if c:getVariable(key) == value then return c end
      end
    end
    
    function QuickApp:connect()
      local options = {port = PORT, clientId = "hc3_klmz_" .. self.id, keepAlivePeriod = 30}
      if USER ~= "" then
        options.username = USER
        options.password = PASSWORD
      end
      local client = mqtt.Client.connect("mqtt://" .. BROKER, options)
      self.client = client
      client:addEventListener('connected', function()
        if client ~= self.client then return end
        self:debug("Mit dem Broker verbunden")
        pcall(function() self:updateProperty("dead", false) end)
        client:subscribe(STAT .. "PRESENCE")
        client:subscribe(STAT .. "DETECTION")
        if ZONES then client:subscribe(ZONE_ .. "#") end
        client:subscribe(TELE .. "STATE")
        client:subscribe(TELE .. "LWT")
      end)
      client:addEventListener('message', function(event)
        if client == self.client then self:onMessage(event.topic, event.payload) end
      end)
      client:addEventListener('closed', function()
        if client == self.client then self:retry("Verbindung getrennt") end
      end)
      client:addEventListener('error', function(event)
        if client == self.client then self:retry(event and (event.code or event.error)) end
      end)
    end
    
    function QuickApp:retry(reason)
      self:debug("Broker nicht erreichbar: " .. tostring(reason))
      pcall(function() self:updateProperty("dead", true) end)
      local old = self.client
      self.client = nil
      pcall(function() old:disconnect() end)
      fibaro.setTimeout(RETRY * 1000, function() self:connect() end)
    end
    
    function QuickApp:onMessage(topic, payload)
      if topic == STAT .. "PRESENCE" then
        local on = bool(payload)
        if on ~= nil and on ~= self.last then
          self.last = on
          self:updateProperty("value", on)
          self:debug("Praesenz " .. tostring(on))
        end
      elseif topic == STAT .. "DETECTION" then
        local c = self:child("field", "detection")
        if c then c:show(tonumber(payload)) end
      elseif ZONES and topic:sub(1, #ZONE_) == ZONE_ then
        local name, on = topic:sub(#ZONE_ + 1), bool(payload)
        local c = self:child("zone", name)
        if on == nil then                     -- empty message: zone without area
          if c then c:show(false) end
          return
        end
        if not c then
          c = self:createChildDevice({name = "Zone " .. name, type = "com.fibaro.motionSensor"}, Zone)
          c:setVariable("zone", name)
        end
        c:show(on)
      elseif topic == TELE .. "STATE" then
        local ok, d = pcall(json.decode, payload)
        if not ok or type(d) ~= "table" then return end
        for _, c in pairs(self.childDevices) do
          local field = c:getVariable("field")
          if field and field ~= "" and field ~= "detection" then c:show(d[field]) end
        end
      elseif topic == TELE .. "LWT" then
        local online = payload == "Online"
        pcall(function() self:updateProperty("dead", not online) end)
        if not online then self:debug("Sensor nicht erreichbar") end
      end
    end
    
    Setting in the code Value
    BROKER Name or IP address of the broker, e.g. 192.168.1.10
    PORT Port of the broker, usually 1883
    USER, PASSWORD leave empty unless the broker requires a login
    TOPIC Main topic of the sensor, note upper and lower case
    ZONES true: one child device for each detection zone, false: none
    VALUES true: child devices for people, brightness, temperature, humidity, air pressure
  4. Save. The Quick App starts immediately, connects to the broker and creates the child devices once. The broker keeps the last state of presence and zones ready, so it arrives right after connecting.

Quick test

  • Go into the room: the “Anwesenheit” device and the child device of the zone you are standing in report motion immediately. Leave the room: after the sensor's timeout, both stop reporting motion.
  • The Quick App's log shows “Mit dem Broker verbunden” and, at every change, a line like Praesenz true.
  • Counter-check: enter a wrong main topic in the code and save. No zone devices are created, and “Anwesenheit” does not change. Then set it back to the correct one.

Optional

People, brightness, temperature, humidity, air pressure: set VALUES = true and save. Five child devices are created once. People and air pressure are general measured-value devices (air pressure with the unit hPa). The number of people arrives at every change; brightness, temperature, humidity and air pressure arrive at the sensor's Publish interval (5 minutes as delivered).

Only the whole room: set ZONES = false, and the Quick App then creates no zone devices. Delete those already created in the device list.

Limitations

  • The Quick App only reads. You change the sensor's settings (timeout, LED, alert) in its web interface.
  • If the sensor fails, the broker reports it after about 20–30 seconds. The Quick App then marks the “Anwesenheit” device as unreachable, and the log shows “Sensor nicht erreichbar”. The last value stays, even “motion”. The child devices are not marked.
  • If the broker is not reachable, the Quick App also marks “Anwesenheit” as unreachable and tries again every 30 seconds. Once the connection is back, it removes the mark.
  • Renaming zones: the Quick App recognizes a zone by its name. If you rename a zone on the sensor, it creates a new child device. The old device stays with its last value. Delete it by hand and adjust your scenes.
  • A zone for which no area has been drawn on the sensor gets no child device. If you delete the area of a zone, its child device no longer reports motion. You delete the device itself by hand. The factory name Detection 1 is taken over as the sensor sends it. The child device is then called “Zone DETECTION 1”.
  • Umlauts in the zone name stay lower case in the sensor's message: Küche becomes KüCHE. It is therefore better not to use umlauts.
  • The broker's login and password are in plain text in the code.

Verification status

This guide is based on public documentation for the Home Center 3; the code has been tested with Lua 5.3.6.

Next

Manual

KL MZ presence sensor

Mounting, connecting to Wi-Fi, drawing zones.

Smart home

All systems

An overview of the guides for all twelve systems.

Support

Help and contact

Phone, email and contact form.