Navigation

    Discussion Forum to share and further the development of home control and automation, independent of platforms.

    SmartHome Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Unsolved
    (Last Updated: October 23, 2020)
    • Luup : Error Handling

      parkerc

      Hi,

      Please could people share how they are presenting and handling errors in their Vera / OpenLuup plugins, I’ve tried to look through various Implementation files, but very few seem to have anything, other than perhaps a luup.task (which for some reason doesn’t work for me) ?

      Below is the startup and check/validation functions for a plugin I’m working on..

      function checkIPPowerSetUp(lul_device) log("Checking if parent device is configured correctly...") ipAddress = luup.devices[lul_device].ip -- check if parent device has an ip address assigned if ipAddress == nil or ipAddress == "" then -- if not stop and present error message luup.task('ERROR: IP Address is missing',2,'IPPower',-1) debug("ERROR: IP Address is missing " ..ipAddress.. " unable to progress") return false else -- if one is provided, present success message luup.task('IP Address for IPPower 9258 present, setup continues',4,'IPPower',-1) debug("IPPower StartUp activated - Device #" .. lul_device .. " now creating children") createChildIPPowerOutlets(lul_device) luup.call_delay("IPPowerPoller", 5) return true end end function IPPowerStartup(lul_device) -- set attributes for parent device luup.attr_set( "name", "IPPower 9258", lul_device) luup.attr_set( "category_num", "3", lul_device) luup.attr_set( "subcategory_num", "1", lul_device) luup.variable_set("urn:nodecentral-net:serviceId:IPPower1", "Icon", 1, lul_device) luup.variable_set("urn:nodecentral-net:serviceId:IPPower1", "PluginVersion", PV, lul_device) checkIPPowerSetUp(lul_device) log("Start up, Parent device created...") end </functions> <startup>IPPowerStartup</startup>

      What’s the best way to present errors to the user, and make iot clear what they need to do ?

      Code/Snippet library
    • Help with luup.chdev.sync

      therealdb

      I'm struggling to fix the code attached here

      dbochicchio/vera dbochicchio/vera

      LUA Scripts for the eZlo Vera Platform (UI7). Contribute to dbochicchio/vera development by creating an account on GitHub.

      Under certain circumstances (thanks @DesT!) I see that it's causing a luup reload infinite cycle, because child devices are being created, then deleted. Specifically, I see this in the logs:

      2020-06-01 19:35:30.482 luup.chdev.sync:: [102] Open Sprinkler Test, syncing children 2020-06-01 19:35:30.482 openLuup.chdev:: deleting [413] Daily Garden 2020-06-01 19:35:30.482 openLuup.chdev:: deleting [414] Water Level 2020-06-01 19:35:30.482 openLuup.chdev:: deleting [411] Daily Cedars 2020-06-01 19:35:30.482 openLuup.chdev:: deleting [412] St-Eustache Rules AM 2020-06-01 19:35:30.482 openLuup.luup:: device 102 'Open Sprinkler Test' requesting reload

      The devices are created (look at line 357/410), but when I call luup.chdev.sync, they got deleted. Any hints? Thanks

      Code/Snippet library
    • Vera StaticJSON Help - Showing a button’s status/selection (in/out) in the UI ?

      parkerc

      Hi

      I’m putting the finishing touches to a HDMI Matrix plugin, and while I have it working well - I can’t find anything on the Vera/MIOS wikis that tells me how I can show if a UI button is pressed or not (to reflect a input choice that is selected)

      Here’s a screenshot of the child outputs I’ve created for the Matrix switcher. (The plugin creates a parent device and then 4 children to show the Matrix Outputs - parent is not shown - and the idea is that’s you select the input number for the respective output)

      BB5B6001-294E-4AE9-A095-D2E639F56B9C.jpeg

      Here is an extract of the button element in the associated JSON file used for the child devices..

      { "ControlGroup": "1", "ControlType": "button", "top": "0", "left": "0", "Label": { "lang_tag": "Input1", "text": "Input1" }, "Display": { "Top": 60, "Left": 50, "Width": 75, "Height": 20 }, "Command": { "Service": "urn:nodecentral-net:serviceId:SYMatrix1", "Action": "SYCall", "Parameters": [ { "Name": "action", "Value": "I1" } ] } },

      The associated command calls the parent implementation file SYCall - (The value “I1” relates to a element of the URL that needs to be called to select that associated input)

      <action> <serviceId>urn:nodecentral-net:serviceId:SYMatrix1</serviceId> <name>SYCall</name> <run> SYMatrix.SYCall(lul_device, lul_settings.action, lul_settings) </run> </action>

      And then the Lua file (L_****) has holds the SYCall function

      function SYCall (deviceNo, action, settings) ….. end
      Code/Snippet library
    • URL - /data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=

      parkerc

      I’ve just started to have a play with iOS Shortcut and one of my test cases is to see if I can do the following

      select a a file (.lua or .txt) on my iPad extract the entire script/contents encode the data obtained append the encode content to the end of the RunLua action. call the URL http://myIP/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=

      Below is a screenshot of the workflow I have built in Shortcuts, which seems pretty straight forward, and it does generate a encoded URL, however the actual request itself does not complete. I get an ‘OK’ response back eventually, but the code is not actioned, and the logs don’t seem to tell me anything..

      FAB8DB5F-9003-4624-BCF3-8F536A660D21.jpeg

      The code I’m extracting from the Lua file works fine in the test Lua window, so i’m not sure what’s occurring differently, between the two routes, maybe it’s the encryption being used ?..

      Is anyone able to help me test this, and see if they can generate a long / multi line RunLua encoded URL (if not via Shortcut, then by some that can help me with the root cause to then address that in Shortcut

      Code/Snippet library
    • Lua : http(s) request, works on some URLs, but not all ? But all work via the browser..

      parkerc

      I have a couple of calendar URLs I’m trying to call, and both work when i enter the URL into the browser, however when I try to call them via Lua and http(s).request, only one of them works ? Please could someone help me understand why, and what needs to be done differently to make the other one work ?

      local socket = require 'socket' local http = require "socket.http" local ssl = require 'ssl' local https = require 'ssl.https' local calendarUria = "https://ics.fixtur.es/v2/ipswich-town.ics" local calendarUrib = "https://calendar.google.com/calendar/ical/en-gb.uk%23holiday%40group.v.calendar.google.com/public/basic.ics" print("Fixtur.es Football (URL A) returns the following?") local responseBodya, responseCodea, responseHeadersa = https.request(calendarUria) print(responseBodya, responseCodea, responseHeadersa) print("Google UK Holidays (URL B) returns the following?") local responseBodyb, responseCodeb, responseHeadersb = https.request(calendarUrib) print(responseBodyb, responseCodeb, responseHeadersb)

      If you run the code above, only the second Google (URL `B) returns anything..

      Code/Snippet library
    • Add-on - Aviosys IPPower 9258

      parkerc

      Hi

      Picking up from another thread this is to focus on the creation of the 4 key elements of a new Plugin for my Aviosys IPPower 9258, which are quite old, and I don’t believe are made anymore, but they seem to have a simple http api interface to cut my teeth on with a plugin.

      First the device file, which is to support the creation/set up of the device, and here I explain what it is, tell Vera what the implementation file and .json file is, and also leverage the pre-existing Switch and HA capabilities..

      Device File - D_IPPower.xml

      <?xml version="1.0"?> <root xmlns="urn:schemas-upnp-org:device-1-0"> <specVersion> <major>1</major> <minor>0</minor> </specVersion> <device> <deviceType>urn:nodecentral-net:device:IPPower:1</deviceType> <staticJson>D_IPPower1.json</staticJson> <manufacturer>Aviosys</manufacturer> <modelDescription>IPPowerSwitch</modelDescription> <modelName>IPPower9258</modelName> <handleChildren>1</handleChildren> <implementationList> <implementationFile>I_IPPower1.xml</implementationFile> </implementationList> <serviceList> <service> <serviceType>urn:schemas-upnp-org:service:SwitchPower:1</serviceType> <serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId> <SCPDURL>S_SwitchPower1.xml</SCPDURL> </service> <service> <serviceType>urn:schemas-micasaverde-com:service:HaDevice:1</serviceType> <serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId> <SCPDURL>S_HaDevice1.xml</SCPDURL> </service> </serviceList> </device> </root>

      Next it is the Implementation file, which thanks to the feedback on this forum, will focus on a specific Lua file, where all the code will be, the only thing I need to add here are the Actions (what do I want it to be able to do etc.)

      Implementation file - I_IPPower.xml

      <?xml version="1.0"?> <!-- I_IPPower.xml; Vera/openLuup "IPPower 9258" Plug-in V1.1 Nov 2021 --> <implementation> <settings> <protocol>crlf</protocol> </settings> <files>L_IPPower1.lua</files> <startup>IPPowerStartup</startup> <actionList> <action> <serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId> <name>SetTarget</name> <job> local url = "http://" .. ipAddress .. "/set.cmd?user=admin+pass=12345678+cmd=setpower+" .. luup.devices[lul_device].id .. "=" .. lul_settings.newTargetValue luup.log("Sending command " .. url) local status, data = luup.inet.wget(url) if (data) then debug("Data received = " .. data) else log("No Data received !! ") end local value = string.match(data, luup.devices[lul_device].id.."=(%d)") if (value) then luup.variable_set("urn:upnp-org:serviceId:SwitchPower1", "Status", value, lul_device) else log("Value returned is empty") end </job> </action> </actionList> </implementation>

      The other two files D_IPPower.json, and L_IPPower.lua are still being worked on so i will add later …

      If anyone notices any improvement

      Code/Snippet library
    • Lua : storage.set , storage.get

      parkerc

      Hi

      I’ve seen storage.set and storage.get used in some Lua code posted on the internet, where they need to store/retrieve somethings, e.g.

      iv = encdec.base64dec(challenge_Key)     storage.set('IV', iv)

      and then later on within another function I see..

      iv = storage.get('IV')

      It makes sense how this is meant to work, and it seems such a simple/elegant feature - hence I was wondering, is there an equivalent in Vera/OpenLuup? As I’d naturally go to use luup.variable_set and luup.variable_get - but that requires a device to be used etc.

      Code/Snippet library
    • Get your Alexa replies to the device you've asked them to with VeraAlexa plug-in

      therealdb

      So, I was messing with my Alexa routines and ha bridge, and I want to share something very cool you could do with the ability to get the last Alexa that heard your command. I mentioned it a couple of times on the old place, but Vera's OS is missing the jq package, but openLuup could have it installed.

      Basically, just execute -lastalexa with my VeraAlexa plug-in:

      local lastAlexa = luup.call_action("urn:bochicchio-com:serviceId:VeraAlexa1", "RunCommand", {Command="-lastalexa"}, 666)

      Then use it in your scene, to dynamically generate your TTS response with the device you've asked your question seconds before!

      local temperature = 25 -- get it from your sensor luup.call_action("urn:bochicchio-com:serviceId:VeraAlexa1", "Say", {Text="Ok, outise temperature is " .. temperature .. " degree", Volume=50, GroupZones= lastAlexa, Repeat = 2}, 666

      Very cool indeed 🙂

      Code/Snippet library
    • Luup : Hue Energy (watts) Calculator

      parkerc

      Hi all

      I’ve been trying to use the Hue api and some of my Lua knowledge to create an energy calculator based on the brightness and wattage of specific models of hue bulb registered on the hub

      I’ve pretty much got there, the only stumbling block I have is how I total up all the individual bulb wattages. Can anyone help ?

      It’s likely an easy thing for someone more experienced to see, but as I only dip in and dip out now and then, the correct code/syntax does not always come to mind.

      Note : as I’ve tried various routes, I’ve commented some things out, but you should be able to get the idea of what I’m trying to do..

      Create device json from Hue Hub Decode JSON and extract key values to a table Calculate approx watts based on bulb model and/or watts function Total up watts of all bulbs that are switch on.

      Code below...

      local hueBridgeIP = '192.168.1.29' local hueBridgeAPI = "80uCoXjnn2LNLhxEJ9PW6nmt-G5KWQ2uP3oONAvcm0j" function getHueLight() local http = require('socket.http') local ltn12 = require('ltn12') local json = require('dkjson') t = {} local url = string.format("http://%s/api/%s/lights", hueBridgeIP, hueBridgeAPI) b, c, h = http.request{url=url, sink = ltn12.sink.table(t), method='GET'} huestring = tostring(table.concat(t)) local hue, pos, err = json.decode(huestring, 1, nil) huelights = {} for k, v in pairs(hue) do local modelno = string.gsub(hue[k]['modelid'], "%s+", "") table.insert(huelights, {k, hue[k]['state']['on'], hue[k]['name'], hue[k]['state']['bri'], modelno, hue[k]['state']['reachable']}) print(k, hue[k]['state']['on'], hue[k]['name'], hue[k]['state']['bri'], modelno, hue[k]['state']['reachable']) end end local fourpointeightwattTable = { [ 1 ] = 0.6 , [ 2 ] = 0.7 , [ 3 ] = 0.8 , [ 4 ] = 0.9 , [ 5 ] = 1.2 , [ 6 ] = 1.4 , [ 7 ] = 1.7 , [ 8 ] = 2.0 , [ 9 ] = 2.3 , [ 10 ] = 2.6 , [ 11 ] = 2.9 , [ 12 ] = 3.1 , [ 13 ] = 3.5 , [ 14 ] = 4.0 , } local sevenwattTable = { [ 1 ] = 1.6 , [ 2 ] = 1.7 , [ 3 ] = 1.8 , [ 4 ] = 1.9 , [ 5 ] = 2.2 , [ 6 ] = 2.4 , [ 7 ] = 2.7 , [ 8 ] = 3.0 , [ 9 ] = 3.5 , [ 10 ] = 3.9 , [ 11 ] = 4.5 , [ 12 ] = 5.1 , [ 13 ] = 5.5 , [ 14 ] = 6.4 , } local ninewattTable = { [ 1 ] = 1.6 , [ 2 ] = 1.7 , [ 3 ] = 1.8 , [ 4 ] = 1.9 , [ 5 ] = 2.2 , [ 6 ] = 2.5 , [ 7 ] = 2.9 , [ 8 ] = 3.5 , [ 9 ] = 3.8 , [ 10 ] = 4.6 , [ 11 ] = 5.5 , [ 12 ] = 6.5 , [ 13 ] = 7.7 , [ 14 ] = 8.5 , } function fourpointeightgetWattage(hue) local index = math.floor(hue / 16.5) if index <= 0 then return 0.2 elseif index >= 15 then return 4.8 else return fourpointeightwattTable[index] end end function sevengetWattage(hue) local index = math.floor(hue / 16.5) if index <= 0 then return 0.4 elseif index >= 15 then return 7.0 else return sevenwattTable[index] end end function ninegetWattage(hue) local index = math.floor(hue / 16.5) if index <= 0 then return 0.4 elseif index >= 15 then return 9.0 else return ninewattTable[index] end end local total = 0 local Value = 0 local huewatts = {} for k,v in pairs(huelights) do if v[2] == true and v[5] == "RS125" and v[6] == true then local watts = fourpointeightgetWattage(v[4]) local Value = tonumber(watts) local total = total + Value print("four point eight watts") print(v[5], v[4], v[2], v[3], watts) table.insert(huewatts, {v[5], v[4], v[2], v[3], watts}) --print(watts) --print(total) elseif v[2] == true and v[5] == "LWA004" and v[6] == true then local watts = sevengetWattage(v[4]) local Value = tonumber(watts) local total = total + watts print("seven watts") print(v[5], v[4], v[2], v[3], watts) table.insert(huewatts, {v[5], v[4], v[2], v[3], watts}) --print(watts) --print(total) elseif v[2] == true and v[6] == true then local watts = ninegetWattage(v[4]) local Value = tonumber(watts) local total = total + Value print("nine watts") print(v[5], v[4], v[2], v[3], watts) table.insert(huewatts, {v[5], v[4], v[2], v[3], watts}) --print(watts) --print(total) end end print(total) print(huewatts) -- confirm if table it there (TBC)
      Code/Snippet library
    • UDP Datagrams

      therealdb

      I've implemented this:

      https://smarthome.community/topic/20/openluup-version-log/18

      into my own MQTT Server and that's cool, since I'm now pushing every variable via MQTT, originating from the Vera.

      Just a couple of questions for @akbooer

      do I need to check that sock is connected, from time to time? is there anything specifically to retry the command?

      I'm running it in the latest hour, and everything seems OK, but I want to code it for the worst situations. Thanks, always inspiring!

      Code/Snippet library
    • Luup : Whole house energy usage.

      parkerc

      Hi all

      Here’s another snippet of code I like to use, to see what’s going on.
      If anyone has any variations on this, I’d love to see it.

      local variables = {"Watts"} local NRG_SER = "urn:micasaverde-com:serviceId:EnergyMetering1" local total = 0 for lul_device in pairs(luup.devices) do local readings = {} -- create empty array called readings for _, variable in ipairs(variables) do -- using the id and value in variables table above local value = luup.variable_get(NRG_SER, variable, lul_device) local name = luup.attr_get ('name', lul_device) table.insert( readings, { variable, tonumber(value), name}) -- populate readings table end for _, reading in ipairs(readings) do local Variable = reading[1] local Value = reading[2] or 0 local Name = reading[3] or "Unknown" total = total + Value if Value ~= 0 then print(Name, Variable.. " - ".. Value) end end end print("Total watts = " ..total)
      Code/Snippet library
    • Luup : Foscam API

      parkerc

      Sharing the love...

      As I have a number of foscam cameras around the house, using their API I created the following bit of code to set to retrieve any settings across all of them, to keep them in sync.

      This one gets the device name from each of them. If anyone has any variations or ways to improve the bit of code please let me know..

      local url = require("socket.url") local URL = "http://" local username = "admin" local password = "password" local cmd = "getDevName" -- /cgi-bin/CGIProxy.fcgi?cmd=getDevName&usr=admin&pwd= local foscamsIPs = { { NO=1, IP="192.168.102.165:88", LOCATION="conservatory"}, { NO=2, IP="192.168.102.38:80", LOCATION="boiler room"}, { NO=3, IP="192.168.102.223:88", LOCATION="Living room"}, { NO=4, IP="192.168.102.245:88", LOCATION="front room"}, { NO=5, IP="192.168.102.104:88", LOCATION="kitchen"}, } for k,v in pairs(foscamsIPs) do -- Read each value. local update = URL .. v["IP"] .. "/cgi-bin/CGIProxy.fcgi?cmd="..cmd.."&usr="..username.."&pwd="..password -- do this for each reading. local status, result = luup.inet.wget(update) print(v["LOCATION"].. " status is " ..status.. " : result is " ..result) end````
      Code/Snippet library
    • Help with luup.call_delay()

      T

      I have this block of lua and I am using luup.call_delay to delay the sending of IR codes. it works as intended but I am trying to eliminate the use of luup.sleep for the delay before the tcp:close() as well. i cant figure out how to implement luup.call_delay() for the tcp:close() and keep the luup.call_delay intact for the delay between the IR codes.

      Thanks in advance.

      function Delay1() --[[HDMI Matrix B1--]] local socket = require("socket") tcp = assert(socket.connect("192.168.255.204", 4998)) tcp:send("sendir,1:3,1,38000,1,69,341,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,64,22,21,22,21,22,64,22,21,22,64,22,21,22,21,22,21,22,64,22,64,22,21,22,64,22,21,22,64,22,64,22,64,22,1493,341,85,22,3669" .. "\r\n") luup.sleep(1050) tcp:close() end luup.call_delay("Delay1", 1) function Delay2() --[[HDMI Matrix B2--]] local socket = require("socket") tcp = assert(socket.connect("192.168.255.204", 4998)) tcp:send("sendir,1:3,1,38000,1,69,343,171,21,21,22,21,22,21,22,21,21,21,22,21,22,21,21,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,63,22,21,21,21,22,21,22,21,21,22,21,21,22,63,22,21,22,63,22,63,22,63,22,1528,342,85,22,1528" .. "\r\n") luup.sleep(1050) tcp:close() end luup.call_delay("Delay2", 5)
      Code/Snippet library
    • io.popen: cannot allocate memory error

      therealdb

      I have a script calling io.popen to get the file system partition info, running on the Vera to check for space, and it's getting "cannot allocate memory error".

      Any suggestions, beside doing a luup.reload?

      Code/Snippet library
    • Something smarter than string.format for user-defined patterns?

      therealdb

      In my Virtual HTTP plugin I have patterns that could be specified to dynamically compose HTTP URLs based on current values. So, if you enter
      http://myip/color?v=%s

      it gets replaced with the current color. It's very handy when having more parameters, or if your parameter is in a different position.

      The problem is that from time to time, there are users with legitimate % in their URLs (since it's the escape char in URLs, after all) and this is causing weird behavior or crash.

      So, I want to find something smarter to support both.
      Any hints here is appreciated.

      Code/Snippet library
    • List of plugins available at the Alternative App Store

      A

      The plugins listed here are available via the Alternative App Store. The app store becomes accessible via a new menu item in the Alternative User Interface once configured.

      Both the Alternative User Interface (AltUI) and AltAppStore (AltAppStore) plugins need to be installed on Vera to access the store. With openLuup; this is all "automatically" set up and ready to go as part of the openLuup suite.

      The Alternative App Store can be found here.

      Publishing a plugin in the store is pretty easy. First your plugin code must be available in GitHub. Publish it, using the Publish command in the AltAppStore web page. You need to enter the salient information and it's ready to go.

      Plugin icons can be stored on GitHub eg like so. After a "few days" the raw json describing the plugin appears here.

      Vera 3 users should note the store will not work, as Vera 3 doesn't have the https capability required to access GitHub. However, the apps can always be downloaded from GitHub and manually installed.

      For those just interested in what the store contains; refer to the list below - as of 2021 July 27 there were about 75 plugins available:

      Plugin Comments ABC: Aeratron fans Alternative App Store Built into openLuup ALTHue ALTUI Amcrest Dahua AutoVirtualThermostat BroadLink-Mk2 Canal Plus Not in GitHub Countdown Timer Originated by Futzle DEF: DALI Planet DarkSky Weather Service is rumoured to be closing in late 2021. The "Multi Provider Weather Station" plugin can potentially be used as a replacement. DataYours DelayLight DeusExMachinaII Domoticz Bridge Non functional: needs work check here Domoticz Bridge 2 Originated by 999LV and updated by perhusaas DreamColorESP8266 DreamColorLedRGB Ecobee Edisio Gateway EDS One Wire Server Originated by Chris Jackson EKM metering Emby Interface Enphase Envoy Solar Monitor EventWatcher Ezlo Bridge FritzBox Sensor GHI: Google Calendar 3 Harmony Hub Control Heliotrope Originated by Futzle. openLuup incorporates the same functionality, so this plugin is not required in that casse. Homebridge 2 openLuup HomeWave Push HundredGraphs Logger IKEA Tradfri Image Map Remote Info Viewer For Vera only IPhone Locator IPX800 Irrigation Caddy JKL: KSenia Lares 16 Bridge LuaView MNO: Multi Provider Weather Station Netatmo Network Monitor OpenSprinkler OpenTherm Gateway openWeather PQR: Paradox EVO IP150 web page scrapper Pioneer Receiver Rachio Rainforest Eagle Based on robertmm's work RaZberry (ALPHA) Reactor RGB Controller Rules Engine STU: SiteSensor SMA inverter Smartmeter Reader Solar Meter Sonos Originated by lolomodo and updated by toggledbits. Sony Bravia IP Surveillance Station Remote (BETA) Switchboard Telegram Tesla Car UPS Sensor UPnP Event Proxy OpenWRT only - originated by Futzle VWX: VeraAlexa Virtual HTTP Devices MQTT commands & status are only available with openLuup. http & Lua can be used by Vera and openLuup. Virtual Pronto Remote Virtual Sensor VW CarNet WES Xee YZ: Yamaha RX HTTP Z-Way ZiBlue Gateway ZiGate Gateway
      Code/Snippet library
    • node-red Alexa OpenLuup/Vera voice integration

      Elcid

      Here is a simple integration of OpenLuup/vera device to Alexa via Node-red.

      E1cid/Node-red-Vera E1cid/Node-red-Vera

      Node-red flows for Vera. Contribute to E1cid/Node-red-Vera development by creating an account on GitHub.

      The speed is fast sub 1 second responses.

      Requirements -
      node-red.
      alexa.
      node-red-contrib-amazon-echo(local Hue devices).
      openluup or Vera (or any controller via http requests).

      Capabilities-
      Binary switch.
      dimming switch.
      rgb switch.
      Run scenes.

      Each alexa device node is configured in the topic of the amazon-echo device node -
      (device number#type of switch)
      bnary - 123#binary.
      dimming - 123#dimming.
      rgb - 123#colour (W/D is default 310 to adjust colour temp add value to end e.g. 123#colour#300
      scene - 123#scene#124 (123 on 124 off. 124 can be omitted).

      Enter the ip of your controller in the http request block.
      Just copy code and import into Node-red

      [ { "id": "de7838ac.ebead", "type": "amazon-echo-hub", "z": "8659fc6b.981b4", "port": "8980", "processinput": "0", "discovery": true, "x": 150, "y": 840, "wires": [ [ "cd0ae070.e98378", "a605448.899d8b8", "21ca89ff.b0f6ce" ] ] }, { "id": "a605448.899d8b8", "type": "amazon-echo-device", "z": "8659fc6b.981b4", "name": "bedroom four", "topic": "199#colour", "x": 410, "y": 860, "wires": [ [ "688830f.c57775" ] ] }, { "id": "21ca89ff.b0f6ce", "type": "amazon-echo-device", "z": "8659fc6b.981b4", "name": "app safe", "topic": "164#binary", "x": 390, "y": 900, "wires": [ [ "688830f.c57775" ] ] }, { "id": "cd0ae070.e98378", "type": "amazon-echo-device", "z": "8659fc6b.981b4", "name": "lounge 1", "topic": "8#dimming", "x": 390, "y": 940, "wires": [ [ "688830f.c57775" ] ] }, { "id": "688830f.c57775", "type": "function", "z": "8659fc6b.981b4", "name": "", "func": "let types = {\n \"dimming\":[\"urn:upnp-org:serviceId:Dimming1\",\"SetLoadLevelTarget\",\"newLoadlevelTarget\"],\n \"binary\":[\"urn:upnp-org:serviceId:SwitchPower1\",\"SetTarget\",\"newTargetValue\"],\n \"scene\":[\"urn:micasaverde-com:serviceId:HomeAutomationGateway1\",\"RunScene\",\"SceneNum\"],\n \"colour\":[\"urn:micasaverde-com:serviceId:Color1\",{\"tt\":\"SetColor\",\"hs\":\"SetColorRGB\",\"ct\":\"SetColorTemp\"},{\"tt\":\"newColorTarget\",\"hs\":\"newColorRGBTarget\",\"ct\":\"newColorTempTarget\"}] \t\n}\nfunction binaryPayload(device, type, turnOn, payload) {\n payload.id = \"action\";\n payload.serviceId = type[0];\n payload.DeviceNum = device;\n payload.action = type[1];\n payload[type[2]] = (turnOn === true ? 1 : 0);\n payload.message = payload[type[2]];\nreturn payload;\n}\n\nfunction dimmingPayload(device, type, level, payload) {\n payload.id = \"action\";\n payload.serviceId = type[0];\n payload.DeviceNum = device;\n payload.action = type[1];\n payload[type[2]] = level;\n payload.message = level;\nreturn payload;\n}\nfunction scenePayload(device, type, turnOn, payload) {\n payload.id = \"action\";\n payload.serviceId = type[0];\n payload.action = type[1];\n payload[type[2]] = (turnOn === true ? device[0] : (device[2] || device[0]));\n payload.message =\"Run Scene \" + payload[type[2]];\nreturn payload;\n}\n\nfunction rgbPayload(device, types, msg, payload) { \n if(msg.on === true && msg.meta.changes.on === false && msg.meta[\"input\"].on === true){\n payload = binaryPayload(device[0], types[\"binary\"], msg.on, {});\n }else if (msg.meta.changes.percentage && msg.on === true){\n payload = dimmingPayload(device[0], types[\"dimming\"], msg.percentage, {});\n }else if (msg.on === true && msg.colormode === \"hs\"){\n payload.id = \"action\";\n payload.serviceId = types[\"colour\"][0];\n payload.DeviceNum = device[0];\n payload.action = types[\"colour\"][1][\"hs\"];\n payload[types[\"colour\"][2][\"hs\"]] = msg.rgb.join(\",\");\n payload.message = msg.rgb.join(\",\");\n }else if (msg.on === true && msg.colormode === \"ct\"){\n let diff = msg.ct - (Number(device[2]) || 310);\n msg.ct = (diff < 0) ? \"D\" + Math.min(Math.abs(diff * 1.7),255).toFixed() : \"W\" + Math.abs(Math.min((diff * 1.7),255) - 255).toFixed();\n payload.id = \"action\";\n payload.serviceId = types[\"colour\"][0];\n payload.DeviceNum = device[0];\n payload.action = types[\"colour\"][1][\"ct\"];\n payload[types[\"colour\"][2][\"ct\"]] = msg.ct;\n payload.message = msg.ct;\n }\nreturn payload;\n}\n\nmsg.topic = msg.topic.split(\"#\").map(Function.prototype.call, String.prototype.trim);\nmsg.hold = msg.payload;\nmsg.payload = {};\nlet type = msg.topic[1] || \"binary\";\nif(msg.topic[1] === \"scene\"){\n msg.payload = scenePayload(msg.topic, types[\"scene\"], msg.on, {});\n}else if (msg.topic[1] === \"binary\" || msg.percentage === 0 || msg.on === false){\n msg.payload = binaryPayload(msg.topic[0], types[\"binary\"], msg.on, {});\n}else if(msg.topic[1] ===\"dimming\"){\n msg.payload = dimmingPayload(msg.topic[0], types[\"dimming\"], msg.percentage, {});\n}else if (msg.topic[1] === \"colour\"){\n msg.payload = rgbPayload(msg.topic, types, msg, {});\n}\nlet error = [\"green\", msg.topic[1] + \" | \" + msg.topic[0], msg.payload.message];\ndelete msg.payload.message;\nif (Object.keys(msg.payload).length < 1){\n error[0] =\"red\";\n error[2] =\"failed to create payload\";\n}\nnode.status({\"fill\": error[0],\"shape\":\"ring\",\"text\": error[1] + \" | \" + error[2]});\n\nreturn msg;\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 590, "y": 940, "wires": [ [ "680d28ae.8a163" ] ] }, { "id": "680d28ae.8a163", "type": "http request", "z": "8659fc6b.981b4", "name": "Get request", "method": "GET", "ret": "txt", "paytoqs": "query", "url": "http://192.168.1.11:3480/data_request", "tls": "", "persist": false, "proxy": "", "authType": "", "x": 760, "y": 1000, "wires": [ [ "cb471442.5d60c8" ] ] } ]
      Code/Snippet library
    • Low battery alerts

      akbooer

      Moved from https://smarthome.community/topic/56/disable-vera-zwave-device-polling-at-the-device-level where you'll find the referenced code.

      Code/Snippet library
    • How to parse JSON path in LUA?

      therealdb

      Hi,

      I'm working on new features for my Virtual Devices Plug-in. One of the things I want to add is the ability to poll an endpoint to get power consumption.

      So, I want to store the URL and the JSON path in a variable, but I'm confused on how to dynamically parse JSON paths in LUA.

      I have something like this in a string variable

      data.meters[1].power

      and I have to extract the corresponding value from the JSON I got over HTTP.

      Any suggestion is very appreciated. Thanks.

      Code/Snippet library
    • Humidity/Mold sensor

      therealdb

      I'm trying to write a sensor similar to this:

      home-assistant/core home-assistant/core

      :house_with_garden: Open source home automation that puts local control and privacy first - home-assistant/core

      I've already translated it to LUA, but I'm getting strange values. Maybe it's because it's not that cool yet.

      Anyone has already done something similar? I have outside and inside sensors and I want to run my de-humidifier based on certain conditions. I want to avoid condensation on the large windows. Last year I ran it based on a fixed threshold, but I want to optimize this if possible.

      Code/Snippet library
    For those who registered but didn't received the confirmation email, please send an email to support@smarthome.community with the email you used

    Humidity/Mold sensor

    Code/Snippet library
    1
    1
    49
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • therealdb
      therealdb last edited by

      I'm trying to write a sensor similar to this:

      home-assistant/core

      home-assistant/core

      :house_with_garden: Open source home automation that puts local control and privacy first - home-assistant/core

      I've already translated it to LUA, but I'm getting strange values. Maybe it's because it's not that cool yet.

      Anyone has already done something similar? I have outside and inside sensors and I want to run my de-humidifier based on certain conditions. I want to avoid condensation on the large windows. Last year I ran it based on a fixed threshold, but I want to optimize this if possible.

      --
      Vera+MQTT+HomeAssistant+my own framework all orchestrated via MSR
      70+ Zwave Devices, a bunch of ZigBee light strips and a lot of code

      My Luup Plug-ins => https://github.com/dbochicchio/vera

      1 Reply Last reply Reply Quote 0
      • First post
        Last post

      Welcome. If you’d like to participate in the discussion, rather than just read, then you can join the forum. As a member, you can interact with others here to share your experience and ask the questions you need answered.

      Powered by NodeBB | Contributors
      Hosted freely by PointPub Media Communications Inc. | Contact us