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


  • 1

QA: Presence simulation


Question

Posted

subj!

 

configuring:

 

local rooms = {
    "Section1/roomName1",
    "Section1/roomName3",
    "Section2/roomName7",
    "Section2/roomName5",
    "Section1/roomName13"
}
-- just sectionName slash roomName
-- "GroundFloor/WC"
 
local exclusion = {}
-- You can provide here DeviceId's what you wnat to exclude from simulation
 
local timestr = "$Sunset..23:00"
local timestr = "19:00..23:00"

 

just period when simulator works

startTime..endTime

 

You can start and stop emulator manuall via button or via scene

Please login or register to see this code.

 

enabled / disabled action you can configure via triggering in scene

- alarm system

- switching profiles to AWAY

- etc

 

Please login or register to see this attachment.

  • Thanks 2

10 answers to this question

Recommended Posts

  • 0
Posted

Hi @10der,

 

Thanks for that! I uploaded the QA but I get the following error after enabling it:

Please login or register to see this code.

It relates to the checkOff() line, part of the local function doSimulate(rndlight) function.  I have not changed anything besides the sections/rooms definitions on top.

 

Furthermore, and probably related to, is that I cannot disable the QA - the buttons don't seem to change its state.

 

Thanks for your time!

  • 0
Posted

for me the same problem:[01.12.2021] [21:54:01] [ERROR] [QUICKAPP499]: main.lua:64: attempt to call a nil value (global 'checkOff')

  • 0
Posted

Yes,

local function doSimulate(rndlight) calls local function checkOff() that is declared afterwards.

Open the QA and change

Please login or register to see this code.

to

Please login or register to see this code.

I will not guarantee that it works but it will at least fix the missing checkOff function

 

The QA will not enable/disable as it isn't checking the enabled state when it starts up

  • 0
Posted (edited)
On 12/1/2021 at 10:08 PM, jgab said:

Yes,

local function doSimulate(rndlight) calls local function checkOff() that is declared afterwards.

Open the QA and change

Please login or register to see this code.

to

Please login or register to see this code.

I will not guarantee that it works but it will at least fix the missing checkOff function

 

The QA will not enable/disable as it isn't checking the enabled state when it starts up

 

I changed the above and the below lines for room + timestr, but still got an error. 

 

Debug: 

26.01.2022] [12:17:00] [DEBUG] [QUICKAPP96]: onInit[26.01.2022] [12:17:00] [DEBUG] [QUICKAPP96]: Begane grond/Woonkamer [40][26.01.2022] [12:17:00] [DEBUG] [QUICKAPP96]: the section of room name Section1/roomName3 not found[26.01.2022] [12:17:00] [DEBUG] [QUICKAPP96]: the section of room name Section2/roomName7 not found[26.01.2022] [12:17:00] [DEBUG] [QUICKAPP96]: the section of room name Section2/roomName5 not found[26.01.2022] [12:17:00] [DEBUG] [QUICKAPP96]: the section of room name Section1/roomName13 not found[26.01.2022] [12:17:00] [ERROR] [QUICKAPP96]: QuickApp crashed[26.01.2022] [12:17:00] [ERROR] [QUICKAPP96]: main.lua:172: attempt to compare nil with number

 

Changed rooms & timestr: 

local rooms = {
    "Begane grond/Woonkamer",
    "Section1/roomName3",
    "Section2/roomName7",
    "Section2/roomName5",
    "Section1/roomName13"
}
local exclusion = {}
local timestr = "$12:00..13:00"
 
 
Edited by pnutp0wer
  • 0
Posted
On 9/9/2020 at 7:29 PM, 10der said:
ocal timestr = "$Sunset..23:00"
local timestr = "19:00..23:00"

 

Just imported the QA again, I changed the sections and it was working.

 

When I changed the timestr to "12:45..14:00" the QA crashed with the same error as above. Am I doing this wrong? Do you need to change other elements too? 

  • 0
  • Inquirer
  • Posted

    Please login or register to see this code.

     

     

    Please login or register to see this code.

     

    so, QA is started

    and will use 628,1990,2201,2211

    devices as Presence simulation

     

    • 0
    Posted

    anyone got this QA working? I don't, it does start, gives me the configured room and light id's, but nothing seems to happen after that in the timeslot.

     

    Description is very limited and unclear.

    • 0
    Posted (edited)

    This code is a QuickApp for the Fibaro Home Center 3 (HC3). Its purpose is to simulate human presence by randomly turning lights on and off in specific rooms during a defined time window.

    Here is a breakdown of how the script works:


    1. Configuration (The "Who" and "When")

    At the top of the script, you define your settings:

    • rooms: A list of rooms to include in the simulation (format: "Section/RoomName"). Currently, only "Upstairs/Office" is active.

    • exclusion: A list where you can put specific Device IDs you want the script to ignore (e.g., a nightlight you never want to trigger).

    • timestr: The time window. In your code, it is set to 12:45 to 14:00. This function is quite advanced; it can also handle keywords like $Sunset or $Sunrise.


    2. Initialization (initRooms)

    When the QuickApp starts (onInit), it performs a "discovery" phase:

    1. It scans your entire HC3 for sections and rooms.

    2. It filters for devices that are enabled, visible, and specifically marked with the property isLight = true.

    3. It groups these light IDs into the fake_devices table.

      • Based on your logs, it found 4 lights in the Office: [628, 1990, 2201, 2211].


    3. The Logic Loop (check)

    The script runs a check every minute (setInterval). Here is the logic it follows:

    Step A: Time Validation

    The between(timestr) function checks if the current time is within the allowed window.

    • If YES: It proceeds with the simulation.

    • If NO: It calls allOff() to ensure all lights used in the simulation are turned off once the window expires.

    Step B: Turning Lights ON (doSimulate)

    If the simulation is active:

    1. It picks a room at random from your list.

    2. It checks the lights in that room. If a light is currently OFF, it turns it ON.

    Step 😄 Turning Lights OFF (checkOff)

    This is what makes the simulation look "real":

    • The script doesn't just turn lights on; it checks how long they have been on.

    • It generates a random number between 1 and 30 minutes. If a light has been on longer than that random duration, the script turns it OFF.


    4. Strengths and Weaknesses

    Strengths Weaknesses / To Watch
    Realistic Behavior: Lights don't stay on forever; they turn off after a random duration (1–30 mins). Fixed Time Window: Your current setting (12:45) is mid-day. For real security, you’d usually use $Sunset..23:00.
    Automatic Discovery: It finds your lights automatically based on the room name; no need to manually find IDs. One Room at a Time: In each 1-minute cycle, it only picks one room to "activate," which might be slow if you have 10 rooms.
    Section Support: Great for large houses with many sections. Emulator Dependency: The very first lines are for a developer's local emulator; they aren't needed for the HC3 itself.

    How to adjust it

    1. Change the Schedule: Edit local timestr = "12:45..14:00" to something like local timestr = "$Evening..23:30" (Sunset until 11:30 PM).

    2. Add More Rooms: Remove the dashes (--) in the rooms list or add your own following the "Section/Room" format.

    3. Manual Control: The script includes functions for buttons (onBtnOn / onBtnOff). You should see an "Enabled" label on your QuickApp interface to tell you if the simulation is currently armed.

     

    (Gemini 3)

    Edited by Julien6
    • 0
    Posted

    @Julien6 are you an AI bot or spam account reacting on a post from January 2022? 

    • 0
    Posted

    Yes, from Openclaw framwork.

    Lol, I'm joking. I'm a human but I recognise I used Gemini 3

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