Jump to content
  • 0

How to getValue from a label in a VD ?


Question

How to get the vlaue from a label in a VD ?

 

I want to read the status from a label in a VD, how to do so?

 

if  fibaro:getValue(189, "ui.verandaspots.value") == 'ON' then
  
fibaro:debug("TEST")
  
end

 

Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 1

This is correct... please note you should use label's ID and not label value.

if  fibaro:getValue(189, "ui.verandaspots.value") == 'ON' then

                                                    label ID

Capture.PNG.3f37d8a694585817f60e2f9d23fa5081.PNG

Link to post
Share on other sites
  • 0

How can I Debug the Value, by me stand all the time "Nil"?

 

 fibaro:debug(fibaro:getValue(488, "ui.Labe3.value"))
nil.JPG.ea39bc8e697c91170b7871a82f88ee4e.JPG

Edited by Jothebone
Link to post
Share on other sites
  • 0

@Jothebone

 

If you're interested

 

"universal" get:

function getPowerState(dev)
    if dev.powers ~= nil then
        for i, id in ipairs(dev.powers) do
            if fibaro:getType(id) == "virtual_device" then
                local statusLabel = dev.powers.status or "lblStatus"
                local state = fibaro:getValue(id, "ui." .. statusLabel .. ".value")
        		if tonumber(state) ~= nil then
          			return tonumber(state), os.time()
				else
                	if state == "ON" then
            			return 1, os.time()
                	end
          		end
            else
                local deviceState, deviceLastModification = fibaro:get(id, "value")
                if (tonumber(deviceState) > 0) then
                    return tonumber(deviceState), deviceLastModification
                end
            end
        end
        return 0, 0
    else
        return 0, 0
    end
end

 

"universal" set

 

function setPowerState(dev, value)
    if dev.powers ~= nil then
        local function hex2rgb(hex)
            local hex = hex:gsub("#", "")
            return tonumber("0x" .. hex:sub(1, 2)), tonumber("0x" .. hex:sub(3, 4)), tonumber("0x" .. hex:sub(5, 6))
        end

        for i, id in ipairs(dev.powers) do
            local lightType = GetDeviceType(id)
            if (lightType == "com.fibaro.multilevelSwitch") then
                if type(value) == "string" then
                    fibaro:call(id, value)
                else
                    fibaro:call(id, "setValue", value)
                end
            elseif (lightType == "com.fibaro.RGBW") then
                if type(value) == "string" then
                    local r, g, b = hex2rgb(value)
                    fibaro:call(id, "setColor", r, g, b, 0)
                else
                    if value > 0 then
                        fibaro:call(id, "setBrightness", value);
                    else
                        fibaro:call(id, "turnOff")
                    end
                end
            elseif lightType == "com.fibaro.binarySwitch" then
                if value > 0 then
                    fibaro:call(id, "turnOn")
                else
                    fibaro:call(id, "turnOff")
                end
            elseif lightType == "virtual_device" then
                -- on = 1, off = 2
                local btnOn = dev.powers.on or "1"
                local btnOff = dev.powers.off or "2"
                local sliderName = dev.powers.slider or "2"
                if value > 0 then
                    if value ~= 99 then
                        fibaro:call(id, "setSlider", sliderName, value); 
                    else
                        fibaro:call(id, "pressButton", btnOn)
                    end
                else
                    fibaro:call(id, "pressButton", btnOff)
                end
            else
                if value > 0 then
                    fibaro:call(id, "turnOn")
                else
                    fibaro:call(id, "turnOff")
                end
            end
        end
    end
end

function idIsInList(id, list)
    for i = 1, #list do
        if (id == list[i]) then
            return true
        end
    end
    return false
end

local RGBWDeviceType = {"com.fibaro.RGBW", "com.fibaro.colorController", "com.fibaro.FGRGBW441M"}
local BinaryDeviceType = {"com.fibaro.binarySwitch", "com.fibaro.FGWP101", "turnOn"}
local DimmerDeviceType = {"com.fibaro.multilevelSwitch", "com.fibaro.FGD212"}

function GetDeviceType(itemId)
    local deviceType = fibaro:getType(itemId)
    if (idIsInList(deviceType, RGBWDeviceType)) then
        deviceType = "com.fibaro.RGBW"
    elseif (idIsInList(deviceType, BinaryDeviceType)) then
        deviceType = "com.fibaro.binarySwitch"
    elseif (idIsInList(deviceType, DimmerDeviceType)) then
        deviceType = "com.fibaro.multilevelSwitch"
    elseif (deviceType == " com.fibaro.philipsHue") then
        deviceType = "Philips.Hue"
    end
    return deviceType
end

 

 

Link to post
Share on other sites
  • 0

bonjour

 

Comment récupéré la valeur d'une étiquette dans un VD?

 

ça ne fonctionne pas 🤥

 


How to recover the value of a label in a VD ?

it does not work

local comptid     = fibaro:getValue(484, "ui.label4.value")
fibaro:debug("MOYENPOMPE>>> " ..comptid)

merci de votre aide


Thank you for your help

 

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...