Contents
Home Center 3, Home Center 3 Lite and Yubii Home integrate the sensor through a small Quick App (Lua). It polls the sensor over HTTP on your home network every 60 seconds. No MQTT broker is needed. The sensor's power saving mode must not be activated. The Quick App shows the fill level in percent as a device and, if you wish, liters and temperature as additional devices. This guide includes the code for the Quick App.
In this guide, <Hauptthema> stands for whatever is entered on the sensor under Connections → Main topic. It only appears in the “Optional” section. Replace it there with your own value.
Requirements
- Home Center 3, Home Center 3 Lite or Yubii Home (Quick Apps are available on all three). For the additional liter/temperature devices: firmware 5.030 or newer.
- Sensor with firmware 4.2.8 on the same network as the hub, with a fixed IP address (assign it permanently in the router).
- Power saving mode on the sensor off (otherwise see “Optional”).
Setting up the sensor
For the HTTP method, nothing needs to be set on the sensor. Just check that http://<IP des Sensors>/measurements shows measured values in the browser. If authentication is switched on at the sensor (under System), you need the login and password for step 3.
Setup
-
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.
-
Fill in the dialog:
Field Value Name Füllstand(freely selectable)Room as you like Device type Multilevel sensor ( com.fibaro.multilevelSensor) -
Open the new Quick App, tab Edit & Preview, replace the existing code completely with this one and adjust the lines marked with
<<<:-- Senvolon Level Sensor -> Fibaro HC3 / Yubii Home (HTTP) local SENSOR_IP = "192.168.1.50" -- <<< ANPASSEN: IP-Adresse des Sensors local LOGIN = "" -- <<< nur bei eingeschalteter Anmeldung am Sensor local PASSWORD = "" -- <<< nur bei eingeschalteter Anmeldung am Sensor local CHILDREN = false -- <<< true: Zusatzgeräte für Liter und Temperatur local INTERVAL = 60 -- Abfrage alle 60 Sekunden class 'Litres' (QuickAppChild) function Litres:__init(device) QuickAppChild.__init(self, device) end function Litres:show(d) if type(d.filling) == "number" then self:updateProperty("value", d.filling) end end class 'Temperature' (QuickAppChild) function Temperature:__init(device) QuickAppChild.__init(self, device) end function Temperature:show(d) if type(d.temperature) == "number" then self:updateProperty("value", d.temperature) end end function QuickApp:onInit() self.url = "http://" .. SENSOR_IP .. "/measurements" if LOGIN ~= "" then self.url = self.url .. "?login=" .. LOGIN .. "&password=" .. PASSWORD end self.http = net.HTTPClient({timeout = 5000}) self.fails = 0 self:updateProperty("unit", "%") self:initChildDevices({ ["com.fibaro.multilevelSensor"] = Litres, ["com.fibaro.temperatureSensor"] = Temperature, }) if CHILDREN and next(self.childDevices) == nil then self:createChildDevice({name = "Inhalt (Liter)", type = "com.fibaro.multilevelSensor"}, Litres) self:createChildDevice({name = "Temperatur", type = "com.fibaro.temperatureSensor"}, Temperature) end self:poll() end function QuickApp:poll() self.http:request(self.url, { options = {method = "GET"}, success = function(response) self:onReply(response) end, error = function(message) self:onFail(message) end, }) fibaro.setTimeout(INTERVAL * 1000, function() self:poll() end) end function QuickApp:onReply(response) local ok, d = pcall(json.decode, response.data) if response.status ~= 200 or not ok or type(d) ~= "table" then self:onFail("HTTP " .. tostring(response.status)) return end self.fails = 0 pcall(function() self:updateProperty("dead", false) end) if type(d.rel_level) ~= "number" then self:debug("Sensor hat noch keinen Messwert") return end self:updateProperty("value", d.rel_level) for _, child in pairs(self.childDevices) do child:show(d) end if d.problem then self:debug("Sensor meldet ein Messproblem") end end function QuickApp:onFail(message) self.fails = self.fails + 1 self:debug("Sensor nicht erreichbar: " .. tostring(message)) if self.fails >= 3 then pcall(function() self:updateProperty("dead", true) end) end end -
Save. The Quick App starts immediately and polls the sensor.
Quick test
- After a few seconds, the “Füllstand” device shows the same percentage as the sensor's main page.
- The Quick App's log contains no “Sensor nicht erreichbar” line.
- Counter-check: enter a wrong IP in the code and save. Every minute, “Sensor nicht erreichbar” appears. Then set it back to the correct one.
Optional
Liters and temperature: Set CHILDREN = true and save. Two additional devices, “Inhalt (Liter)” and “Temperatur”, are created once. Liters only make sense if the tank geometry is stored on the sensor.
Power saving mode on the sensor: The sensor then responds over HTTP only during its short wake phases, so the query mostly goes nowhere. Use MQTT instead: the sensor reports the fill level to an MQTT broker (e.g. Mosquitto on a NAS; the Fibaro hub itself is not a broker), and the Quick App subscribes to the topic. The broker keeps the last value. Configure the sensor as described in the user manual under Connections and MQTT Broker. Then create the Quick App as above, but with this code:
-- Senvolon Level Sensor -> Fibaro HC3 / Yubii Home (MQTT)
local BROKER = "mqtt://192.168.1.10" -- <<< ANPASSEN: Adresse des Brokers
local PORT = 1883 -- <<< ANPASSEN, falls abweichend
local TOPIC = "stat/<Hauptthema>/REL_LEVEL" -- <<< ANPASSEN: <Hauptthema> ersetzen
function QuickApp:onInit()
self:updateProperty("unit", "%")
self.client = mqtt.Client.connect(BROKER, {port = PORT, clientId = "hc3_fuellstand"})
self.client:addEventListener('connected', function(event)
self.client:subscribe(TOPIC)
end)
self.client:addEventListener('message', function(event)
local v = tonumber(event.payload)
if v then self:updateProperty("value", v) end
end)
end
If the broker requires a username and password, enter them in the options of mqtt.Client.connect. The names of the options are in the Fibaro article on the MQTT client (link below).
Limitations
- Read-only: the sensor cannot be configured over HTTP.
- In power saving mode, the sensor responds over HTTP only when it is awake, so better use the MQTT version.
- The value is up to 60 seconds old. If the sensor fails, the last value stays. After three failed attempts, the Quick App marks the device as unreachable. The Quick App's log then shows “Sensor nicht erreichbar”.
- After a broker outage, the MQTT version does not reconnect on its own. In that case, save the Quick App once more or restart the hub.
- Login and password are stored in plain text in the code and must not contain special characters such as
&,#,?or spaces.
Verification status
The code is based on Lua 5.3.6. Information about the hub comes from the Fibaro documentation:
- Quick Apps (creating,
net.HTTPClient,requestwithoptions/success/error,response.data/response.status,json.decode,fibaro.setTimeout,updateProperty,self:debug): https://manuals.fibaro.com/home-center-3-quick-apps/ - Child devices (
QuickAppChild,createChildDevice,initChildDevices,childDevices, from firmware 5.030): https://manuals.fibaro.com/knowledge-base-browse/hc3-quick-apps-managing-child-devices/ - MQTT client (
mqtt.Client.connect,addEventListener,subscribe,event.payload): https://manuals.fibaro.com/knowledge-base-browse/hc3-quick-apps-mqtt-client/