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


Recommended Posts

Posted (edited)
1 hour ago, jgab said:

Now it barfs on the config.json file - the json format is not correct - you cant't end with a ',' after "fibemuvar":true,

json is more strict than Lua...

 

Hallelujaaaaaa

Jan, sorry, after these hours now i would be really glad, if i could utilize fibemus power.
i need some little explanation, just to know how this is working.


1. I want to develop my ER5 QAs in VS code. Should I create a separate folder in Examples folder, or in .VScode folder, or does it even matter where do I put my files?

 

2. How to use fibemu? Should i copy past every file from Fibaro ER5 QA and paste it into a file in VS code? That is the way it works?

UPDATE: I figured out from description. This can be done, by built-in Tasks. For those who don't know how. Press  Terminal in upper menu. Then select Run Task, then select Download and unpack, then provide the directory in VS code. This will download the given QA and unppack it into lua files. This worked with a simple QA, but when I tried with a ER5 QA it threw error

Please login or register to see this image.

/monthly_2023_12/image.png.6b4c05c147cbcfb0eea7cea2a598ec5c.png" />

 

 

Actually i ran into error with some smaller QA too

Please login or register to see this attachment.

 

3. If i have my file in VS code, and make some changes, how to test them? Is that done through the web UI of emulator? What i see on emulators WEB, it is kinda fake representation of Fibaro's controls, or devices? 

 

4. So when I test it, and seems to be okay, should I copy again my VS code files into Fibaro and replace there the old files?

 

5. When i start debugging the QA_UI.lua example file. It starts to show a couple of events and other stuff in debug window? How to understand them?

image.png.e9b8dbe16f79af4ceb9fcf7d5ab2c03f.png
If i got it properly, this example file creates some binarySwitch and binarySensor and multilevelSwitch etc in onInit function. Where are these devices created?
How to understand this little code?

 

6. Now after you changed your repository, should I do somtehing with this? 

image.png.24f6afe12fceb00a0bccf360a8dd3e1f.png

 

 

Sorry Jan, i am really beginner in fibemu, but i learn really fast :-)

I think i am not alone with questions, maybe some others will find these answers usefull.

