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 'lua'.
-
Hi All! Is there a way to automatic create labels in VD with LUA? I want to add, or delete labels in VD depending on results of my code. For example if i have a VD displaying humidity sensor values and i add a new sensor the code should add a new label to display its value. Any ideas? Thanks in advance.
-
Hi I have this function function getHueLight(id) local hueIP = 'xxx.xxx.xxx.xxx' local huePort = '80' local hueKey = '--------------------------------' local requestUrl = "http://"..hueIP..":"..huePort.."/api/"..hueKey.."/lights/"..id; local httpClient = net.HTTPClient(); httpClient:request(requestUrl, { options = { headers={}, method='GET' }, success = function (response) fibaro: debug (response. data) end, error = function (err) fibaro: debug ("Error:" .. err) end }); end and i want to assign output of this to variable i've tried somthing like this local var = getHueLight(id) but it's get nil value
-
HC2 & OpenZwave Class: MCO Home MH7 Time Synchronisation
Tom1890 posted a question in Urządzenia Firm Trzecich
hallo, Ich habe mehrere MCO Home MH7 Thermostate in meiner Wohnung installiert. Nach dem Neustart des HC2 wird die Uhr der Thermostate zurückgesetzt. Die meiste Zeit ist die Uhr auf UTC-Zeit statt CET eingestellt. Nachdem sie den Support von MCO Home kontaktiert und gefragt haben, wie sie die Zeit mit LUA zurücksetzen könnten, sagten sie mir, dass sie OpenZWave-konform sind. Ich sollte innerhalb der Klasse "COMMAND_CLASS_TIME_PARAMETERS" den Befehl "TIME_PARAMETERS_SET" verwenden. Weiß jemand, wie ich ZWave-Klassen ( http://www.openzwave.com/dev/classOpenZWave_1_1TimeParameters.html ) in einem LUA-Szenario aufrufen kann ? Danke & Mit freundlichen Grüßen thomas- 2 replies
-
- synchronisation
- time
- (and 4 more)
-
Help please with Scene to control Aircondition ACTRONAIR
Guest posted a question in Scenes and Interface
Hi, I have an ACTRONAIR at Home with Wireless Controller. I have done extensive research to understand how the AC is controlled. It turns out that the AC wireless controller get it's instruction from a Web Service in the cloud. I have intercepted the Web Service Call and this is what get passed on to the cloud: PUT https://actron.ninja.is/rest/v0/device/ACONNECTXXXXXXXXXXXX_0_2_5?user_access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HTTP/1.1 Accept: application/json Content-Type: application/json Referer: https://actronair.com.au/aconnect/ Accept-Language: en-AU,en;q=0.8,ar-LB;q=0.5,ar;q=0.3 Origin: https://actronair.com.au Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393 Host: actron.ninja.is Content-Length: 24 Connection: Keep-Alive {"DA":[0,1,1,0,0,0,0,0]} I need help with creating a Scene that sends instructions to the same cloud service. So far I tried the following without any sucess. Appreciate any guidance please! --[[ %% properties %% events %% globals --]] -- Callback at success local function successCallback(resp) fibaro:debug('connection success, status: ' .. resp.status) end -- Callback at error local function errorCallback(resp) fibaro:debug('connection no success, error: ' .. resp) end -- http-request Scene : senden über AutoRemote Tasker WiFi Service enabled in Tasker Action local function getDirect() local http = net.HTTPClient() payload = '"DA":[1,1,1,1,1,0,0,0]' fibaro:debug('this is the payload: ' .. payload .. '.') http:request('https://actron.ninja.is/rest/v0/device/ACONNECTXXXXXXXXXXX_0_2_4?user_access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', { options = payload, success = successCallback, error = errorCallback } ) end -- Do the request getDirect() -
Switch-case possible as substitution for many if-statements?
mainnsto posted a question in Scenes and Interface
Hi, I have a LUA programming question - for making a scene that helps HC2 heat panel control my AC via ZXT-120. My end-goal (for now) is to set the Fan speed and AC mode (heat/cool/off) by the logic in the following table (explanation below) Explanation for table: Setpoint is retrieved from Heat Panel. The deviation from setpoint is calculated from a global temp-variable subtracting setpoint to get the deviation. Based on that daviation AND the outside temperature, the AC will be set do fan speed and mode. I realize that the amount of if statements would be too big for me to handle, so someone suggested to use "switch-case" (which i am not familiar with but is sort of understood). The below example was provided for me: The problem is i still can't translate this to anything sensible in LUA. Can anyone please help me?-
- lua
- switch-case
-
(and 1 more)
Tagged with:
-
Below is a simple LUA script to turn off most lights at night. The script (my first LUA attempt) works, but raises some basic questions: I would have liked to find the length of the array Lights_exBedrooms using the LUA function n=table.getn(ArrayName). I could not make it work. Is this function not implemented in HC2 LUA? General LUA documentation allows the construction for i,v in ipairs(ArrayName) do .. to cycle through an entire array. This does not seem to be implemented in HC2 LUA either? The script runs without delay, including the do loop turning off all lights in the list. Line 18, however, turning device 251 back on at 20 %, is delayed by about 5 seconds. Why? The idea is to define the device list as a global variable to be used in other scenes. Will adding Lights_exBedrooms{} below line 5 "%% globals" achieve that? More generally: How can something inserted between comment brackets --[[ and --]] in the header be significant to the LUA interpreter? -- "Good night" script - turns off most lights --[[ %% properties %% events %% globals --]] -- set toilet light to low before turning off (night light position, if manually switched on during night) fibaro:call(267,'setValue','20') -- Define vector of all non-bedroom light devices Lights_exBedrooms={306,304,311,305,291,286,271,366,276, 261,267,251,246,373,404,338,328,333} -- Turn off all lights except bedrooms n=18 for i=1,n do fibaro:call(Lights_exBedrooms,'turnOff') end -- Special cases fibaro:call(251,'setValue', '20') -- Hallway at 20%
-
Is it possible the read out the set of favorite colors for RGBW modules in LUA? How? I want to cycle the favorite colors in a scene. Thanks for hints.
-
- lua
- favourite colors
-
(and 1 more)
Tagged with:
-
I bought a mermaid Devolo (Zipato). I get the LEDs on, but it does not sound. According to the manual there are 7 sounds and for this use this: The device supports using SWITCH_MULTILEVEL SET to play the sound The sound ID is defined as follows: 1 or 255: Emergency sound. 2: Fire alert. 3: Ambulance sound. 4: Police car sound. 5: Door chime. 6 ~ 99: Beep Beep. 0: means stop the sound. But I do not know how to activate it. Then he has some COMMAND_CLASS ....... I do not know how I can configure them with lua. Let's see if someone can help me. Thank you. ph-pse02-Zipato-Siren-User-Manual-v1-2.pdf
- 7 replies
-
- lua
- command_class
-
(and 1 more)
Tagged with:
-
Dear forum readers. I have a virtual device where I wanted to read the XML values from. i know that it is not possible to use external libs to read the XML. the device wich I wanted to control has a status page which in XML format is. I wanted that my virtual device can read the location ID and from each location id the Preset and the name and at last the type of "room" I use Lua for the virtual device. hope that someone can help me out with this This XML file does not appear to have any style information associated with it. The document tree is shown below. <locations> <location id="eec0c0b41b4c43119d33e2bdafe1fc08"> <name>Woonkamer</name> <description/> <type>livingroom</type> <created_date>2019-01-30T17:06:14.387+01:00</created_date> <modified_date>2019-02-13T14:12:37.667+01:00</modified_date> <deleted_date/> <preset>away</preset> <clients/> <appliances> <appliance id="0ae80e58c6354c0ab69dc9f512f73bd0"/> <appliance id="b9cd5290b2c840d6a2cb1e7629987020"/> </appliances> <logs> <point_log id="9b603d2e231e466b83aad0bbe1e3df87"> <updated_date>2019-02-13T14:12:12.637+01:00</updated_date> <type>thermostat</type> <unit>C</unit> <last_consecutive_log_date>2019-01-31T13:28:58.345+01:00</last_consecutive_log_date> <period start_date="2019-02-13T14:12:12.637+01:00" end_date="2019-02-13T14:12:12.637+01:00"> <measurement log_date="2019-02-13T14:12:12.637+01:00">15.00</measurement> </period> </point_log> <point_log id="b42775ccb8a34300b89e2783a12d377c"> <updated_date>2019-02-13T14:12:37.627+01:00</updated_date> <type>temperature</type> <unit>C</unit> <last_consecutive_log_date>2019-01-31T15:32:18.644+01:00</last_consecutive_log_date> <period start_date="2019-02-13T14:12:37.627+01:00" end_date="2019-02-13T14:12:37.627+01:00"> <measurement log_date="2019-02-13T14:12:37.627+01:00">27.60</measurement> </period> </point_log> </logs> <actuator_functionalities> <thermostat_functionality id="a214798f9ce448b3975d52f0e5b39ed3"> <updated_date>2019-02-13T14:12:12.638+01:00</updated_date> <type>thermostat</type> <setpoint>15</setpoint> <lower_bound>0</lower_bound> <upper_bound>99.99</upper_bound> <resolution>0.01</resolution> <regulations> <open_therm_regulation id="c843041e028c40c7972a37186db7d292"/> </regulations> </thermostat_functionality> </actuator_functionalities> </location> <location id="c2763300e52545c4b702214d842397cd"> <name>Home</name> <description/> <type>building</type> <created_date>2019-01-30T16:31:22.406+01:00</created_date> <modified_date>2019-02-13T14:00:34.694+01:00</modified_date> <deleted_date/> <preset>home</preset> <clients/> <appliances/> <logs> <point_log id="4cdaf2b988d449adb9bcbde2173fabac"> <updated_date>2019-02-13T13:20:00+01:00</updated_date> <type>outdoor_temperature</type> <unit>C</unit> <last_consecutive_log_date>2019-02-13T13:20:00+01:00</last_consecutive_log_date> <period start_date="2019-02-13T13:20:00+01:00" end_date="2019-02-13T13:20:00+01:00"> <measurement log_date="2019-02-13T13:20:00+01:00">6.31</measurement> </period> <thermo_meter id="2874c255abe74e119ce7ae18f28f1620"/> </point_log> <point_log id="6ff4a2747be5466999362dde2ab4de6c"> <updated_date>2019-02-13T13:20:00+01:00</updated_date> <type>wind_vector</type> <unit>m_s</unit> <last_consecutive_log_date>2019-02-13T13:20:00+01:00</last_consecutive_log_date> <period start_date="2019-02-13T13:20:00+01:00" end_date="2019-02-13T13:20:00+01:00"> <measurement log_date="2019-02-13T13:20:00+01:00">(5.10,220.00)</measurement> </period> <wind_vector id="e3b37ca9d9bc4a9c8aa792996c9631f7"/> </point_log> <point_log id="9fedd3ce56544d9cb3ba8741d586195b"> <updated_date>2019-02-13T13:20:00+01:00</updated_date> <type>solar_irradiance</type> <unit>W_m2</unit> <last_consecutive_log_date>2019-02-13T13:20:00+01:00</last_consecutive_log_date> <period start_date="2019-02-13T13:20:00+01:00" end_date="2019-02-13T13:20:00+01:00"> <measurement log_date="2019-02-13T13:20:00+01:00">267.19</measurement> </period> <irradiance_meter id="9f2e62dac6274336abbee38c3f30ae55"/> </point_log> <point_log id="a2b370beeb0340dea1bb4dd76ef4fc69"> <updated_date>2019-02-13T13:20:00+01:00</updated_date> <type>humidity</type> <unit>RH</unit> <last_consecutive_log_date>2019-02-13T13:20:00+01:00</last_consecutive_log_date> <period start_date="2019-02-13T13:20:00+01:00" end_date="2019-02-13T13:20:00+01:00"> <measurement log_date="2019-02-13T13:20:00+01:00">75.00</measurement> </period> <hygro_meter id="7f96900dfb2e47309660a1614e7acc2d"/> </point_log> </logs> <actuator_functionalities/> </location> <location id="9cc6fd06c60c4199b1bd9e97267ee274"> <name>kelder</name> <description/> <type>cellar</type> <created_date>2019-01-31T08:59:18.287+01:00</created_date> <modified_date>2019-02-13T14:12:18.391+01:00</modified_date> <deleted_date/> <preset>away</preset> <clients/> <appliances> <appliance id="6b7d7b6082a54ad7914fac36d268ffd7"/> <appliance id="cee97024adb94776ba6aecddb6ea62d7"/> </appliances> <logs> <point_log id="5b479e2315b84ea3a1b36b9afed23eeb"> <updated_date>2019-02-13T14:12:18.375+01:00</updated_date> <type>temperature</type> <unit>C</unit> <last_consecutive_log_date>2019-01-31T15:32:38.107+01:00</last_consecutive_log_date> <period start_date="2019-02-13T14:12:18.375+01:00" end_date="2019-02-13T14:12:18.375+01:00"> <measurement log_date="2019-02-13T14:12:18.375+01:00">24.00</measurement> </period> </point_log> <point_log id="e7787444f4ef461d856a23aa405f3aab"> <updated_date>2019-02-13T14:12:12.765+01:00</updated_date> <type>thermostat</type> <unit>C</unit> <last_consecutive_log_date>2019-01-31T14:45:00.766+01:00</last_consecutive_log_date> <period start_date="2019-02-13T14:12:12.765+01:00" end_date="2019-02-13T14:12:12.765+01:00"> <measurement log_date="2019-02-13T14:12:12.765+01:00">15.00</measurement> </period> </point_log> </logs> <actuator_functionalities> <thermostat_functionality id="9c1f952c1cdc470bb72716858b004bf5"> <updated_date>2019-02-13T14:12:12.766+01:00</updated_date> <type>thermostat</type> <setpoint>15</setpoint> <lower_bound>0</lower_bound> <upper_bound>99.99</upper_bound> <resolution>0.01</resolution> <regulations> <open_therm_regulation id="c843041e028c40c7972a37186db7d292"/> </regulations> </thermostat_functionality> </actuator_functionalities> </location> </locations>
- 41 replies
-
- lua
- virtual device
-
(and 1 more)
Tagged with:
-
Hi all, I'm new to HC2 having migrated from Domoticz. I've a limited knowledge of LUA and so rely heavily on copy and paste I am trying to create a scene whereby if any of my heat controllers are calling for heat a fibaro relay will switch on my boiler... and if all off... turn it off again i.e. " if A or B or C = On then set H = On elsif A and B and C = Off then set H = Off" My attempt at code is as follows --[[ %% properties 52 operatingMode 62 operatingMode 43 operatingMode 67 operatingMode 7 operatingMode 26 operatingMode %% weather %% events %% globals --]] local startSource = fibaro:getSourceTrigger(); if ( ( tostring(fibaro:getValue(52, "operatingMode")) == "1" ) or ( tostring(fibaro:getValue(62, "operatingMode")) == "1" ) or ( tostring(fibaro:getValue(43, "operatingMode")) == "1" ) or ( tostring(fibaro:getValue(67, "operatingMode")) == "1" ) or ( tostring(fibaro:getValue(7, "operatingMode")) == "1" ) or ( tostring(fibaro:getValue(26, "operatingMode")) == "1" ) or startSource["type"] == "other" ) then fibaro:call(48, "turnOn"); elseif ( ( tostring(fibaro:getValue(52, "operatingMode")) == "0" ) and ( tostring(fibaro:getValue(62, "operatingMode")) == "0" ) and ( tostring(fibaro:getValue(43, "operatingMode")) == "0" ) and ( tostring(fibaro:getValue(67, "operatingMode")) == "0" ) and ( tostring(fibaro:getValue(7, "operatingMode")) == "0" ) and ( tostring(fibaro:getValue(26, "operatingMode")) == "0" ) and startSource["type"] == "other" ) then fibaro:call(48, "turnOff"); end This appears to run without bugs but just turns the boiler (device 48) on and stays on. Does anyone have any idea where I am going wrong? Any help/tips would be greatly appreciated. Many thanks Sean
-
net.HTTPClient() call gives "short read" Error
Sergey Malygin posted a question in Scenes and Interface
Hi all, I have an issue trying to make and HTTPS POST request from my LUA scnene in Fibaro HC. I am getting "short read" error with the URL "https://api2.magicair.tion.ru/idsrv/oauth2/token" This is my scene: ============================================= --[[ %% properties %% events %% globals --]] local authData = "username=XXX&password=YYY" function doTest() print('Test!') local requestUrl = "https://api2.magicair.tion.ru/idsrv/oauth2/token" local httpClient = net.HTTPClient() httpClient:request(requestUrl, { options = { method = "POST", headers = { ["Content-Type"] = "application/x-www-form-urlencoded", ["Content-Length"] = tostring(authData:len()) }, data = authData, timeout = 5000 }, success = function (response) fibaro:debug (response.data) end, error = function (err) fibaro:debug ("Error: " .. err) end }) setTimeout(doTest, 5*1000) end print('Script start...') doTest() ============================================= I am getting the following in my log: [DEBUG] 15:16:52: Script start... [DEBUG] 15:16:52: Test! [DEBUG] 15:16:52: Error: short read I have been trying to play with headers, data format, timeouts and all parameters I could find, however I always get the same error with the provided URL. Other HTTPS URLS I tried with GET method works just fine. Also I have been trying to do the same with cURL and it works fine with the exact same set of headers and payload (with full credentials string, of course). So the issue is somehow connected with this specific URL: "https://api2.magicair.tion.ru/idsrv/oauth2/token" The Internet is saying that short read problem in HTTPClient request might be related to ciphering protocols mismatch between the client and server. So there could be some parameter regulating this? 2 main versions, which I see: 1. Some tricky param is required to form the correct HTTPS request. 2. Some bug / missing feature in HTTPClient implementation in HC2. Anyway I am stuck and need the help from the community and HC developers. Has anyone seen something similar? Any clues? Please help! Many thanks in advance. PS Using the latest FW 4.51 of Fibaro Come Center 2 -
-- Removed -- my idea was not to take credit for the job someone else have made. If you like the script you can find it on other sites around internet.
-
This is my first topic in a series of post I'm going to write about the advanced LUA scenes I wrote for my home automation project. My goal is not flipping a light scene with a phone but for 90% autonome home automation. Besides posting LUA code I give you more insight why I came to this routine. It may help you with designing your own automation routines. Disclaimer: I am not a professional programmer and I post the scenes as is. I have no time to make the LUA scenes generic like other great members do on this forum. I just post my LUA code to share knowlegde and inspire you to create awesome things! Advanced home wake-up routine with Philips Hue and HC2 Applies to: Fibaro Home Center 2 and Philips HUE bridge. GOALS Use my Philips Hue led strips as a wake-up light. Use 1 app to schedule the whole home wake-up routine. Start the morning routine when walking downstairs (check motion). Turn on the lights only when it’s dark (read lux). In our bedroom we integrated a Philips Hue lightstrip in the ceiling and use this with the Philips Hue app as a wake-up light. It beautifully fakes a sunrise in our whole room. As we use the Hue app to set our wake-up alarm I use this app to trigger the Home Center to run a wake-up routine for the rest of the house. TL;DR Set recurring wake-up schedule in the Philips Hue app. Home Center LUA scene 1 reads schedules at 04:00 with the keyword Wake in it. If schedule is set for today and motion is detected at the hallway after the scheduled time (scene 2), run wake-up routine. HOW I IMPLEMENTED IT IN WORDS Reading Hue schedules from the bridge cannot be done with the Fibaro Hue plug-in. Therefore I wrote a LUA scene to read the Hue schedules from the Hue bridge and run the wake-up routine at the schedules wake-up time. I achieved this with 2 LUA scenes: Scene 1 runs every minute and polls the Hue bridge schedules at 04:00. If a wake-up is scheduled for today write the wake-up times to a global variable. Every minute it checks if there is a wake-up planned by reading the same global variable and if so it sets the WakeUpReady global variable to 1. Scene 2 runs when motion detected by a Fibaro Motion Sensor. If it detects motion it checks if the global variable WakeUpReady is set to 1 and runs the wake-up routine. SCENE 1 EXPLAINED You can download the full LUA scenes at the bottom of this post. I only describe snippets of my code to make you understand what it does and show the challenges I ran into. TAG YOUR HUE SCHEDULE WITH A WAKE-UP STRING IN IT! To know which schedules are used for wake-up I set all those schedules with the Wake keyword in it. Like Wake-up weekday’s and Wake-up weekends. In the LUA scene I find these schedules with the code: if name:find('Wake') and status == 'enabled' then ... end RECURRING DAY’S ARE SAVED AS A BITMASK IN THE HUE BRIDGE The Hue API states: The Hue bridge saves the recurring day’s as a bitmask. You have to convert this bitmask to weekday’s. So you can check if the alarm is set for today. The first step is to convert decimal to a binary. I did this with the folowing LUA function: function bin(dec) local result = "" repeat local divres = dec / 2 local int, frac = math.modf(divres) dec = int result = math.ceil(frac) .. result until dec == 0 local StrNumber StrNumber = string.format(result, "s") local nbZero nbZero = 8 - string.len(StrNumber) local Sresult Sresult = string.rep("0", nbZero)..StrNumber return Sresult end Then I have a binary representation of the scheduled weekday’s. For example: mo tu we th fr sa su 1 1 1 1 0 1 0 You see the alarm is set for monday, tuesday, wednesday, thursday and saturday. With this I can determine if the alarm is set for today: if name:find('Wake') and status == 'enabled' then local huedays, huetime = string.match(timepattern, 'W(.*)/T(.*)') -- Hue starts at monday, LUA starts at sunday, so I have to fix this. local dayofweek = os.date("*t").wday-1 if dayofweek == 0 then dayofweek = 7 end local scheduleddays = bin(huedays) -- dayofweek+1 because a week is 7 days and binary is 8 digits, so -- a have a pre 0 local waketoday = string.sub(scheduleddays, dayofweek+1, dayofweek+1) if waketoday == '1' then wakeUpAlarms = wakeUpAlarms .. huetime:sub(1, -4) .. '|' end ... end WRITE WAKE-UP TIME TO GLOBAL VARIABLE If there is an alarm schedule for today write it to a global variable for later use: if wakeUpAlarms ~= '' then fibaro:setGlobal("WakeUpTime", wakeUpAlarms:sub(1, -2)) -- remove last | else -- If no schedules are set, write disabled to the global variable. fibaro:setGlobal("WakeUpTime", "disabled") end SET WAKEUPREADY GLOBAL VARIABLE FOR MOTION SENSOR LUA SCENE The LUA scene runs every minute using the code: setTimeout(tempFunc, 60*1000) At 04:00 it checks the schedules in the Hue bridge, but every minute it checks the WakeUpTime global variable to set the wakeupReady global variable to 1. This variable triggers the second LUA scene used by the motion sensor. local wakeupTime = fibaro:getGlobal("WakeUpTime") if wakeupTime ~= "disabled" then local waketimes = {} for match in (wakeupTime..'|'):gmatch("(.-)"..'|') do table.insert(waketimes, match); end for k, v in pairs(waketimes) do if os.date("%H:%M") == v then fibaro:setGlobal("WakeUpReady", 1) fibaro:debug("It's wake-up time! Set motion detector ready!") end end end SCENE 2 EXPLAINED (MOTION SENSOR PART) With scene 1 I created a global variable setting to determine if the wake-up routine must run. Now I create a second scene to act if there is motion in our hallway. CHECK FOR MOTION AND IF ALARM IS NOT ARMED First I want to check if there is motion and if the alarm is not armed with the line: if tonumber(fibaro:getValue(158, "value")) > 0 and tonumber(fibaro:getValue(158, "armed")) == 0 then ... RUN WAKE-UP ROUTINE ONLY IF IT’S DARK OUTSIDE The Philips Hue wake-up schedule runs always because our bedroom had curtains and the room is always dark. Downstairs I only want to run the wake-up routine when it’s dark outside. The wakeupReady global variable check’s if the routine needs to run when there is motion (set with scene 1). The line below gets the current lux reading from the Fibaro motion sensor: fibaro:getValue(160, "value") If the illuminance is below 20 I want to turn on my lights. if wakeupReady == "1" then fibaro:setGlobal("WakeUpReady", 0) -- Disable trigger for current wake-up time. -- check lux local currentLux = tonumber(fibaro:getValue(160, "value")) -- id 160 is sensors light device. -- If it's dark then start wake-up routine if currentLux < 20 then fibaro:debug("Illuminance measuring " .. currentLux .. " lx, starting wake-up routine.") fibaro:call(44, "setValue", "8") -- Spots keuken (8%) fibaro:call(29, "setValue", "5") -- Tafel eethoek (5%) fibaro:call(106 , "turnOn") -- Bolles (aan) fibaro:call(118 , "turnOn") -- Spot voordeur (aan) fibaro:call(156, "sendPush", "Started wake-up routine. Debug: " .. currentLux .. " lx") else fibaro:debug("Illuminance measuring " .. currentLux .. " lx, do nothing.") end ... DOWNLOAD MY SCENES COMPLETE LUA CODE You can download the full LUA scene code from GitHub: Scene 1: Wakeup.lua Scene 2: MotionRoutine1.lua You have to change the device id’s from my motion sensors in this scene to your own id’s! And don't forget to set the scenes to run automatic in the Fibaro Home Center 2
-
I am looking to create a simple Lua scene that looks to see if the door is locked then do "something". everything I enter to look for the door status it is not working. Someone please tell me what I am doing wrong. 92 = my door lock --[[ %% properties %% events %% globals --]] local User = "User_Present"; if tonumber(fibaro:getValue(92, "secured")) == 0 then fibaro:setGlobal(User,"0") fibaro:debug("Door locked"); end
-
I have an issue trying to make and HTTPS POST request. I am getting "short read" error with the URL "https://api2.magicair.tion.ru/idsrv/oauth2/token" This is my scene: ============================================= --[[ %% properties %% events %% globals --]] local authData = "username=XXX&password=YYY" function doTest() print('Test!') local requestUrl = "https://api2.magicair.tion.ru/idsrv/oauth2/token" local httpClient = net.HTTPClient() httpClient:request(requestUrl, { options = { method = "POST", headers = { ["Content-Type"] = "application/x-www-form-urlencoded", ["Content-Length"] = tostring(authData:len()) }, data = authData, timeout = 5000 }, success = function (response) fibaro:debug (response.data) end, error = function (err) fibaro:debug ("Error: " .. err) end }) setTimeout(doTest, 5*1000) end print('Script start...') doTest() ============================================= I am getting the following in my log: [DEBUG] 15:16:52: Script start... [DEBUG] 15:16:52: Test! [DEBUG] 15:16:52: Error: short read I have been trying to play with headers, data format, timeouts and all parameters I could find, however I always get the same error with the provided URL. Other HTTPS URLS I tried with GET method works just fine. Also I have been trying to do the same with cURL and it works fine with the exact same set of headers and payload (with full credentials string, of course). So the issue is somehow connected with this specific URL: "https://api2.magicair.tion.ru/idsrv/oauth2/token" The Internet is saying that short read problem in HTTPClient request might be related to ciphering protocols mismatch between the client and server. So there could be some parameter regulating this? 2 main versions, which I see: 1. Some tricky param is required to form the correct HTTPS request. 2. Some bug / missing feature in HTTPClient implementation in HC2. Anyway I am stuck and need the help from the community and HC developers. Help!
-
I am looking to have the wall plug restart (turn off then back on after 30 seconds) at an exact time (midnight). i have tried coding this in Lua but i am having no success on getting it to turn off and on at midnight can some help me?
-
Hi All, Is it possible to change the colours of the LUA IDE in the Scenes dialogue? The dark background and dark text colours make it difficult to use.. All help greatly appreciated!
-
Is it possible to check if the virtual device button was pressedin lua? Is there any function for that in lua? I want to code something like this: (If Button "3" of virtual device with ID 674 was pressed than a=a+1) for example
- 1 reply
-
- lua
- virtual_device
-
(and 3 more)
Tagged with:
-
Can someone help me. I have been thinking about how the logic would work and cannot come up with the correct Lua code to make this work correctly. Goal: want the door to unlock when I arrive at home and lock when I leave and send a message (push, email etc..) every time. but if I am home/not home I don't want it to keep locking/unlocking and sending me a message *I already have fibaro looking for my phone to see if I'm present. a global variable keeps a number count present =1 not present = 0 so the logic I came up with is like this: Check Present=0 then lock door and send message check present =0 (still not at home) do nothing check present = 1 unlock door and send message check present = 1 (still at home) do nothing etc... let me know if you have questions or suggestions.
-
Can I do time calculation, without using epoc format?
Teza posted a question in Scenes and Interface
I want to subtract "tid_entre" from "tid" and check if it is longer than "entre". fibaro:setGlobal("Tid_entre", (os.date("%Y-%m-%d %H:%M:%S",fibaro:getValue(37, "lastBreached")))) local entre = "00:00:30" --hh:mm:ss local tid_entre = fibaro:getGlobal("Tid_entre") local tid = os.date("%Y-%m-%d %H:%M:%S") [DEBUG] 16:06:52: Variabelen entre = 00:00:30, VariableType = string [DEBUG] 16:06:52: Variabelen Tid_entre = 2018-10-17 14:00:44, VariableType = string [DEBUG] 16:06:52: Variabelen tid = 2018-10-17 16:06:52, VariableType = string Is it possible to do this without using epoc numbers for time?- 11 replies
-
maybe a simple question, but is there a way to extract a list of all devices (inluding actors, reactors, users) and its corresponding ID ?
-
Hello, Am a learner and currently practicing lua coding, i would like to know how to identify errors before i use the codes on HC2 . Am not really sure what am doing. Am worried i may Crush the system. For instance, can't identify the problem... (i was trying to tell the TVwallplug to detect if the TV is Off then Turn it On, and if TV is On then Turn it Off) i want to use it when running scenes. The TV has 1 Button for On/Off Hop to get help from here. Thank you
-
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).
- 1 reply
-
- global vars
- table
-
(and 2 more)
Tagged with:
-
creating variables using lua or thru API
AutoFrank posted a question in Other Devices / Third-party devices
HI, Is it possible to create a variable (specifically a predefined variable) As part of creating a VD I want to create the variable on the fly I looked at the developer documentation but couldn't find anything Is this possible ? Thanks -f -
Ok, this is not the best solution and might need a few more tweaks to make it look perfect (but i wasn't going for perfection) Get Chrome, install the plugin called "Stylish" after you installed it, go to preferences, make a new rule and add your domain name or ip address of your fibaro. Then add the following css code: .kitBody { width: 1100px; } #mainLoop_0 { width: 98%; height: 600px !important; } #Container1 { width: 98%; } #Top { width: 98%; } #Menu { width: 98%; } .Left { width: 13%; } .Content { width: 85%; } .Sections { width: 100%; } .SectionContent { width: auto; } #Top { float: left; } .kit { width: 100%; } .kitBody { width: 100%; } .kitBodyRight { width: 96%; } #kitsContainer { width: 100%; } .DeviceEditRight { padding-left: 25px; } .SceneArea { width: 98%; height: 600px; } .DeviceEditParametrs { width: 96%; } .CodeMirror { height: inherit; } Once you done this, at least the lua code window looks like this: So what this does is change the css code so that it tries to span the full screen that you have. So i assume you have a high resolution monitor or else it might look funny p.s. found a class that is called ".FisrtHeadline" Nice typo, it is in the html and css..