Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Search the Community

Showing results for tags 'global vars'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • FIBARO Community
    • FIBARO Portal and Forum policy
    • FIBARO
    • Say hello!
    • Off-topics
  • FIBARO Update
    • FIBARO System Update
    • FIBARO Mobile Update
  • FIBARO Community Support
    • Scenes and Interface
    • FIBARO Products
    • FIBARO Mobile
    • FIBARO HomeKit
    • FIBARO Assistant Integrations
    • Other Devices / Third-party devices
    • Tutorials and Guides
    • Home Automation
    • Suggestions
  • FIBARO Społeczność
    • FIBARO
    • Przywitaj się!
    • Off-topic
  • FIBARO Aktualizacja
    • FIBARO System Aktualizacja
    • FIBARO Mobile Aktualizacja
  • FIBARO Wsparcie Społeczności
    • Sceny i Interfejs
    • FIBARO Urządzenia
    • FIBARO Mobilnie
    • FIBARO HomeKit
    • Integracja z Amazon Alexa i Google Home
    • Urządzenia Firm Trzecich
    • Poradniki
    • Automatyka Domowa
    • Sugestie

Categories

  • Scenes
  • Virtual Devices
  • Quick Apps
  • Icons

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Facebook


Google+


Skype


Website URL


WhatsApp


Country


Gateway/s


Interests

Found 2 results

  1. How do I create a Global Variable from LUA in HC3? I'm trying to create a light dimmer function for Philips HUE using a Logic Group Matrix ZDB5100 switch so when I hold the Button its starts dimming up or down. But to keep track if the button is released and pressed again I need to keep track of the direction from last time it was pressed. So I'm thinking of using an Enumerated global variable "dimDirection" that can be set to Up or Down. I want the code to create the variable if not present. My working code whiteout remembering dimDirection is here https://pastebin.pl/view/d74c93bb In HC2 i used this snippet of code. But how is it in HC3 ? local ProjectorStatus = {On="Tændt", Off="Slukket"}; -- in code you then declare predefined global variable using users mapped values: local varName = { ["Projector"] = { value = ProjectorStatus.On, isEnum = true, isTable = false, enumValue = {ProjectorStatus.On, ProjectorStatus.Off} }, } function checkGlobalVariable(varName) -- Check if variable exist for i , v in pairs(varName) do if fibaro:getGlobalValue(i) == nil then api.post("/globalVariables/", { name = i }); fibaro:sleep(400) api.put("/globalVariables/"..i, { name = i, value = v.value, isEnum = v.isEnum, enumValues = v.enumValue }) if v.isTable then ok, msg = pcall(function() wT = json.decode(fibaro:getGlobalValue(i)) if type(wT) ~= "table" then error() end end ) if not ok then fibaro:debug("ERROR - Creating table was unsuccessful, error code: "..msg) else fibaro:debug("Variable '"..i.."' created successfully."); end else if fibaro:getGlobalValue(i) ~= nil then fibaro:debug("Variable '"..i.."' created successfully."); else fibaro:debug("ERROR - Variable '"..i.."' was NOT created!") end end end -- update all predefined global variables in case user changed default values if v.isEnum then fibaro:debug("Variable '"..i.."' allready exists."); local value = fibaro:getGlobalValue(i) for i,m in pairs(v.enumValue) do if m == value then v.value = value end end if v.value == value then fibaro:debug("For variable '"..i.."' found current value ("..value..") and will keep it") else fibaro:debug("For variable '"..i.."' NOT found current value, will set default value ("..value..")") end api.put("/globalVariables/"..i, { name = i, value = v.value, isEnum = v.isEnum, enumValues = v.enumValue }) fibaro:sleep(400) end end updateVar = true end checkGlobalVariable(varName)
  2. I like to initialize an empty table (like HomeTable) from a scene if it is not exist. I tried the simple following lua code but it fails. -- Check if variable exist if (fibaro:getGlobal(DDDTable) == nil) then fibaro:debug("Creating Variable Table "..varName) jsonDDD = { settings = { version='0.1' }, } jDDDTable = json.encode(jsonDDD) fibaro:setGlobal("DDDTable", jDDDTable) -- store table in global else fibaro:debug('Existing Variable') end It sounds crazy but I stuck on this point for 2 days...and my Bosch/Siemens Home-Connect project (I will share it with you guys) is on halt due to this **small** detail. Any help is more than welcome! P.S. @10der I know that you help people (high appreciate, thank you) like me on first steps... what a fool....! here is the code: api.post("/globalVariables", { name="testTable", value="Table", -- optional }) -- Modify existing variable to "predefined" style api.put("/globalVariables/testTable", { name="testTable", value="Table", -- optional isEnum=true, enumValues= { "Table", } }) here is the source: Another question is howto check if a variable is a table or something gone wrong during writing (human interaction).
×
×
  • Create New...