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

  • 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

  1. Hi, I'm trying to access from Virtual Device web page which requires authentication. Unfortunately "setBasicAuthentication" does not work here. Can you please advise how to authenticate the access. Server IP: '138.91.51.153'
  2. Hi, I currently use the script (Scene) below to turn off all lights when going to sleep. The problem is sometimes my adult children are still awake upstairs. How would I modify scene to turn off only downstairs lights? HC2 - Running latest version I thought of using the description field in devices and evaluating but can't work out the code. Help! --[[ %% properties %% events %% globals --]] local ids = fibaro:getDevicesId( { interfaces = { "light", }, properties = { dead = false, }, enabled = true, visible = true, -- optional --userDescription ~= "", -- attempt to evaluate if user description in device is not nil. } ); -- loop through light ids for i, id in ipairs(ids) do fibaro:debug("Turning off " .. fibaro:getName(id)); -- turn light off fibaro:call(id, "turnOff"); end Thanks Jason
  3. Guys, Problem, I have code below, however, change the value of Global variable "regenover" does not trigger the scene. I don't understand why not, someone able to help me out here ? --[[ %% globals regenover -]] local trigger = fibaro:getSourceTrigger() local regentijd = fibaro:getGlobalValue("regenover") if regentijd == "0" then fibaro:call(475, "turnOn") fibaro:call(782, "pressButton", "5"); elseif regentijd == "5" then fibaro:call(475, "turnOff") fibaro:call(782, "pressButton", "4"); elseif regentijd == "15" then fibaro:call(475, "turnOn") fibaro:call(782, "pressButton", "3"); elseif regentijd == "30" then fibaro:call(475, "turnOff") fibaro:call(782, "pressButton", "2"); end
  4. Hi All Following on from posts elsewhere about my issue I am convinced the problem lies with the block/lua conversion. However as a newbie I do not know enough to decipher the flow of the code. Primarily I need to understand how this scene is triggered when %%autostart is not used. I get that a manual start will set things going by the first 4 lines but how does the scene trigger otherwise? If someone could add some comments to the offending code below for me it would be most useful! --[[ %% properties 172 value %% weather %% events %% globals --]] local startSource = fibaro:getSourceTrigger(); if(startSource["type"] == "other") then fibaro:call(64, "turnOff"); fibaro:call(66, "turnOff"); else if (( tonumber(fibaro:getValue(172, "value")) == 0 )) then setTimeout(function() local delayedCheck0 = false; local tempDeviceState0, deviceLastModification0 = fibaro:get(172, "value"); if (( tonumber(fibaro:getValue(172, "value")) == 0 ) and (os.time() - deviceLastModification0) >= 200) then delayedCheck0 = true; end local startSource = fibaro:getSourceTrigger(); if ( ( delayedCheck0 == true ) or startSource["type"] == "other" ) then fibaro:call(64, "turnOff"); fibaro:call(66, "turnOff"); end end, 200000) end end
  5. Hello,every one! How to control air conditioning with Lua, I want to control the temperature in the scene, the mode of those.
  6. Hi, I had the requirement for a very simple scheduler. The code below is a stripped down version of @Sankotronic Main Scene code and just contains the Scene Scheduler. Thanks to @Sankotronic for his permission to post this. -- SIMPLE SCHEDULER. -- STRIPPED DOWN VERSION OF 'MAIN SCENE' CODE BY SANKOTRONIC --[[ %% autostart %% properties %% globals --]] if (fibaro:countScenes() > 1) then fibaro:abort(); end local jT = json.decode(fibaro:getGlobalValue("HomeTable")); -- comment out if you don't use a hometable local currenttime = os.date('*t'); local currentwday = currenttime['wday']; local TimeCurrent = os.date("%H:%M", os.time()); -- SCHEDULED SCENES SETUP -- (seperate multiple entries by comma) local runSceneSchedName = {"Test Scene 1", "Test Scene 2"}; -- Add scene names local runSceneSchedID = {641, jT.scene.Wakeup}; -- add scene ID's or references local runSceneSchedHour = {{"21:47"}, {"07:30"}}; -- Add times to run the scenes local runSceneSchedWeek = {{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}}; -- specify what day to run the scenes, Sunday is first day in array function doSceneSched() if #runSceneSchedID > 0 then for i = 1, #runSceneSchedID do if runSceneSchedWeek[i][currentwday] == 1 then for t = 1, #runSceneSchedHour[i] do if runSceneSchedHour[i][t] == TimeCurrent then fibaro:startScene(runSceneSchedID[i]); end end end end end end -- MAIN LOOP while true do currenttime = os.date('*t'); currentwday = currenttime['wday']; TimeCurrent = os.date("%H:%M", os.time()); doSceneSched(); fibaro:sleep(59700); end The full Main Scene code can be found at https://forum.fibaro.com/index.php?/topic/23510-scene-main-scene-for-time-based-events-control-v-125/ I thought this many be useful for some new users starting out or those like me that need a simple yet well written scheduler and may even be a stepping stone for some to the full Main Scene. -f
  7. This is feature request with low priority. So i will post it only on forum Better function of clipboarding from debug windows from VD debug window and LUA scene debug window. How it is now works: Succesfull clipboard: Hold left mouse button to select some debug lines and then ctrl+C for copy, while left mouse button is held down. Unsuccesfull clipboard: Hold left mouse button to select some debug lines, release mouse button and then ctrl+C for copy, while left mouse button is holded. What is requested: Hold left mouse button to select some debug lines, release mouse button and then ctrl+C for copy, while left mouse button is holded.
  8. Hello, I like to start a scene at every keypress on my Zipato Mini Keypad with RFiD Example: Zipato Away + PIN >>> Start scene Arm Zipato Home + TAG >>> Start scene DisArm Zipato Away + TAG >>> Start scene Arm Zipato Home + PIN >>> Start scene DisArm This works fine, no problem so far but if i'm also using my smartphone it doesn't work 1) Yesterday Alarm Disarmed by Zipato-Home-key + PIN 2) Today Alarm Armed by Smartphone 3) Today i try to disarm by Zipato-Home-key + TAG >>> NO TRIGGER Fibaro HC2 doesn't start a scene at step-3 because 'value' was not changed, for the system i pushed the home-key again (step 1 and 3) How do i trigger a scene with FIBARO LUA every time a key was pushed? ----------------------- Every key-press is send to Fibaro HC2 as it shows in the status screen [23:11:56] ID 299: locked by user 2 [23:24:50] ID 299: unlocked by user 2 [23:24:58] ID 299: locked by user 2 [23:25:25] ID 299: locked by user 2 [23:25:43] ID 299: locked by user 2 [23:25:54] ID 299: unlocked by user 2 [23:27:46] ID 299: locked by user 2 [23:27:52] ID 299: locked by user 3 [23:27:57] ID 299: unlocked by user 2 [23:31:03] ID 299: locked by user 2 [23:31:13] ID 299: unlocked by user 2 [23:47:04] ID 299: locked by user 1 [23:47:11] ID 299: unlocked by user 1 ----------------------- SCENE HEADER: --[[ %% properties 299 value %% events %% globals --]] Can somebody help?
  9. Hello I have a HC2 v4.130. I wanted to try to create a new virtual device with a simple lua script. However the script always fails with '[ERROR] 15:47:28: line 183: Assertion failed'. The script currently only consists of the following lines: if (fibaro:countScenes() > 1) then fibaro:abort(); end fibaro:debug("run complete") If I remove the 'fibaro:countScenes' command, the script is working. Is it possible, that virtual devices in v4.130 do not understand the fibaro:countScenes() command? What can I do to fix it or to work around this issue? Thanks.
  10. I have some device connected to z-wave plugs that can measure the energy consumption (devolo (Metering Plug MT:2646) and aeon labs (aeotec ZW075 v2) plugs are used). Now I would like every month a report how many kWh each of the plugs counted so far. Best would be to get that report by email. Is something like this possible in the HC2 eg with LUA? Can anybody help me to get started: - how to get the combined kWh from the devices - how to send an email - how to run the script only once per month thanks
  11. Hi, I am trying to connect to a secure web server, with a self-signed SSL certificate, using the net.HTTPClient() library in a scene. When I connect to the web server using my web browser, I get a warning telling me that the certificate is not certified by a valid authority, as you may have already seen on such certificate. In my web browser, I just click on the button to continue anyway. Firefox even allows me to add the certificate to the list of approved certificates. Problem solved But on HC2, I can't figure how to bypass the warning Here is the LUA code i use : local URL = "https://subdomain.domain.com/path" local httpClient = net.HTTPClient() httpClient:request(URL, { success = function(response) if response.status == 200 then -- Code to execute if successfull else fibaro:debug("Error : status=" .. tostring(response.status)) end end, error = function(err) fibaro:debug('httpClient:request() : Error : ' .. err) end, options = { method = 'GET', checkCertificate = false, } }) As you can see,I tried to use the "checkCertificate = false" option, but I doesn't seem to have any effect. I always get the following message : "sslv3 alert handshake failure" [DEBUG] 21:05:41: httpClient:request() : Error : sslv3 alert handshake failure The checkCertificate option seems to exist, as I found it as a string in the compiled binaries into the HC2. I tried both true and false boolean values, which seems to be accepted by the LUA interpreter, but I doesn't affect result as I would normally expect; If I try another value, such as a number or a string, I get a LUA Cast error and the script immediately ends. This is a proof that the checkCertificate parameter is used, but apparently with no effect. Can anyone confirm this strange behavior ? To Fibaro developers, can you confirm this parameter is correctly implemented ?
  12. Hi, Specific Lua question I'm hoping a more experienced member can help with. I have a 3-way momentary switch connected to a universal binary sensor which controls my Hue lights via Logic/Lua. I would like to increment the brightness of the Hue lights when the button is held down, I'm comfortable with the Hue control I just don't know how to increment the value for brightness when the button is held. I've attached a screenshot of the scene that I need to add the functionality to, the brightness value is represented by question marks. Any help would be greatly appreciated. Ryan PS. If anyone would like to know how to trigger a Hue Scene or change the state of a Hue Group I'll post something up.
  13. Hi, I have a Home Energy monitor (HEM2) and have the clamp in the main live into my meter box to try and understand what the house is drawing power wise. I seem to be getting two power readings that are different with both changing over time but none seem fully accurate. One power reading seems accurate some times and the other power reading seems more accurate at other times if I look at what is running in the house at the time. I have only one clamp but the inclusion created 12 devices in in total 1471 (device id = 1471) 1471.0 & 1471.0.1, 1471.0.2 (device ID 1472, 1473, 1474) 1471.1 & 1471.1.1, 1471.1.2 (device ID 1475, 1476, 1477) 1471.2 & 1471.2.1, 1471.2.2 (device ID 1478, 1479, 1480) 1471.3 & 1471.3.1, 1471.3.2 (device ID 1481, 1482, 1483) I can get power readings on 1472 & 1475 1472 - api details (power = 895.79w) {"id":1472,"name":"House Energy 1","roomID":234,"type":"com.fibaro.energyMeter","baseType":"com.fibaro.meter","enabled":true,"visible":true,"isPlugin":false,"parentId":1471,"remoteGatewayId":0,"interfaces":["energy","power","zwave"],"properties":{"parameters":[{"id":3,"lastReportedValue":1,"lastSetValue":1,"size":1,"value":1},{"id":5,"lastReportedValue":50,"lastSetValue":50,"size":2,"value":50},{"id":6,"lastReportedValue":50,"lastSetValue":50,"size":2,"value":50},{"id":7,"lastReportedValue":50,"lastSetValue":50,"size":2,"value":50},{"id":9,"lastReportedValue":10,"lastSetValue":10,"size":1,"value":10},{"id":10,"lastReportedValue":10,"lastSetValue":10,"size":1,"value":10},{"id":11,"lastReportedValue":10,"lastSetValue":10,"size":1,"value":10},{"id":101,"lastReportedValue":14,"lastSetValue":14,"size":4,"value":14},{"id":102,"lastReportedValue":590080,"lastSetValue":590080,"size":4,"value":590080},{"id":103,"lastReportedValue":2049,"lastSetValue":2049,"size":4,"value":2049},{"id":111,"lastReportedValue":-740793856,"lastSetValue":-740793856,"size":4,"value":-740793856},{"id":112,"lastReportedValue":120,"lastSetValue":120,"size":4,"value":120},{"id":113,"lastReportedValue":1800,"lastSetValue":1800,"size":4,"value":1800}],"zwaveCompany":"AEON Labs","zwaveInfo":"3,3,67","zwaveVersion":"1.19","pollingTimeSec":0,"configured":"true","dead":"false","deviceControlType":"0","deviceIcon":"102","emailNotificationID":"0","emailNotificationType":"0","endPointId":"0","energy":"1379.51","liliOffCommand":"","liliOnCommand":"","log":"","logTemp":"","manufacturer":"","markAsDead":"false","model":"","nodeId":"212","parametersTemplate":"317","power":"895.79","productInfo":"0,134,0,2,0,28,1,19","pushNotificationID":"0","pushNotificationType":"0","remoteGatewayId":"0","saveLogs":"true","serialNumber":"","showEnergy":"true","smsNotificationID":"0","smsNotificationType":"0","unit":"kWh","useTemplate":"true","userDescription":"","value":"0.00"},"actions":{"reconfigure":0,"reset":0},"created":1480078127,"modified":1480078127,"sortOrder":406} 1475 - api details (power = 2.44 kw) {"id":1475,"name":"House Watts","roomID":234,"type":"com.fibaro.energyMeter","baseType":"com.fibaro.meter","enabled":true,"visible":true,"isPlugin":false,"parentId":1471,"remoteGatewayId":0,"interfaces":["energy","power","zwave"],"properties":{"parameters":[{"id":3,"lastReportedValue":1,"lastSetValue":1,"size":1,"value":1},{"id":5,"lastReportedValue":50,"lastSetValue":50,"size":2,"value":50},{"id":6,"lastReportedValue":50,"lastSetValue":50,"size":2,"value":50},{"id":7,"lastReportedValue":50,"lastSetValue":50,"size":2,"value":50},{"id":9,"lastReportedValue":10,"lastSetValue":10,"size":1,"value":10},{"id":10,"lastReportedValue":10,"lastSetValue":10,"size":1,"value":10},{"id":11,"lastReportedValue":10,"lastSetValue":10,"size":1,"value":10},{"id":101,"lastReportedValue":14,"lastSetValue":14,"size":4,"value":14},{"id":102,"lastReportedValue":590080,"lastSetValue":590080,"size":4,"value":590080},{"id":103,"lastReportedValue":2049,"lastSetValue":2049,"size":4,"value":2049},{"id":111,"lastReportedValue":-740793856,"lastSetValue":-740793856,"size":4,"value":-740793856},{"id":112,"lastReportedValue":120,"lastSetValue":120,"size":4,"value":120},{"id":113,"lastReportedValue":1800,"lastSetValue":1800,"size":4,"value":1800}],"zwaveCompany":"AEON Labs","zwaveInfo":"3,3,67","zwaveVersion":"1.19","pollingTimeSec":0,"configured":"true","dead":"false","deviceControlType":"0","deviceIcon":"102","emailNotificationID":"0","emailNotificationType":"0","endPointId":"1","energy":"1379.51","liliOffCommand":"","liliOnCommand":"","log":"","logTemp":"TxtGreen","manufacturer":"","markAsDead":"false","model":"","nodeId":"212","parametersTemplate":"317","power":"2436.61","productInfo":"0,134,0,2,0,28,1,19","pushNotificationID":"0","pushNotificationType":"0","remoteGatewayId":"0","saveLogs":"true","serialNumber":"","showEnergy":"true","smsNotificationID":"0","smsNotificationType":"0","unit":"W","useTemplate":"true","userDescription":"","value":"0.00"},"actions":{"reconfigure":0,"reset":0},"created":1480078127,"modified":1480078127,"sortOrder":409} The energy readings from both are the same Does anybody know which parameter I should be using thanks frank
  14. Hi all, How do I get te currently set temperature from a heating panel of a certain room to use in a scene? I'm trying to do the following. I have a scene looping to switch the boiler on and off depending on the current temperature in a room. For each room I have a heating panel and a danfoss value on each radiator. I use this value to readout the currently set temperature (which is done through the heating panel). This works very fine. However, in my living room i have floor heating without a danfoss value. I like to also program different temperatures using the heating panel but for that i need to get the set temperature from the panel instead of from the danfoss valve. How? Hope someone can help me out... Any help is much appreciated!
  15. Hi I'm having a little hard time for whatever reason on getting JSON string into local variables in a VD. The JSON string is: [{"sensorTemp": "23.68", "sensorHumidity": "25.50", "sensorPressure": "1014.22", "sensorBattery": "3145"}] my code for this: jsonTable = json.decode(response) fibaro:debug("response: " .. response) local temperature = jsonTable.sensorTemp local humidity = response.sensorHumidity local pressure = response.sensorPressure local battery = response.sensorBattery I have also tried printing the key value pairs but I never got anything into the debug window... Any pointers appreciated! Thanks, Timo L
  16. Hello, everybody! I stuck in a problem. I tried to setValue for few dimmers simultaneously with no luck. Initial: dimmer = {754, 441, 435, 747, 682, 481}; -- dimmer IDs on = {99, 99, 99, 99, 99, 99}; -- values for ON (accordingly) off = {0, 0, 0, 0, 0, 0}; -- values for OFF (accordingly) Then I make a loop to set all the values: for i = 1, #dimmer do fibaro:call(dimmer[i], "setValue", on[i]); end What could be simpler? But not as it seems... Usually, first few dimmers accept "setValue" command and successfully set up. But few last ones set up the desired level with a big lag (2-20 seconds) or even have no reaction at all. I thought it is because of z-wave network be overloaded within multiple commands were sent during a short period of time. I tried to make some pause between each fibaro:call for i = 1, #dimmer do fibaro:call(dimmer[i], "setValue", on[i]); fibaro:sleep(500); end But it has no effect also. I tried to make an acknowledgment mechanism: for i = 1, #dimmer do while tonumber(fibaro:getValue(dimmer[i], "value")) ~= on[i] do fibaro:debug("! SETVALUE ATTEMPT !"); fibaro:call(dimmer[i], "setValue", on[i]); fibaro:sleep(500); end end It helps - all dimmers eventually set up. But regarding debug screen, a number of attempts were needed for some dimmers to setValue. So time to setValue for all 6 dimmers varies from 3 to 20 seconds. So the question is there some method available for setting up multiple dimmers (or any other actors) with values. Something like this: fibaro:call({754, 441, 435, 747, 682, 481}, "setValue", {99, 99, 99, 99, 99, 99}); So it will be not a number of sequential commands but one "broadcast command" for example? Thanks for helping!
  17. I have written an enhancement scripts for boosting the heating in certain rooms based on presence. I already have a zwave boiler controller, and LC-13 radiators with a scripted running base heating scene.. The purpose of this is for certain rooms that meet the following criteria:- 1. Don't need to be heated to comfort level all the time in the heating panel 2. Presence is detected, and the user tends to be in the room for a good amount of time. 2 initial rooms for me are Study and Living Room I wrote it based on tabulated data, so I could just add additional information into the tables for inclusion, but my lua was "stretched" and there are a lot of loops in loops... it runs fine, but I wondered if anyone wanted to demonstrate how it SHOULD be written or if you want to use it, and you have radiator set points you would like to boost, feel free... heating_enhancement.txt
  18. Hi @T.Konopka We can change set or dynamically the icon for a virtual device using the following in lua fibaro:call(device, "setProperty", "currentIcon", 1960) Is there an equivalent command for a scene Thanks -f
  19. How to get user id who start scene or press button on device in app? I would like to send message about result only for him/her and not for everyone ... Thanks for any advice.
  20. Hi Does anybody know if it is possible to specify the icon for a scene or a VD within the la itself as opposed to the usual method Thanks -f
  21. Witam, może ktoś z was podpowiedzieć, gdzie określana jest wartość wielokrotności kliku Keyfob'a w kodzie LUA, ponieważ wartości po utworzeniu schematu blokowego nie działają poprawnie. Mianowicie problem mój polega na: -Chcę włączyć część oświetlenia jednym wciśnięciem przycisku pierwszego (kwadratu) na Keyfob'ie -Natomiast listwy LED chcę włączyć podwójnym wciśnięciem przycisku pierwszego (kwadratu) na Keyfob'ie Mimo skorzystania z schematu blokowego do utworzenia takiej sceny, wszystko reaguje na pojedyncze wciśnięcie przycisku (czyli zapala się oświetlenie i listwy led), mimo, że listwa led jest ustawiona tak, aby reagowała na 2 kliknięcia. Analogicznie jest w przypadku ustawienia, aby oświetlenie i listwy led się wyłączyły, ale tym razem na przycisku drugim (kółko). Mam jeszcze pytanie, czy jak ustawię, aby oświetlenie reagowało na jedno wciśnięcie, a listwy led na dwa wciśnięcia, to czy centralka/keyfob odróżni, że wcisnąłem dwa razy a nie raz, po to aby nie zapalać oświetlenia, a tylko listwy led na dwa wciśnięcia? Centralka - Home Center 2 Urządzenia: Keyfob, Double switch, RGBW Controller Pozdrawiam, Krzysztof
  22. Hi everyone, I'm having some issues with Lua code in a virtual device I am writing. I'm getting information on the status of my Bluespray irrigation controller. It has a basic API and reports if any of the zones are on watering. I want to just query the unit and then print out if any are detected as on. When I query bluespray controller and its not watering anything I get some JSON back which looks like this. { "result": { "sensors": { "door": 0, "rain": 1 }, "active_zones": [ ], "timestr": "Sat Mar 11 2017 10:09:38 PM", "time": 1489241378000, "door": 0 }, "id": 528452 } When its IS watering I get the following. { "result": { "sensors": { "door": 0, "rain": 1 }, "active_zones": [ { "on": 1489240754, "off": 1489241054, "run": 1489240754, "terminal": 3 } ], "timestr": "Sat Mar 11 2017 10:00:12 PM", "time": 1489240812000, "door": 0 }, "id": 218829 } To make it even more complex sometimes the system reports multiple zones operating. (This is normal and ok. I just need to pick up the first zone reported) { "result": { "sensors": { "door": 0, "rain": 1 }, "active_zones": [ { "on": 1489241854, "off": 1489241974, "run": 1489241854, "terminal": 4 }, { "on": 1489241854, "off": 1489241974, "run": 1489241854, "terminal": 8 } ], "timestr": "Sat Mar 11 2017 10:17:38 PM", "time": 1489241858000, "door": 0 }, "id": 998161 } My issue is detecting if I get none, one or multiple active zones. If I have a valid zone then I then want to put the first zone number into the zoneterminal variable. If I don't have a valid zone I just want to put 0 into the zoneterminal variable. The problem is when I try something like the code below I get [ERROR] 22:11:22: line 56: attempt to index field '?' (a nil value) I cant figure out how to deal with LUA arrays correctly. (specifically detecting valid entries) The json.null operator does not seem to work the same way on array values. -- This script polls data from a local Bluespray Irrigation controller every 60 seconds and displays the status of the active zones -- Its configured for a speicific system but could easily be adapted to any bluespray controller. -- This script is written for Fibaro HC2 -- Script written by Brom ([email protected]) -- version 0.1 (10/3/17) function round(x, n) n = math.pow(10, n or 0) x = x * n if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end return x / n end fdata = {} zonename_1 = "Front Lawn" zonename_2 = "Road Lawn" zonename_3 = "Front Garden" zonename_4 = "Back Lawn Left" zonename_7 = "Back Lawn Right" zonename_5 = "Back Garden Left" zonename_6 = "Back Garden Right" fdata.selfId = fibaro:getSelfId() fdata.selfIp = fibaro:get(fdata.selfId, "IPAddress"); -- Perform the grab from the irrigation controller. local irrigationcontroller= Net.FHttp(fdata.selfIp); response,status,errorCode = irrigationcontroller:GET("/api/status") -- Basic debugging fibaro:debug(response) -- Check the respose from the controller is valid and Pull out the details from the JSON response. if (tonumber(status)==200 and tonumber(errorCode)==0) then local irrigation = json.decode(response) -- If any of the responses are null then make them 0 if irrigation.result.time == json.null then polltime = 0 else polltime = irrigation.result.time end -- this bit does not work !!!! zoneterminal = irrigation.result.active_zones[1].terminal zoneon = irrigation.result.active_zones[1].on zoneoff = irrigation.result.active_zones[1].off zonerun = irrigation.result.active_zones[1].run -- Basic Debugging fibaro:debug("polltime: "..polltime) fibaro:debug("zoneterminal: "..zoneterminal) fibaro:debug("zoneon: "..zoneon) fibaro:debug("zoneoff: "..zoneoff) fibaro:debug("zonerun: "..zonerun) timeleft = (zoneoff - zonerun) / 2 / 60 fibaro:debug("timeleft: "..timeleft) -- Output to the device. if zoneterminal == 0 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," OFF ") end if zoneterminal == 1 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," ON "..zonename_1) fibaro:log("Time Left "..timeleft.." Min"); end if zoneterminal == 2 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," ON "..zonename_2) fibaro:log("Time Left "..timeleft.." Min"); end if zoneterminal == 3 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," ON "..zonename_3) fibaro:log("Time Left "..timeleft.." Min"); end if zoneterminal == 4 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," ON "..zonename_4) fibaro:log("Time Left "..timeleft.." Min"); end if zoneterminal == 5 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," ON "..zonename_5) fibaro:log("Time Left "..timeleft.." Min"); end if zoneterminal == 6 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," ON "..zonename_6) fibaro:log("Time Left "..timeleft.." Min"); end if zoneterminal == 7 then fibaro:call(fdata.selfId, "setProperty", "ui.watering.value"," ON "..zonename_7) fibaro:log("Time Left "..timeleft.." Min"); end if zoneterminal == 0 or zoneterminal == 1 or zoneterminal == 2 or zoneterminal == 3 or zoneterminal == 4 or zoneterminal == 5 or zoneterminal == 6 or zoneterminal == 7 then fibaro:debug("Valid Zone") else fibaro:call(fdata.selfId, "setProperty", "ui.watering.value","Error") end else fibaro:debug("error Irrigation Controller: "..errorCode) end -- sleep for 1 min fibaro:sleep(10000) -- fibaro:sleep(60000) Any help appreciated. ps Code for the output is really extra long. Looking to understand how I can manipulate the variable name / number I am outputting to reduce the number of if statements. Once I get this figured out I plan to also add in buttons to perform manual runs. Brom
  23. I'd like to see an optional parameter added that will disable triggering scenes when setting a global variable in LUA. The HTTP API has this functionality albeit in reverse (default to false) Something along the lines of: fibaro:setGlobal( varName, value [, invokeScenes] ) Where: varName: The name of the global variable value: The new value of the global variable invokeScenes: Boolean, default true
  24. Hi Wondering why we don't have resizable txt boxes in the LUA scripting page ? It's not often I code in LUA in HC2, but when I do .. gee it's annoying Thanks, al.
  25. Hi Fibaro users Many of us are experiencing a very strange bug since a long time that kill our scenes. This bug appear without any reasons after several hours/days without any problems, it's a major issue that give us the feeling that the Fibaro box is not reliable. Just to give you my example of yesterday evening 19:41:06 : [DEBUG] 07:07:03: Module Parents (128) pressButton to 1 [DEBUG] 07:07:03: Module Espace Famille (123) pressButton to 1 [DEBUG] 07:07:03: Date : 2017/03/07 07:07:03 [DEBUG] 19:41:06: line 35: unexpected character @ character: 1 0:1 [�] line: [DEBUG] 19:41:06: � [DEBUG] 19:41:19: Redémarrage auto du script Réveil Matin (106): 2017/03/07 19:41:19 [DEBUG] 07:00:00: Réveil matin enclenché [DEBUG] 07:00:09: Ouverture volets matin phase 1 [DEBUG] 07:00:15: Module Parents (128) pressButton to 2 I saw several subjects in this forum with the same problem but without any clear answer to the problem, for examples : https://forum.fibaro.com/index.php?/topic/22964-script-terminated-garbage-in-log-script-error-line-incorrect/#comment-100942 https://forum.fibaro.com/index.php?/topic/22658-scene-keeps-quitting-on-error/#comment-99007 https://forum.fibaro.com/index.php?/topic/23955-vdscene-weather-status-v10b-netatmo-weather-station-rain-wind/#comment-108439 https://forum.fibaro.com/index.php?/topic/22801-issue-in-scene-after-update-to-41/#comment-99865 As you can see in the sample, i'm using (like many of us) another scene to check that the main scene is still active or not, and if not, to restart it. In french forums, users have done a specific virtual device to check scenes and vd. It seems it's a Lua bug that can be solved only by Fibaro. Could someone in Fibaro check that point to finally solve it one time for all? PS : Sorry for my english...
×
×
  • Create New...