Jump to content

Search the Community

Showing results for tags 'node-red'.



More search options

  • 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

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Facebook


Google+


Skype


Website URL


WhatsApp


Country


Gateway/s


Interests

Found 6 results

  1. Here is an example of how to code in a "single instance / event" style. A style I'm using today for all of my scenes. The idea is that instead of having to deal with a new instance being spawned with every scene trigger, all triggers are dealt with from within a single scene instance that is continuously running. It becomes something close to a traditional event loop model found in most modern GUI frameworks. The advantages with coding scenes in this style are: Scene can keep state in local lua variables between scene invocations/triggers Easy to keep different rules/logic in the same scene without causing conflicts, e.g. combining continuous running loops/schedules with immediate reaction on incoming triggers Easy to distribute different rules/logic between different scenes and allow them to communicate Easy to schedule actions to do in the future - that can be easily cancelled if new information is gained. Because the scene is continuously running it doesn't matter if there is a heavy initialisation when the scene starts up (parsing HomeTables etc.) as it is only done once... The framework has extensive support to run and debug the scene offline on a PC/Mac to get things right before deploying the scene on the HC2. Offline it is easy to simulate trigger/events to understand if the logic is correct, something that is not always easy to detect in a asynchronous environment. It has proven to be easy to integrate with external event/msg based systems like Node-red, where scenes can both send and receive events to node-red and thus extend functionality with Alexa, Google home, Hue etc etc. The framework is available in two version, a 'light' version and a full blow version with a lot of bells and whistles. The latter also supports writing rules in EventScript, a "simple", but very flexible and efficient approach to writing rules that need to trigger things at various times of the day, or trigger on sensors or switches changing states. The implementation of EventScript is built on-top of the single instance framework and the event model and would have been impossible to do in a traditional scene model. Ex of EventScript rules. --[[ %% properties 55 value 66 value 77 value 78 sceneActivation 88 ui.Slider1.value 88 ui.Label1.value %% events 100 CentralSceneEvent 120 AccessControlEvent %% globals Home %% autostart --]] myLightSensor = 55 -- do not declare local, script will not find them(!) myLight1 = 66 myLight2 = 67 myDoorSensor = 77 mySwitch = 78 myVD=88 myKeyFob = 100 myLock = 120 function main() -- Trigger rukes Rule.eval("myLightSensor:lux > 200 => myLight1:on") -- Turn on light1 if lux value goes above 200 Rule.eval("myLight1:isOn => myLight2:on") -- Turn on light2 if light1 is turned on Rule.eval("myDoorSensor:breached => myLight1:on") -- Turn on light1 if door sensor is breached Rule.eval("mySwitch:scene == S2.click => myLight1:on") -- Turn on light1 if S2 is clicked once Rule.eval("slider(myVD,'Slider1') == 50 => myLight1:on") -- Turn on light1 if slider is set to 50 Rule.eval("label(myVD,'Label1') == 'ON' => myLight1:on") -- Turn on light1 if label is set to 'ON' Rule.eval("myKeyFob:central.keyId==4 => myLight1:on") -- Turn on light1 if key 4 is pressed on keyFob Rule.eval("myLock:access.status=='Unlock' => log('Door unlocked by %s',myLock:access.name)") -- Door unlocked Rule.eval("$Home == 'AWAY' => myLight1:on") -- Turn on light1 if fibaro global variable 'Home' is set to 'AWAY' Rule.eval("#AccessControlEvent{data={name='$name',slotId='$slot',status='Unlock',id=myLock}} => log('Door unlocked by %s',name)") lamp = 55 lamp2 = 56 lux = 57 lux2 = 58 sensor = 66 switch = 77 -- S2 switch keyfob = 88 -- more rules -- Turn on lamp at 15min before sunset Rule.eval("@sunset-00:15 => lamp:on") -- Turn off 2 lamps 15min past sunrise on weekdays Rule.eval("@sunrise+00:15 & wday('mon-fri') => {lamp,lamp2}:on") -- Turn on lamp if sensor breached Rule.eval("sensor:breached => lamp:on") -- Turn off lamp if sensor safe for 5min Rule.eval("for(00:05,sensor:safe) => lamp:off") -- Turn on lamp if doubleclick on switch S2 Rule.eval("switch:scene==S2.double => lamp:on") -- Toggle lamp if key '1' pressed on keyfob Rule.eval("keyfob:central.keyId=='1' => lamp:toggle") -- Turn on lamp if average lux is less than 200 Rule.eval("sum({lux,lux2}:lux)/2<200 => lamp:on") end More on EventScript and the full blown version is available in the posts listed below: Here is a post on setting up the framework (works for EventRunnerLite too) Here is a post on the EventRunnerLite version - a bare bone version of the framework Here is a post on writing schedulers using EventScript. Here is a post on writing trigger rules using EventScript. Here is a post on EventScript syntax and rules Here is a post on writing Lua event handlers Here is a post on debugging the framework Here is a post on enabling Hue support - mapping of Hue devices to standards z-wave/fibaro:* calls Here is a post on integrating the event model with Node-red - sending/receiving events from node-red, with extendable, example flow. Gives support for Sonos TTS and Alexa input... Here is a post on running and debugging standard HC2 scenes - using the EventRunner framework (SceneRunner) There will also be some services based on the EventFramework posted iOSLocator - a service that checks with iClod for people at places and sends events to other EventFramework services Logger service - TBD Alarm service - TBD CronRunner - a UNIX like crontab service other scenes can register call-backs with Supervisor - A scene that pings EventRunner scenes and makes sure they stay alive. Best practices rules - TBD Implementation notes Notes on the basic EventRunner framework Notes on the EventScript implementation - TBD ChangeLog for the EventRunner framework. The lastest version of the code is kept in my GitHub. The background of this framework and a thread discussing it can be found here, however the code has evolved a bit from when originally posted there.
  2. Hi, tired of Fibaro's poor skill at Amazon Alexa (never connect, it's slow) and the HABridge (we must pray for Alexa to find the devices, it is very random, it works when it wants, it duplicates devices). For all that I decided to try and do tests with Node-RED. And now I can say that it is fantastic, there are no limits to create. If you are interested I leave more info. Now I can control the lights, turn on and off, change the intensity, change the color, execute scenes of Fibaro and many things, all without depending on the official skill or any third party Bridge. I used: * https://nodered.org (Installed in Raspberry) * https://www.amazon.com/Ben-Hardill-Node-RED/dp/B01N0D97FZ (Node-RED alexa skill) * https://alexa-node-red.bm.hardill.me.uk (You have to create user and then create all the devices and scenes) * "HomeTable" global variables in HC2
  3. amatt

    Node-Red Change Variable

    Can someone help me with Node-Red? I need to tell node-Red to change a global value in HC2. Thanks for the Help
  4. Hi to you all! Maybe you know that I'm a critical HC2 user since 2013. In short, as I mention here I was feeling the Fibaro was holding me back in possibilities, privacy and security. So I started to investigate to get more control over what I think was important to me. I said I would abandon the HC2. The good news, I will not (for now). After extensive testing and trying to find a proper configuration, I found a way to implement the HC2, demanding my needs and wishes concerning: Security Privacy Possibilities Time to spend (re-configuring 200+ devices, 50 scenes and 30 Virtual Devices) The solution I'm implementing is a Raspberry Pi 3 with Node-Red for all communications from the HC2. In short, this means using the HC2 solely as a Z-wave controller and automation gateway. Setup: - The Node-Red will receive commands from the HC2 by an encrypted (https) and password protected connection. At this point it's still one way by sending from the HC2 to Node-Red. - The HC2 is (will be) blocked from internet access. Internet access to the HC2 will be done by VPN. - All other domotica devices are on a separate subnet (VLAN). - All messages (email/push/Telegram) is processed by Node-Red. (disabling all Fibaro 'services'). Example: An alarm is breached: - HC2 will send a message by https to Node-Red. - Node-Red sends IP-Camera snapshots to own email-server, push-account or private Telegram-bot. - Node-Red will check my Ubiquiti manage-switch to check if someone is at home (Mobile phone present in LAN) at will send result to push or Telegram. For sending data to Node-Red a scene is used with content of 5 Global Variable, triggered by one: SC_Nred_VarName (Name variable to send. used as trigger, must be written as last) SC_Nred_VarVal (Value to send) SC_Nred_VarType (not used yet, could be used for sending the type of value, like string, date, time etc.) SC_Nred_VarLog (data for storing data in Node-Red logfiles) SC_Nred_VarPath (path to the Node-Red http-receive-node, default /hc2) The scene code (Beta code 20170526): --[[ %% properties %% events %% globals SC_Nred_VarName --]] -- -- Initialisation of user settings (change if necessary) -- -- Global variables (has to be added manually in HC2 variables panel) local globVarName = 'SC_Nred_VarName'; -- Name of global variable to send (trigger!) local globVarValue = 'SC_Nred_VarVal'; -- Value of global variable to send local globVarType = 'SC_Nred_VarType'; -- Type of global variable to send local globVarLog = 'SC_Nred_VarLog'; -- Logmessage to send local globVarPath = 'SC_Nred_VarPath'; -- Node-Red http-node path to interact with -- Node-Red server connections credentials local nredIp = '192.168.x.x'; -- Node-RED server IP-address local nredPort = 1880; -- Node-Red server port number local nredUser = 'HC2'; -- Node-Red user used to change variables local nredPass = 'XXXXXXXXXXXXXXXX'; -- Node-Red password of used user -- Node-Red server credentials options: true = Enable, false = Disable local nredUseLogin = false; -- TODO!! Option to use user/password login (default = false) local nredUseSecure = true; -- Option to use secure https connections (default = true) -- Node-Red http-node settings local nredPathDefault = 'hc2'; -- Default Node-Red http-node path to interact with local nredVarName = 'name'; -- Node-Red http-node option for variable name local nredVarValue = 'value'; -- Node-Red http-node option for variable value local nredVarType = 'type'; -- Node-Red http-node option for variable type local nredVarLog = 'log'; -- Node-Red http-node option for variable log -- Debug options: true = Enable (default), false = Disable local debug = true; -- -- Funtions (do not change) -- -- Debug and Log local function log(str) if debug then fibaro:debug('<font color="yellow">'..str..'</font>'); end; end local function errorlog(str) fibaro:debug('<font color="red">'..str..'</font>'); end -- -- Code (do not change) -- -- Prevents the scene from running when command is 0 if (tonumber(fibaro:getGlobalValue(globVarName)) == 0) then fibaro:abort(); end -- Get variable content from global variable and convert to usable values -- Name value content local nredName = fibaro:getGlobalValue(globVarName); local nredName = string.gsub(nredName,'%s','%%20'); -- Replace <space> with %20 local nredName = string.gsub((nredName),'?','%%3F'); -- Replace ? with %3F --local nredName = string.gsub((nredName),'%','%%25'); -- TODO! Replace % with %25 -- Value content local nredValue = fibaro:getGlobalValue(globVarValue); local nredValue = string.gsub((nredValue), '%s', '%%20'); -- Replace <space> with %20 local nredValue = string.gsub((nredValue),'?','%%3F'); -- Replace ? with %3F --local nredValue = string.gsub((nredValue),'%','%%25'); -- TODO! Replace % with %25 -- Type value content local nredType = fibaro:getGlobalValue(globVarType); local nredType = string.gsub((nredType), '%s', '%%20'); -- Replace <space> with %20 local nredType = string.gsub((nredType),'?','%%3F'); -- Replace ? with %3F --local nredType = string.gsub((nredType),'%','%%25'); -- TODO! Replace % with %25 -- Log value content local nredLog = fibaro:getGlobalValue(globVarLog); local nredLogIsChanged = ''; if nredLog == '' or nredLog == nil then nredLogIsChanged = ' is changed to'; nredLog = os.date("%d/%m/%Y %X ")..': '..nredName..' --> '..nredValue; end if debug then fibaro:debug('Logcontent'..nredLogIsChanged..': '..nredLog) end; local nredLog = string.gsub((nredLog), '%s', '%%20'); -- Replace <space> with %20 local nredLog = string.gsub((nredLog),'?','%%3F'); -- Replace ? with %3F -- Node-Red http-node path value local nredPath = fibaro:getGlobalValue(globVarPath); if debug then fibaro:debug('Node-RED Path: '..nredPath) end; if nredPath == '' or nredPath == nil then nredPath = nredPathDefault; end local nredPath = string.gsub((nredPath), '%s', '%%20'); -- Replace <space> with %20 local nredPath = string.gsub((nredPath),'?','%%3F'); -- Replace ? with %3F -- Construct API URL if nredUseSecure then urlPre = 'https'; else urlPre = 'http'; end local apiURL = urlPre..'://'..nredIp..':'..nredPort..'/'..tostring(nredPath)..'?'..tostring(nredVarName)..'='..tostring(nredName)..'&'..tostring(nredVarValue)..'='..tostring(nredValue)..'&'..tostring(nredVarType)..'='..tostring(nredType)..'&'..tostring(nredVarLog)..'='..tostring(nredLog); if debug then log(apiURL) end; -- Initialisation of communication to Node-Red local selfHttp = net.HTTPClient(); -- Sending HTTP apiURL selfHttp:request(apiURL, { options={ headers = selfHttp.controlHeaders, data = requestBody, method = 'GET', timeout = 5000 }, success = function(status) local result = json.decode(status.data); if result.status == 'OK' then if debug then log('<font color="green">Respond is OK</font>') end; else errorlog('failed'); if debug then log(status.data) end; end end, error = function(error) errorlog("ERROR"); if debug then log(error) end; end }) -- Reset the global command variable to 0 and empty all other global variables fibaro:setGlobal(globVarValue, ''); fibaro:setGlobal(globVarType, ''); fibaro:setGlobal(globVarLog, ''); fibaro:setGlobal(globVarPath, ''); fibaro:setGlobal(globVarName, '0'); -- Trigger variable, write as last To actually send data, a Virtual Device can be used with buttons to write values to the proper global variables. For example (when balcony security is breached, VD report-label name = RedNodeAlarmLabel): -- -- Initialisation of user settings (change if necessary) -- -- Global variables (has to be present in HC2 variables panel) local globVarName = 'SC_Nred_VarName'; -- Global variable used for Node-RED variable name local globVarValue = 'SC_Nred_VarVal'; -- Global variable used for Node-Red variable value local globVarType = 'SC_Nred_VarType'; -- Global variable used for Node-Red variable type local globVarLog = 'SC_Nred_VarLog'; -- Global variable used for Node-Red variable Log (String) local globVarPath = 'SC_Nred_VarPath'; -- Node-Red http-node path to interact with -- Symbol and text table local symbolTable = { -- Symbols to show in this VD buttonIcon = 'Balcony', -- Symbol representing activating this button (for VD Label) buttonText = 'Alarm', -- Text representing activating this button (for external log) timeLastRun = 'Time: ' -- Symbol representing time of last run } -- Node-Red http-node values to send local sendName = 'HC2_Alarm_Balcony'; -- Node-Red variable name to use local sendValue = 'Balcony'; -- Node-Red variable value to use local sendType = '2'; -- Node-Red variable type to use -- Types: 0 = Integer, e.g. -1, 1, 0, 2, 10 -- 1 = Float, e.g. -1.1, 1.2, 3.1 -- 2 = String -- 3 = Date in format DD/MM/YYYY -- 4 = Time in 24 hr format HH:MM -- 5 = DateTime (but the format is not checked) local sendLog = tostring(symbolTable.buttonText.. os.date(" %d/%m/%Y %X ")..symbolTable.buttonText..' --> '..sendValue); local sendPath = 'hc2_alarm'; -- Debug options local debug = true; -- Enable (default, true) or disable (false) general debug output local debugCommands = true; -- Enable (true) or disable (false, default) debug output of command sending to Homey -- ------------------------------------------------------------------------------------------ -- Initialisation of code (do not change unless you know what you are doing!) -- ------------------------------------------------------------------------------------------ local selfId = fibaro:getSelfId(); local selfLabel = 'RedNodeAlarmLabel'; local function debugLog(_logString, _logStringColor, _logValue, _logValueColor) fibaro:debug('<span style="color:'.._logStringColor..'"> '..tostring(_logString)..' </span><span style="color:'.._logValueColor..'"> '..tostring(_logValue)..'</span>'); end -- ------------------------------------------------------------------------------------------ -- Code (do not change) -- ------------------------------------------------------------------------------------------ -- store values (store scene-trigger as the last) fibaro:setGlobal(globVarValue, sendValue); fibaro:setGlobal(globVarType, sendType); fibaro:setGlobal(globVarLog, sendLog); fibaro:setGlobal(globVarPath, sendPath); fibaro:setGlobal(globVarName, sendName); -- Scene-trigger fibaro:call(selfId, "setProperty", "ui."..selfLabel..".value", symbolTable.buttonIcon..' '..symbolTable.timeLastRun.. os.date(" %d/%m/%Y %X ")); fibaro:log(symbolTable.buttonIcon); if debugCommands then debugLog(symbolTable.buttonIcon..' '..symbolTable.timeLastRun.. os.date(" %d/%m/%Y %X. "), 'orange', 'Variable name: '..sendName..', type: '..sendType..', value: '..sendValue, 'yellow') end; Node-Red Nodes examples: Receiving data and respond with 'OK' Processing content of received values: Example Commandfilter code with 5 outputs: var input = { payload: msg.payload }; // Output 1 (msg.payload) var hc2AlarmAlgemeen; // Output 2 (HC2_Alarm_Generic) var hc2AlarmGarage; // Output 3 (HC2_Alarm_Garage) var hc2AlarmBalkon; // Output 4 (HC2_Alarm_Balcony) var add2Log; // Output 5 (add2Log) // --> Output 1 (msg.payload) // Content of payload: // Name: msg.payload.name // Value: msg.payload.value // Type: msg.payload.type // Log: msg.payload.log // --> Output 2 (HC2_Alarm Generic) if (msg.payload.name === "HC2_Alarm_Generic") { hc2AlarmAlgemeen = { payload: msg.payload.value }; add2Log = { payload: msg.payload.log }; } // --> Output 3 (HC2_Alarm Garage) if (msg.payload.name === "HC2_Alarm_Garage") { hc2AlarmGarage = { payload: msg.payload.value }; add2Log = { payload: msg.payload.log }; } // --> Output 4 (HC2_Alarm Balcony) if (msg.payload.name === "HC2_Alarm_Balcony") { hc2AlarmBalkon = { payload: msg.payload.value }; add2Log = { payload: msg.payload.log }; } // Set to proper outputs return [ input, hc2AlarmGeneric, hc2AlarmGarage, hc2AlarmBalcony, add2Log ]; How to get snapshots from IP-camera and send to Telegram: https://github.com/guidone/node-red-contrib-chatbot/wiki/Examples Updates, changes and additional info: 20170527 Setup Raspberry Pi with Node-Red Short Guide 20171017 Setup Raspberry Pi with MQTT (Mosquitto) Short Guide Beware, this is not out-of-a-box solution. Just want to share this example because the possibilities are huge! Greetings, Lambik
  5. Hi2Uall! I configured a (working) Raspberry Pi 3 Raspbian with Node-Red and MQTT (see this excellent YouTube video for explanation). Now on working, and learning (a lot) how to implement this. So far it is very useful to connect several IoT services. Did anyone have an idea how to connect the HC2 to an MQTT server?
  6. mlindahl

    HC2 - Virtual device

    I wonder if there is any plans on expanding the functionality of the virtual device in Fibaro HC2. As it works now it´s most suitable to use for controlling some other device with buttons, slider etc, and if you want to display data from another device all you can use is the label. My wish is that you should be able to choose the type of the virtual device. For example, if you want it to appear as a thermometer or humidity device, and be able to set the value of this device via http api and lua. This would open up the possibility to add virtual devices that gets updated via for example node-red or http from other sources. And in the user interface they will show up as a "common" sensor. That would be really nice. I think this functionality would make the platform more attractive for many people, and open up the integration between different protocols and vendors. Is it just me or is anybody else missing this functionality?
×