Edited by Neo Andersson
  • Topic Author
  • Posted

    Ok, many questions and late in he evening - I'll answer tomorrow morning.

  • Topic Author
  • Posted (edited)

    Instructions for setting up your own development environment.

     

    The '

    Please login or register to see this link.

    ' GitHub repo contains the complete emulator.

    Clone it using git

    >git clone 

    Please login or register to see this link.

    (You can also do it from within vscode)

    This will give you a directory named fibemu. The directory contains the following files/directories

    Please login or register to see this code.

     

    So the emulator files are "hidden" in the .vscode directory. That directory is used by vscode projects to store config files. ex. launch.json

     

    If you just want to play around with the emulator, the .gitignore file specifies 2 subdirectories. 'dev' and 'test' that can be created and where you can create your own files and test.

    The advantage is that you can do

    >git pull

    at any time and get the latest fibemu files and not overwriting your own files that resides in fibemu/test or fibemu/dev as they are marked to be ignored by git.

     

    However, if you want your own git repo for developing you can in principle do that in dev or test as they are ignored but I would recommend to do that in a separate directory with symlinks

    Please login or register to see this image.

    /monthly_2023_12/image.png.a115c9461ccefb27dcc88381bb990990.png" />

     

    On the same level as you have the fibemu directory, make your own development directory ex. 'yourRepo'

    Ex. WIndows

    Please login or register to see this code.

    Now we have a directory where we can develop our own stuff and use the emu files from the fibemu directory. We can switch to the fibemu directory and do git pull when the emulator is updated.

    Then add your own .gitignore file to your new directory with appropriate content:

    Please login or register to see this code.

     

    A special case of this is if you want to develop your own version of EventRunner5. 

    EventRunner5 is itself a GitHub repo.

    Start with cloning the EventRunner5 on the same level as fibemu

    .../fíbemu/...

    .../EventRunner5/...

    .../myEventRunner5/...

    The EventRunner5 directory is a bit more messy

    Please login or register to see this code.

     

    but you do the same .vscode linking here. Creating a .vscode directory that shares the emu files and launch.json with fibemu/.vscode

    In this directory, the .gitignore specifies that all files starting with test_ will be  ignored. So copy EventRunner5.lua to test_EventRunner5.lua and modify rules etc and play with it.

     

    If you want your own repo to develop an EventRunner variation, setup your own parallel directory and link fibemu/.vscode's emufles and launch.json like in the previous example.

    Then copy EventRunner5/EventRunner5.lua and EventRunner5/Include.lua to your directory

    .../myEventRunner5/.vscode

    .../myEventRunner5/config.json

    .../myEventRunner5/EventRunner5.lua

    .../myEventRunner5/Include.lua

     

    and then change the Include.lua file to include the files from the EventRunner5 directory

    Please login or register to see this code.

     

    and you can then run your own  EventRunner5.lua in this directory and have your own repo if you want

    Edited by jgab
  • Topic Author
  • Posted (edited)
    13 hours ago, Neo Andersson said:

    Hallelujaaaaaa

    Jan, sorry, after these hours now i would be really glad, if i could utilize fibemus power.
    i need some little explanation, just to know how this is working.


    1. I want to develop my ER5 QAs in VS code. Should I create a separate folder in Examples folder, or in .VScode folder, or does it even matter where do I put my files?

     

    2. How to use fibemu? Should i copy past every file from Fibaro ER5 QA and paste it into a file in VS code? That is the way it works?

    UPDATE: I figured out from description. This can be done, by built-in Tasks. For those who don't know how. Press  Terminal in upper menu. Then select Run Task, then select Download and unpack, then provide the directory in VS code. This will download the given QA and unppack it into lua files. This worked with a simple QA, but when I tried with a ER5 QA it threw error

    Please login or register to see this link.

     

    The error with include is that the file is missing in fibemu. If you setup an EventRunner5 directory and your own directory like in the previous post you will have an include.lua file.

     

    13 hours ago, Neo Andersson said:

     

    Actually i ran into error with some smaller QA too

    Please login or register to see this attachment.

    Well, this is a bug I haven't fixed - it's actually that you use a html color that is not defined in fibemu. I will fix that today so it defaults to white and logs a warning.... fixed in last commit.

     

     

    13 hours ago, Neo Andersson said:

    3. If i have my file in VS code, and make some changes, how to test them? Is that done through the web UI of emulator? What i see on emulators WEB, it is kinda fake representation of Fibaro's controls, or devices? 

    Yes, you have a "fake" UI for the QAs.

    Use the link at

    Please login or register to see this code.

     

    13 hours ago, Neo Andersson said:

     

    4. So when I test it, and seems to be okay, should I copy again my VS code files into Fibaro and replace there the old files?

    There is a vscode task QA, Update

    that updates the QA on the HC3.

    Note that in the QA file you need to define

    --%%id=<HC3ID>

    so it knows what QA on the HC3 it should update.

     

     

    13 hours ago, Neo Andersson said:

     

    5. When i start debugging the QA_UI.lua example file. It starts to show a couple of events and other stuff in debug window? How to understand them?

    Please login or register to see this link.

     

    The [refresh] log is the system events from the HC3.

    You can turn them off with

    --%%debug=refresh:false

     

    13 hours ago, Neo Andersson said:

     

    If i got it properly, this example file creates some binarySwitch and binarySensor and multilevelSwitch etc in onInit function. Where are these devices created?
    How to understand this little code?

    Yes, you can create "fake" devices to interact with.

    This is how I setup a HT with some fake devices to test with

    Please login or register to see this code.

    You can also set

    --%%remote=devices:*

    to allow the emulator to make calls to the devices/QAs on the HC3.

     

     

     

    13 hours ago, Neo Andersson said:

     

    6. Now after you changed your repository, should I do somtehing with this? 

    Please login or register to see this link.

    Do a git pull. It's in the Source Control tab in vscode under the '...' menu.

     

     

    13 hours ago, Neo Andersson said:

     

    Sorry Jan, i am really beginner in fibemu, but i learn really fast :-)

    I think i am not alone with questions, maybe some others will find these answers usefull.

     

    It has a million of features... let's take them one by one :-) 

    Edited by jgab
  • Topic Author
  • Posted

    Oh, and I recommend enabling the Lua language server to get better Lua syntax checking

    Please login or register to see this attachment.

     

    ...and then try out copilot

    Please login or register to see this attachment.

    I believe you get 30days free and then it costs $100/year

  • Topic Author
  • Posted

    So, fibemu only knows about a limited set of colours when using <font color=...> in log outputs.

    The colour table is in .vscode/emufiles/lua/utils.lua

    The table is also exported to os.COLORMAP

    So if you have a color 'seafoamblue' that normally works on the HC3 it may be so it is just rendered as normal text color in the vscode console.

    Because you have access to the colormap you can do

    Please login or register to see this code.

    to map that to another color in fibemu.

    If you want to create your own color it needs to be an ascii escape sequence.

    Please login or register to see this code.

     

    Posted
    3 hours ago, jgab said:

    Instructions for setting up your own development environment.

     

    The '

    Please login or register to see this link.

    ' GitHub repo contains the complete emulator.

    Clone it using git

    >git clone 

    Please login or register to see this link.

    (You can also do it from within vscode)

    This will give you a directory named fibemu. The directory contains the following files/directories

    Please login or register to see this code.

     

    So the emulator files are "hidden" in the .vscode directory. That directory is used by vscode projects to store config files. ex. launch.json

     

    If you just want to play around with the emulator, the .gitignore file specifies 2 subdirectories. 'dev' and 'test' that can be created and where you can create your own files and test.

    The advantage is that you can do

    >git pull

    at any time and get the latest fibemu files and not overwriting your own files that resides in fibemu/test or fibemu/dev as they are marked to be ignored by git.

     

    However, if you want your own git repo for developing you can in principle do that in dev or test as they are ignored but I would recommend to do that in a separate directory with symlinks

    Please login or register to see this link.

     

    On the same level as you have the fibemu directory, make your own development directory ex. 'yourRepo'

    Ex. WIndows

    Please login or register to see this code.

    Now we have a directory where we can develop our own stuff and use the emu files from the fibemu directory. We can switch to the fibemu directory and do git pull when he emulator is updated.

    Then add your own .gitignore file to your new directory with appropriate content:

    Please login or register to see this code.

     

    A special case of this is if you want to develop your own version of EventRunner5. 

    EventRunner5 is itself a GitHub repo.

    Start with cloning the EventRunner5 on the same level as fibemu

    .../fíbemu/...

    .../EventRunner5/...

    .../myEventRunner5/...

    The EventRunner5 directory is a bit more messy

    Please login or register to see this code.

     

    but you do the same .vscode linking here. Creating a .vscode directory that shares the emu files and launch.json with fibemu/.vscode

    In this directory, the .gitignore specifies that all files staring with test_ will be  ignored. So copy EventRunner5.lua to test_EventRunner5.lua and modify rules etc and play with it.

     

    If you want your own repo to develop an EventRunner variation, setup your own parallel directory and link fibemu/.vscode's emufles and launch.json like in the previous example.

    Then copy EventRunner5/EventRunner5.lua and EventRunner5/Include.lua to your directory

    .../myEventRunner5/.vscode

    .../myEventRunner5/config.json

    .../myEventRunner5/EventRunner5.lua

    .../myEventRunner5/Include.lua

     

    and then change the Include.lua file to include the files from the EventRunner5 directory

    Please login or register to see this code.

     

    and you can then run your own  EventRunner5.lua in this directory and have your own repo if you want

    Ehh, this is at this point way beyond my comprehension. There is a lot of stuff that i don't even understand..My goal is to develop my own ER5 QA that holds my rules and some more files specific to my projects. First i think , i will focus on simple file development, not ER5, as this is too much for me now. I dont know symlink usage, as well as don't have knoledge about directives. BTW i was looking for some description, how those dricetives work. I could not find a sinlge line abouut directives. Are they LUA specific commands? Wheree to google their usage? What are they in general? So there is a lot to study before i will try to go through steps from the example above, to develop my ER5 QA in VS code., however this is my major goal.

    Posted (edited)

    Jan, i am out of my home, trying to setup things on other computer. Did the same process as at home, but got this error. Did i mess up something again? Can I even work remotely? Can we reach HC3 somehow through cloud? I dont think so..right? Is this error related to being out of my home network?

     

    Please login or register to see this attachment.

    Edited by Neo Andersson
  • Topic Author
  • Posted
    13 minutes ago, Neo Andersson said:

    Jan, i am out of my home, trying to setup things on other computer. Did the same process as at home, but got this error. Did i mess up something again?

     

    Please login or register to see this attachment.

    Never seen it. On the other hand I run always on MacOS....

    Googling someone that got the same error

     

    File "C:\Users\Frisan\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 428, in run_asgi

     

    leads to some tweaking of cache files on Windows....

     

    Please login or register to see this link.

    OP

    Please login or register to see this link.

    This here solved my problem

    Please login or register to see this link.

    Posted
    29 minutes ago, jgab said:

    Never seen it. On the other hand I run always on MacOS....

    Googling someone that got the same error

     

    File "C:\Users\Frisan\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 428, in run_asgi

     

    leads to some tweaking of cache files on Windows....

     

    Please login or register to see this link.

    OP

    Please login or register to see this link.

    This here solved my problem

    Please login or register to see this link.

    The same error appears, after trying to open the web UI.. I don't know if its even worht to set this up in remote network. How can it access HC3 calling a local IP when i am out of home?

    Please login or register to see this attachment.

  • Topic Author
  • Posted
    15 minutes ago, Neo Andersson said:

    The same error appears, after trying to open the web UI.. I don't know if its even worht to set this up in remote network. How can it access HC3 calling a local IP when i am out of home?

    Please login or register to see this attachment.

    No, that doesn't work. The emulator needs direct access and you don't want to open ports...

    Posted (edited)

    @jgab Jan, i am trying fibemu with a non ER5 base file but

     

     

    1. The web UI doesn't show Qauickapp variables

     

    Please login or register to see this attachment.

    2. Buttons doesn't intercat..so i press them, but doesnt happen what should happen when on HC3

    Do i miss some other configuration? I have added the %%remote%% directives as per your insturcions..but still nothing

     

    Please login or register to see this attachment.

     

     

    3. VS code, lua debugger complains about undefined function..like on eaxmple picture below..the load_shs_function...

    This function is defined in another file..that i can see in directicves that is set..

    --%%file=dev/HouseCheck_helpers.lua,helpers;

     

    So why is it complaining?

     

    Please login or register to see this image.

    /monthly_2024_01/image.png.8054ac90d8d71428e0721c711dca4c85.png" />

     

    Edited by Neo Andersson
  • Topic Author
  • Posted

    0. Can you post the whole QA file so I can have a look at it?

    1. Have you set/defined any in the QA?

    2.Seems like you are missing some directives.

    3. I believe it's complaining that you have global function and variables that start with lowercase. What does it say if you shower the pointer overt the names?

    The "Lua style" is that they should start with a capital letter (there are directives to the Lua syntax checker to ignore it)

     

    Posted
    11 minutes ago, jgab said:

    0. Can you post the whole QA file so I can have a look at it?

    1. Have you set/defined any in the QA?

    2.Seems like you are missing some directives.

    3. I believe it's complaining that you have global function and variables that start with lowercase. What does it say if you shower the pointer overt the names?

    The "Lua style" is that they should start with a capital letter (there are directives to the Lua syntax checker to ignore it)

     

    Jan i just run the task copy/unpak and added the remote directive nothing more

    --%%name=HouseCheck
    --%%type=com.fibaro.genericDevice
    --%%id=2323
    --%%u={{button="btnTimeOfRunDown",text="Time -",onReleased="btnTimeOfRunDownClick"},{button="btnTimeOfRun",text="Button",onReleased="btnTimeOfRunClick"},{button="btnTimeOfRunUp",text="Time +",onReleased="btnTimeOfRunUpClick"}}
    --%%u={label="lastrunLBL",text="***"}
    --%%u={{button="btnStartCheckNow",text="Start NOW",onReleased="turnOn"},{button="btnSetscheduled",text="Set schedule",onReleased="btnSetscheduledClick"}}
    --%%u={label="lblInfo",text="..."}
    --%%u={{button="btnManageIP",text="---",onReleased="btnManageIPclick"},{button="btnRight",text=">>>>",onReleased="btnRightClick"}}
    --%%file=dev/HouseCheck_fibaroExtra.lua,fibaroExtra;
    --%%file=dev/HouseCheck_shsExtra.lua,shsExtra;
    --%%file=dev/HouseCheck_voiceHelpers.lua,voiceHelpers;
    --%%file=dev/HouseCheck_helpers.lua,helpers;
    --%%remote=devices:*
     
    function QuickApp:onInit()
        installerUser = { 2711 }
        self.startpattern = "<span><b><font color=#fcba03>"
        self.endpattern = "</b></span>"
        companytext = "® WWW.SMARTHOMESIMPLE.SK"
        time_of_run = ""
        lastly_set_time_of_run = ""
        companytext = "® WWW.SMARTHOMESIMPLE.SK"
        scheduledrun = false
        actionRef = nil
     
        load_shs_Functions()
        shs.logprint("************* Housecheck remastered started ************************* ", "colored")
        refnow = nil
        lights_to_turn_off = { 111, 622, 628, 644, 656, 663, 1002, 227 } --lights
        doors_to_lock = {}                                      -- 1241,2191 doors
        alarms_to_arm = {}                                      -- alarms
        blinds_to_close = {}                                    --236,392,634 --blinds
        heating_to_check = {}                                   -- heating devices / thermostats
        windows_sensors_to_check = { 1498, 1501, 536, 2774 }    --57,536, 102,116 -- window sensors
        doors_sensors_to_check = {}                             --{127,691} --127,691 --door sensors
        devices_to_set_value = {}                               --devices that needs to set values of.
        garages_to_close = { 2142 }
        gates_to_close = { 2143 }
     
        alldeviceIdsInUse = { 111, 622, 628, 644, 656, 663, 1002, 227, 1241, 2191, 236, 392, 634, 1498, 1501, 536, 2774, 2142, 2143 }
     
        loadHelpers()
        loadDeviceActions()
        checkGlobals()
     
        time_of_run = self:getVariable("timeofrun")
        demomode = self:getVariable("demomode")
        demomode = shs.toBool(demomode)
        scheduledrun = self:getVariable("scheduledrun")
        silentmode = self:getVariable("silentmode")
        silentmode = shs.toBool(silentmode)
        scheduledrun = shs.toBool(scheduledrun)
        lastrun = self:getVariable("lastrun")
        self:updateView("lastrunLBL", "text", "Last run:" .. lastrun)
     
        self:declareEvent()
        initDefaultTexts()
        initVariables()
        self:setDemomode(demomode)
        self:setScheduledRun(scheduledrun)
        self:readDeviceIDs()
        self:readUserIDs()
        self:print_info(companytext)






     
        fibaro.event({ type = 'global-variable' },
            function(env)
                if env.event.name == "google_ips" or
                    env.event.name == "cast_language" or
                    env.event.name == "nest_volume" then
                    checkGlobals()
                end
            end)
     
        self:initalDeviceCheck(alldeviceIdsInUse)
    end --oninit end
     
    function QuickApp:initalDeviceCheck(tablestocheck)
        local newmsg = ""
        local hcname = api.get("/settings/info").hcName
        local msg = ""
        local singleDev
        if type(tablestocheck) ~= "table" then tablestocheck = { tablestocheck } end
     
        for key, dev in pairs(tablestocheck) do
            msg = shs.deviceOkay(dev)
            newmsg = newmsg .. msg
        end
     
        if newmsg == "" then
            newmsg = "Device control.\nIn object: " .. hcname ..
                " in function Housecheck all devices are okay. "
            shs.logprint(newmsg)
        else
            newmsg = "Device control.In object: " .. hcname .. " in function Housecheck:\n" .. newmsg
            shs.sendUserPush(installerUser, newmsg)
        end
     
        return newmsg
    end
     
    --**********************TURNING ON DEVICE - FOR MANUAL RUN ************************************************************************************
    function QuickApp:turnOn()
        if self.value == true then return end
        shs:logprint("SHS Manual Housecheck Turned On")
        self:updateProperty("value", true)
        self:runHouseCheck()
    end
     
    function QuickApp:runHouseCheck()
        if self.value == true then return end
     
        shs.logprint("SHS Housecheck running...")
        self:updateProperty("value", true)
        lastrun = os.date("%Y-%m-%d %H:%M")
        self:updateView("lastrunLBL", "text", "Last run:" .. lastrun)
        self:setVariable("lastrun", lastrun)
        self:updateView("lastrunLBL", "text", lastrun)
        initDefaultTexts()
        initVariables()
     
        actionRef = fibaro.sequence(table.unpack(createDelayedActions()))
    end
     
    --***********************Setting scheduleed run or not ***************************************************************
    function QuickApp:setScheduledRun(newState)
        --if not direclty given mode in argument, we just toggle the demomode else
        --we set demomode to mode by first setting to oposite then toggle
        if newState ~= nil then
            scheduledrun = newState
        end
     
        if not scheduledrun then
            self:updateView("btnTimeOfRun", "text", "Disabled")
            self:cancelPostedEvent()
            self:setVariable("scheduledrun", "false")
        else
            self:setVariable("scheduledrun", "true")
            if not refnow and shs.isValidTimeString(time_of_run) then
                self:updateView("btnTimeOfRun", "text", "🕙" .. time_of_run)
                self:postHousecheckEvent(time_of_run)
            else
                shs.logprint("REF already exists " .. tostring(refnow), "warning")
                self:updateView("btnTimeOfRun", "text", "Enabled")
            end
        end
    end
     
    function QuickApp:declareEvent()
        fibaro.cancel(refnow)
        refnow = nil
     
        self:event({ type = 'runHouseCheck2' },
            function()
                self:runHouseCheck()
                self:postHousecheckEvent(time_of_run)
                shs.logprint("Next housecheck event declared " .. tostring(refnow), "warning")
            end)
    end
     
    --*********SET SCHEDULED EVENT**************************************************************************
    function QuickApp:btnSetscheduledClick()
        self:postHousecheckEvent(time_of_run)
    end
     
    --**********CANCEL POSTED EVENT**************************************************************************
    function QuickApp:cancelPostedEvent()
        fibaro.cancel(refnow)
        refnow = nil
    end
     
    --********EVENT POSTING**********************************************************************************
    function QuickApp:postHousecheckEvent(runtime)
        self:cancelPostedEvent()
        self:setVariable("timeofrun", runtime)
        refnow = self:post({ type = 'runHouseCheck2' }, "n/" .. runtime)
        shs.logprint("Housecheck event posted for " .. tostring(refnow), "warning")
        self:updateView("btnTimeOfRun", "text", "🕙" .. time_of_run)
    end
     
    function QuickApp:onInit()
        installerUser = { 2711 }
        self.startpattern = "<span><b><font color=#fcba03>"
        self.endpattern = "</b></span>"
        companytext = "® WWW.SMARTHOMESIMPLE.SK"
        time_of_run = ""
        lastly_set_time_of_run = ""
        companytext = "® WWW.SMARTHOMESIMPLE.SK"
        scheduledrun = false
        actionRef = nil
     
        load_shs_Functions()
        shs.logprint("************* Housecheck remastered started ************************* ", "colored")
        refnow = nil
        lights_to_turn_off = { 111, 622, 628, 644, 656, 663, 1002, 227 } --lights
        doors_to_lock = {}                                      -- 1241,2191 doors
        alarms_to_arm = {}                                      -- alarms
        blinds_to_close = {}                                    --236,392,634 --blinds
        heating_to_check = {}                                   -- heating devices / thermostats
        windows_sensors_to_check = { 1498, 1501, 536, 2774 }    --57,536, 102,116 -- window sensors
        doors_sensors_to_check = {}                             --{127,691} --127,691 --door sensors
        devices_to_set_value = {}                               --devices that needs to set values of.
        garages_to_close = { 2142 }
        gates_to_close = { 2143 }
     
        alldeviceIdsInUse = { 111, 622, 628, 644, 656, 663, 1002, 227, 1241, 2191, 236, 392, 634, 1498, 1501, 536, 2774, 2142, 2143 }
     
        loadHelpers()
        loadDeviceActions()
        checkGlobals()
     
        time_of_run = self:getVariable("timeofrun")
        demomode = self:getVariable("demomode")
        demomode = shs.toBool(demomode)
        scheduledrun = self:getVariable("scheduledrun")
        silentmode = self:getVariable("silentmode")
        silentmode = shs.toBool(silentmode)
        scheduledrun = shs.toBool(scheduledrun)
        lastrun = self:getVariable("lastrun")
        self:updateView("lastrunLBL", "text", "Last run:" .. lastrun)
     
        self:declareEvent()
        initDefaultTexts()
        initVariables()
        self:setDemomode(demomode)
        self:setScheduledRun(scheduledrun)
        self:readDeviceIDs()
        self:readUserIDs()
        self:print_info(companytext)






     
        fibaro.event({ type = 'global-variable' },
            function(env)
                if env.event.name == "google_ips" or
                    env.event.name == "cast_language" or
                    env.event.name == "nest_volume" then
                    checkGlobals()
                end
            end)
     
        self:initalDeviceCheck(alldeviceIdsInUse)
    end --oninit end
     
    function QuickApp:initalDeviceCheck(tablestocheck)
        local newmsg = ""
        local hcname = api.get("/settings/info").hcName
        local msg = ""
        local singleDev
        if type(tablestocheck) ~= "table" then tablestocheck = { tablestocheck } end
     
        for key, dev in pairs(tablestocheck) do
            msg = shs.deviceOkay(dev)
            newmsg = newmsg .. msg
        end
     
        if newmsg == "" then
            newmsg = "Device control.\nIn object: " .. hcname ..
                " in function Housecheck all devices are okay. "
            shs.logprint(newmsg)
        else
            newmsg = "Device control.In object: " .. hcname .. " in function Housecheck:\n" .. newmsg
            shs.sendUserPush(installerUser, newmsg)
        end
     
        return newmsg
    end
     
    --**********************TURNING ON DEVICE - FOR MANUAL RUN ************************************************************************************
    function QuickApp:turnOn()
        if self.value == true then return end
        shs:logprint("SHS Manual Housecheck Turned On")
        self:updateProperty("value", true)
        self:runHouseCheck()
    end
     
    function QuickApp:runHouseCheck()
        if self.value == true then return end
     
        shs.logprint("SHS Housecheck running...")
        self:updateProperty("value", true)
        lastrun = os.date("%Y-%m-%d %H:%M")
        self:updateView("lastrunLBL", "text", "Last run:" .. lastrun)
        self:setVariable("lastrun", lastrun)
        self:updateView("lastrunLBL", "text", lastrun)
        initDefaultTexts()
        initVariables()
     
        actionRef = fibaro.sequence(table.unpack(createDelayedActions()))
    end
     
    --***********************Setting scheduleed run or not ***************************************************************
    function QuickApp:setScheduledRun(newState)
        --if not direclty given mode in argument, we just toggle the demomode else
        --we set demomode to mode by first setting to oposite then toggle
        if newState ~= nil then
            scheduledrun = newState
        end
     
        if not scheduledrun then
            self:updateView("btnTimeOfRun", "text", "Disabled")
            self:cancelPostedEvent()
            self:setVariable("scheduledrun", "false")
        else
            self:setVariable("scheduledrun", "true")
            if not refnow and shs.isValidTimeString(time_of_run) then
                self:updateView("btnTimeOfRun", "text", "🕙" .. time_of_run)
                self:postHousecheckEvent(time_of_run)
            else
                shs.logprint("REF already exists " .. tostring(refnow), "warning")
                self:updateView("btnTimeOfRun", "text", "Enabled")
            end
        end
    end
     
    function QuickApp:declareEvent()
        fibaro.cancel(refnow)
        refnow = nil
     
        self:event({ type = 'runHouseCheck2' },
            function()
                self:runHouseCheck()
                self:postHousecheckEvent(time_of_run)
                shs.logprint("Next housecheck event declared " .. tostring(refnow), "warning")
            end)
    end
     
    --*********SET SCHEDULED EVENT**************************************************************************
    function QuickApp:btnSetscheduledClick()
        self:postHousecheckEvent(time_of_run)
    end
     
    --**********CANCEL POSTED EVENT**************************************************************************
    function QuickApp:cancelPostedEvent()
        fibaro.cancel(refnow)
        refnow = nil
    end
     
    --********EVENT POSTING**********************************************************************************
    function QuickApp:postHousecheckEvent(runtime)
        self:cancelPostedEvent()
        self:setVariable("timeofrun", runtime)
        refnow = self:post({ type = 'runHouseCheck2' }, "n/" .. runtime)
        shs.logprint("Housecheck event posted for " .. tostring(refnow), "warning")
        self:updateView("btnTimeOfRun", "text", "🕙" .. time_of_run)
    end
     

     

    Just now, Neo Andersson said:

    I believe it's complaining that you have global function and variables that start with lowercase.

    No, it is with blue that complains about lowaercase, the yellow complains about undefined function and variable

    2 minutes ago, Neo Andersson said:

    What does it say if you shower the pointer overt the names?

    Please login or register to see this image.

    /monthly_2024_01/image.png.c294a263ea51876b321534e6ebcfb340.png" />

  • Topic Author
  • Posted

    So, the Lua linting mode can be helped if you open the other files in the editor so it sees the other global functions. It doesn't know that you are using the other files always...

     

    The --%% directives in the beginning defines the buttons and their onAction methods.

    Ex.

    --%%u={{button="btnTimeOfRunDown",text="Time -",onReleased="btnTimeOfRunDownClick"},{button="btnTimeOfRun",text="Button",onReleased="btnTimeOfRunClick"},{button="btnTimeOfRunUp",text="Time +",onReleased="btnTimeOfRunUpClick"}}

     

    but I don't see the corresponding QuickApp functions, like function QuickApp:btnTimeOfRunDownClick() ex. ??

     

    The define QuickApp variables use the directive

    Ex.

    Please login or register to see this code.

    defines the QA variable 'timeofrun' to be the Lua string "10:00", and it shows up in the UI. and will be accessible with self:getVariable('timeofrun')

     

    Posted
    4 minutes ago, jgab said:

    but I don't see the corresponding QuickApp functions, like function QuickApp:btnTimeOfRunDownClick() ex. ??

    Because they are not in main file

     

    5 minutes ago, jgab said:

    So, the Lua linting mode can be helped if you open the other files in the editor so it sees the other global functions. It doesn't know that you are using the other files always...

    Well i know nothing about linting mode..on other hand, doesnt fibemu controlling my code? these are the things that are not clear to me

     

    6 minutes ago, jgab said:

    The define QuickApp variables use the directive

    So QA variables, global variables, all must be set manually in fibemu?

     

    Jan there is a lot of use of directives..but nowhere found any turtorial, helper about them..where to search?

  • Topic Author
  • Posted
    4 minutes ago, Neo Andersson said:

    Because they are not in main file

    Because you said that nothing happened when you pressed the buttons I got the feeling that they were not defined.

    Do you see in the log that the below files are loaded?

    Please login or register to see this code.

     

     

    4 minutes ago, Neo Andersson said:

     

    Well i know nothing about linting mode..on other hand, doesnt fibemu controlling my code? these are the things that are not clear to me

    fibemu is the python/lua libraries that provide you with an emulated HC3 environment. Vscode is the editor that gives you hints about your code. A multiple Lua project can be tricky to understand what files are part of it for the editor but if they are opened in the editor it usually scans them and remembers them...

     

    4 minutes ago, Neo Andersson said:

     

    So QA variables, global variables, all must be set manually in fibemu?

    Well, we need some way to tell that these QA variables should be pre-provisioned for the QA - like when we set QA vars in the HC3 web UI.

    You can of course also set and retrieve them with self:getVariable and self:setVariable.

    but you can't do self:getVariable for a variable that is not previously set or pre-provisioned. The --%%var directive allow us to pre-provision QA values.

     

     

    4 minutes ago, Neo Andersson said:

     

    Jan there is a lot of use of directives..but nowhere found any turtorial, helper about them..where to search?

    Check the pdf documentation mentioned in the first post. The chapter on "QA Header configuration"

    Please login or register to see this link.

     

    Posted
    3 minutes ago, jgab said:

    Do you see in the log that the below files are loaded?

    Please login or register to see this attachment.

    7 minutes ago, jgab said:

    Check the pdf documentation mentioned in the first post. The chapter on "QA Header configuration"

    How could i never seen this file...i am reading up and down the entire topic on a daily base, but i missed that one..thanks

    Posted
    10 minutes ago, jgab said:

    fibemu is the python/lua libraries that provide you with an emulated HC3 environment. Vscode is the editor that gives you hints about your code. A multiple Lua project can be tricky to understand what files are part of it for the editor but if they are opened in the editor it usually scans them and remembers them...

    Okay, got the linting, so it seems helping on this..but still lot of comlains about things that are okay..well probably this is more about VS code if i got it correctly

     

    Please login or register to see this attachment.

  • Topic Author
  • Posted

    So there is an error in the file so the QA restarts when you start it up. That can explain why your buttons don't work...

    I'm a bit disappointed that there is no error message though...

    Can you PM me the HouseCheck QA (the .fqa) so I can have a look at it?

    The error could be that there is no QA variables as you expect.... but could also be something else.

    Join the conversation

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

    Guest
    Reply to this topic...

    ×   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...