-
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=%sit 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. -
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.
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 2020 Dec 19 there were 69 plugins available:
ALTHue
ALTUI
Aeratron fans
Amcrest Dahua
AutoVirtualThermostat
BroadLink-Mk2
Countdown Timer - originated by Futzle
DALI Planet
DarkSky Weather
DataYours
DelayLight
DeusExMachina
Domoticz Bridge
DreamColorLedRGB
EDS One Wire Server - originated by Chris Jackson
EKM metering
Ecobee
Emby Interface
Enphase Envoy Solar Monitor
EventWatcher
Ezlo Bridge
FritzBox Sensor
Google Calendar 3
Harmony Hub Control
Heliotrope - originated by Futzle
HundredGraphs Logger
IKEA Tradfri
IPX800
IPhone Locator
Image Map Remote
Info Viewer for Vera only
Irrigation Caddy
KSenia Lares 16 Bridge
LuaView
Netatmo
Network Monitor
OpenSprinkler
OpenTherm Gateway
openWeather
Paradox EVO IP150 web page scrapper
Pioneer Receiver
RGB Controller
RaZberry (ALPHA)
Rachio
Rainforest Eagle - based on robertmm's work.
Reactor
Rules Engine
SMA inverter
SiteSensor
Smartmeter Reader
Solar Meter
Sony Bravia IP
Surveillance Station Remote (BETA)
Switchboard
Telegram
Tesla Car
UPS Sensor
UPnP Event Proxy - OpenWRT only - originated by Futzle
VW CarNet
VeraAlexa
Virtual HTTP Devices
Virtual Pronto Remote
Virtual Sensor
WES
Xee
Yamaha RX HTTP
Z-Way
ZiBlue Gateway
ZiGate Gateway -
Here is a simple integration of OpenLuup/vera device to Alexa via Node-red.
E1cid/Node-red-Vera E1cid/Node-red-VeraNode-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.
[ { "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" ] ] } ]
Just copy code and import into Node-red -
Moved from https://smarthome.community/topic/56/disable-vera-zwave-device-polling-at-the-device-level where you'll find the referenced code.
-
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}, 666Very cool indeed 🙂
-
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].powerand I have to extract the corresponding value from the JSON I got over HTTP.
Any suggestion is very appreciated. Thanks.
-
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.
-
I'm trying to implement the support for http_async in my Virtual Devices plugins. From my tests, Vera's UI seems less busy, but I want to automatically detect if it's installed. Right now I'm using a code like this one:
if pcall(require, "http_async") then else ... endbut I'm not sure it's the best way to do it. Any one? @akbooer? Thanks!
-
I have finally integrated my new motorized (blackout) blinds in the home office, since I'm planning to mainly work from home at least since the end of the year.
I'm quite satisfied, since I made them completely automatic, but I noticed that I have two problems:
rainy days: I have a rain sensor for the exterior sunscreens, so I can think about moving the interior ones as well moving season: while moving them to a middle position for the night is good now at 30 minutes before sunset, I'm not sure it will be OK in autumn or winter.So, I was thinking about adding some logic linked to sun position, or a light sensor device.
Any hints, before re-inventing the wheel? Thanks. -
I’m sure there is a better/more polished way to do this, but this remains one of my go to report urls on Vera.
-- http://forum.micasaverde.com/index.php?topic=52025.msg334246#msg334246 local d, n local file = io.open("/www/sb.html", "w") file:write("<head> <meta http-equiv='refresh' content='30' /> </head>\n") file:write("<style>.custom { font-size: 1em; font-family: Gill Sans Extrabold, sans-serif; padding:5px; border-collapse: collapse; border: 1px solid black; }</style><table class=custom><tr class=custom><th class=custom>Security Sensor</th><th class=custom>Last Tripped</th></tr>\n") local tt = {} for n,d in pairs(luup.devices) do if d.category_num == 4 then -- local lasttrip = tonumber(luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "LastTrip", n) or 0,10) local lasttrip = tonumber(luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "LastTrip", n) or os.time()) local timeString = os.date(" %Y/%m/%d - %X", lasttrip) if lasttrip > 0 then table.insert(tt, { devnum=n, last=lasttrip, ltime=timeString }) end end end table.sort(tt, function(a,b) return a.last > b.last end) -- sort highest to lowest for n,d in ipairs(tt) do file:write("<tr class=custom><td class=custom>" .. luup.devices[d.devnum].description .. "</td><td class=custom>".. d.ltime .. "</td></tr>\n") print ( d.ltime .. ' : ' .. luup.devices[d.devnum].description .. " Sensor was last tripped") end file:write("</table>\n") file:close() -
Responding to @PrincessClevage's request through a PM,
I am posting my Roomba integration:
First of course you will have to have Home Assistant installed and running. I will not be covering that.
Home Assistant iRobot Roomba iRobot Roomba
Then you will need to add and configure the roomba component which can now be done through the UI
Instructions on how to integrate your Wi-Fi enabled Roomba and Braava within Home Assistant.
I won't cover this either.
Next, on Vera or openLuup, I used a sitesensor with the following configuration:
Screen Shot 2020-07-10 at 10.15.55.png
I also have a preset function loaded in my startup lua to directly send post commands to my home assistant instance which I posted here:
https://smarthome.community/topic/39/lua-function-in-openluup-startup-lua-to-send-async-command-to-home-assistant-apiwhich then enables me to create a variety of scenes triggered by the site sensor: For example disarming the site sensor docks the roomba by creating a variable watch on the arm status of the site sensor and then run this code:
Screen Shot 2020-07-10 at 10.22.19.png
Likewise I can get it to start cleaning from openLuup through a similar scene
Screen Shot 2020-07-10 at 10.23.02.png
And you can let wild of your creativity from there... I have an identical integration for the xiaomi robot and am tuning the vacuum noise according to whether I am on the same floor while the robot is cleaning...
-
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 reloadThe devices are created (look at line 357/410), but when I call luup.chdev.sync, they got deleted. Any hints? Thanks
-
With all the acquisition of Dark Sky by Apple in the plans, I thought I would share my rain sensor setting which is used as input for my irrigation system:
Install @toggledbits site sensor Register for a free tier account from http://weatherbit.io an pick up the API key the url I use is using forecast over 2 days (replace with your coordinates and key): https://api.weatherbit.io/v2.0/forecast/daily?lat=**yourlat**&lon=**yourlong**&key=**yourkey**&days=2 The trip expression is as follows as I also pull a variable from within the sensor variable for the calculation: tonumber(response.data[1].precip)+ tonumber(response. data[2].precip) + tonumber(getstate( 67, "urn:toggledbits-com:serviceId:SiteSensor1", "PastRain"))> 5 For display I also pull these value expressions: "Total Rain "+(tonumber(response.data[1].precip)+ tonumber(response.data[2].precip) + tonumber(getstate( 67, "urn:toggledbits-com:serviceId:SiteSensor1", "PastRain")))+" mm" "Tomorrow "+response.data[2].precip+" mm" "Today Probability "+response.data[1].pop+"%" "Tomorrow Probability "+response.data[2].pop+"%" response.data[1].precip "Today "+response.data[1].precip+" mm" "Accumulated "+getstate( 67, "urn:toggledbits-com:serviceId:SiteSensor1", "PastRain") Add a time based scene with the following lua code to record the past day rain accumulation every night at the time of your choosing (I use 23:00). Replace the sensorid variable with your sensor id) local sensorid=**yoursitesensorid** local siteid= "urn:toggledbits-com:serviceId:SiteSensor1" local current =luup.variable_get(siteid,"Value5", sensorid) luup.variable_set(siteid,"PastRain", current, sensorid)With this, my yard irrigation only turns on when the sensor is not tripped... meaning less than 5mm of water is accumulating across 3 days (yesterday, today and tomorrow). Adjustments in value can easily be made.
-
function POSTHA(path, payload, token) local async = require "http_async" local ltn12 = require("ltn12") local resp = {} async.request( { url = path, method = "POST", headers = {["Content-Type"] = "application/json", ["Content-Length"] = payload:len(), ["Authorization"] = token, }, source = ltn12.source.string(payload), sink = ltn12.sink.table(resp) }, function() end) end
example of usage:
local hass_token = "*********" local path = "http://hass_ip:8123/api/services/vacuum/turn_off" local payload = [[{"entity_id": "vacuum.upstairs_roomba"}]] POSTHA(path, payload, hass_token)
define the token obtained from home assistant in the scene lua or startup lua: -
Parameters of devices can be set through the api using this URL
YOURIP:8083/ZWaveAPI/Run/devices[DEVICE#].instances[0].Configuration.Set(PARAMETER,PARAMETER_VALUE,size=PARAMETER_SIZE)
Replace:
YOURIP with the IP of Z-way for example 192.168.1.2.
DEVICE# with the Z-way device # of the devices parameter you want to change
Parameter with the parameter # you want to change
VALUE with the Parameter value
PARAMETER_SIZE with the size of the parameter (should be 1, 2, or 4)An example to change device 51's parameter 3 to a value of 1 with a size of 1:
192.168.1.2:8083/ZWaveAPI/Run/devices[51].instances[0].Configuration.Set(3,1,size=1)
To run it in Luup code
local status, result = luup.inet.wget("192.168.1.2:8083/ZWaveAPI/Run/devices[51].instances[0].Configuration.Set(3,1,size=1)", 5) -
-
for k, v in pairs(luup.devices) do local var= luup.variable_get("urn:micasaverde-com:serviceId:ZWaveDevice1", "PollSettings",k) local bat = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k) if var ~= nil and v.device_num_parent== 1 and bat == nil then if var ~= 0 then luup.variable_set("urn:micasaverde-com:serviceId:ZWaveDevice1", "PollSettings", "0", k) luup.variable_set("urn:micasaverde-com:serviceId:ZWaveDevice1", "PollNoReply", "0", k) end end end
-
A little function to match a device based on, room and/or device name, including wildcard.
function matchDev (pattern, rooms) local wanted = {} for _, r in ipairs ((type(rooms) == "table") and rooms or {rooms}) do wanted[r] = r end return function(_, last) while true do local d last,d = next( luup.devices, last ) if not last or (d.description:match( pattern ) and (not rooms or wanted[d.room_num])) then return last,d end end end endExample #1: Lock all Deadbolt in any room:
for n,d in Tools.matchDev('^TDB%-') do -- All doors lock luup.call_action ("urn:micasaverde-com:serviceId:DoorLock1", "SetTarget", {["newTargetValue"] = 1}, n) --luup.sleep (200) endExample #2: Switch OFF all binary light in specific room
for n,d in Tools.matchDev('^L%-',{13,16,21,6,5,4,24}) do luup.call_action ("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {["newTargetValue"] = 0}, n) --luup.sleep (200) endI'm using a lot of these lua code for scene like "Switching to sleep mode"
-
-- https request json body -- Enable potentially unsafe lua code in, user account - security local https = require "ssl.https" local http = require "socket.http" local ltn12 = require "ltn12" local json = require "dkjson" local payload = {{"test", "test", null, 0}} --payload to be sent local request_body = { secret = "1.KAddd87s8s8FasL7-ze4KG_p5hrVg4Kee1-t3vnwGFhI=", to = "test@gmail.com", device = null, priority = "high", payload = payload } --the json body local response_body = {} request_body = json.encode(request_body) local r, c, h, s = https.request { url = 'https://llamalab.com/automate/cloud/message', method = 'POST', headers = { ["Content-Type"] = "application/json", ["Content-Length"] = string.len(request_body) }, source = ltn12.source.string(request_body), sink = ltn12.sink.table(response_body) }
How to parse JSON path in LUA?
-
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.
-
Tricky.
If I understand correctly, this snippet of code may do what you need.
I have a string variable with that text in it, and a structure which includes that field (and others.) The code extracts the value of the given field...
local text = "data.meters[1].power" local struct = { foo = 42, data = { meters = { {power = math.pi}, {energy = 123}, 3, 4, 5 }, litres = 7, }, bung = "qwerty" } -- CODE STARTS HERE! local x = struct for field in text: gmatch "[^%.%[%]]+" do x = x[tonumber(field) or field] end print(x)
giving:
3.1415926535898
-
Thanks @akbooer!
It's now implemented in v 2.1 on https://github.com/dbochicchio/Vera-VirtualDevices/