-
I'm moving the discussion on this out of the Mantis PR #178 for the benefit of all/documentation, and also because it's easier to type and format here.
@LibraSun wrote in that PR:
I'm 99% certain you'll explain this one away as "expected" but I naively believed it would yield different results:
In an expression defined by:
a=[1,2,3],
each i in a:
shift(a)
// result (array) [1,2] (unexpected
// expected [1,2,3]This has me thinking that 'each' is leaving items on the table, as I tried unsuccessfully pointing out above.
The issue here is that your expression shift(a) is modifying the iteration subject array in place. Basically, here are the iteration steps that are run, starting with a=[1,2,3]
First iteration: a=[1,2,3]; the local i is assigned the first array element 1, but it is not used in the expression. The expression shift(a) results in 1 and causes a to be reduced to [2,3] (the first element is shifted off and becomes the result). Since this is the last value in the expression, 1 is added to the each result array. Second iteration: a is now [2,3] because the previous iteration modified it. So i is assigned 3, because the iteration is on the second element/iteration through the array, but i is not used in the expression. The shift(a) causes a to be reduced to [3] and its return value is 2, so the value 2 is added to the iteration result array. Third iteration: a is now [3], and we are on the third iteration, but the iteration index of 3 (third iteration) is now off the end of the array (only 1 element long), so iteration stops.The result of this each is therefore [1,2] because those are two values that were shifted out, and a is left at [3] because there was no third run of shift() to remove it.
As I said in the PR, modifying an array you are iterating through can be dangerous and confusing in many languages, because iterators keep state during iteration, and some operations you can do inside the iteration can and will invalidate that state in some way. In Lua on Vera, this often leads to deadlocks and crashes so bad that the box reboots, not just a Luup reload. It's a Bad Idea, and programmers who know are very wary of doing this type of thing in any language unless they are certain of the side-effects/lack of side-effects.
Your additional example:
a=[1,2,3], // The array 'a' is [1,2,3]
a=unshift(a,0), // The array 'a' is [0,1,2,3]
a=push(a,4), // The array 'a' is [0,1,2,3,4]
each i in a: // Iterating over the 5 elements of 'a'
shift(a) // Take the first element of 'a' and append it to result array [ ]
// result [0,1,2] (unexpected)
// and array 'a' is now [3,4]! (also unexpected)Also correct result. All of the gyrations before the each are not relevant to behavior here. At the start of the each, the array is [0,1,2,3,4] (5 elements). Iterations:
a=[0,1,2,3,4], i=0, shift(a) returns 0 and modifies a to [1,2,3,4]; the each result array is now [0] a=[1,2,3,4], i=2, shift(a) returns 1 and modifies a to [2,3,4]; the each result array is now [0,1] a=[2,3,4], i=4, shift(a) returns 2 and modifies a to [3,4]; the each result array is now [0,1,2] Iteration stops because the iteration index/step is 4, but there remain only two elements in a=[3,4] (we're off the end of the array).So the each result is [0,1,2] and a is left with [3,4] and this is correct operation.
Key points:
each keeps state during the iteration (as most iterators do) about the subject of the iteration; if the subject changes in a way that affects the state, unexpected results may occur; The functions push(), pop(), shift() and unshift() modify the array in place. If you say b=shift(a) you get a value in b and a modified (shorter) a. -
Has anyone successfully incorporated incoming call(er) information** within an automation workflow?
I'm talking about having Alexa speak out the name and/or phone number of a caller, or activating a routine/scene based on that info.
Always been a dream of mine. Wouldn't know how to achieve it! Do they make an Ethernet/WiFi-connected CallerID box?
**from a LANDLINE, not a MOBILE PHONE (although in the case of my Google Voice #, both lines ring, and if my smartphone is home and turned on, I could see invoking Tasker somehow)
REFERENCES:
NCID - Network Caller ID
[Please file under proper category, as you see fit]
-
-
-
Quite a number of years ago I set up a few Arduino sensors that reported temperature to my VeraLite running UI5. I did this with MySensors, a quite nice community based platform.
I discontinued this mostly because that the combination of a rather flaky Vera and that the Vera when rebooting lost the USB connected gateway.Some time ago I started to look at this again, but this time using ESP8266’s and Tasmota. I think the credit for this partially is the plugin for Shelly and Tasmota that @therealdb has written, even though I have still to use the plugin. The other reason for reentering into this area is that my electrical supplier is replacing the electrical meters for a new smart meter. Today I use a blink meter from Effergy, but the new meter will have a port for reading out data. This also led me to Tasmota, there seems to be a functioning solution for this.
I must say that Tasmota is brilliant! Support for all kind of devices and sensors and super easy to use, also for multi-sensors, OTA update, good documentation etc. You can get parts on ebay etc quite cheap. It has also so far been very stable. You can also very easily adjust the sensors readout, e.g. TempOffset -1.5 gives an offset of -1.5 degrees.
I have put together sensors for temperature and humidity for use in the garage, the outhouse, on the attic etc. I have tested DHT22, DS1820B, BME280 and BH1750 so far and they all work without issues. The latter two I installed in an outdoor enclosure to use as a simple weather station reporting temperature, humidity, air pressure and light level.
I also got a MH-Z19B CO2 meter for testing to monitor the indoor CO2 levels. The initial feeling is that it does what it should.
In general I have pretty good wifi coverage with a few Unifi access points. One of the sensors is in a building some 25 meters from the house where the wifi is not that strong, but the NodeMCU has no problem with this. Quite impressive and a good addition to Z-wave for that kind of location.
Not owning a 3D printer I have had to resort to purchased enclosures and the old Dremel. 😊
For the CO2 sensor I put it in an old smoke detector enclosure for now.
I am sure that there are a lot of talent here that can do much better with a 3D printer!
CO2meter1.jpgYou can get the data from the Tasmota devices into OpenLuup in a number of ways. The obvious way is via MQTT. I have still to set this up at some point in time. The second way is to use the excellent SiteSensor plugin. I tested this but had some problems with reporting stopping after a few days for some reason. I probably got something wrong in the setup. The third option, that I currently use is via adding rules to each sensor. You can quite easily add rules for reporting data to a virtual sensor in OpenLuup, e.g:
Rule1 ON tele-AM2301#Temperature DO Var1 %value% ENDON ON tele-AM2301#Temperature DO WebSend [IP_adress:3480]/data_request?id=lu_action&DeviceNum=65&id=variableset&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature&Value=%Var1% ENDON
With TelePeriod you can change the polling interval as required.
This method I think could be super useful for reporting back e.g. switch status from a Tasmota node much like I understand Shelly can do.
Some resources and notes I made on the way:
Using Tazmotizer to flash the ESP’s is very easy
List of supported sensors including how to connect, commands etc
A good pinout reference for ESP8266 variants
Tasmota rules documentation
Most sensors are either “Generic (0)” or “Generic (18)”, check for each sensor type what to use
For I2C sensors e.g. BME280 one must use tasmota-sensors.bin
For the MH-Z19B I had to flash the ESP before attaching the sensor, this could be a good practice always
Use the following url for the query in SiteSensor:
http://IP_address/cm?cmnd=Status%2010This became a rather long post but hopefully it can be of some use.
//ArcherS -
Just thought i'd mention it, as I've walked into it multiple times when editing rules:
dbc9e2c8-887e-46bd-8e3c-1364eb99bb03-image.pngWhen I make/edit rules, i'm used to pressing "save" through the process, and when I do that, theres only the red one left to press. It does make sense, as its already saved, but I'll stop and think one more time when it says w/o saving.
In my head, a exit button which causes a pop-up warning if changes are not saved makes more sense - like in vera reactor.Feel free to discard the idea, its just something to get used to mabye. 🙂
-
Followers will be aware of the problems I had setting up MSR, so it won;t come as a surprise that now I have problems Upgrading to the latest version. (How much I wish for a "Click to Upgrade" Button.....)
I've been stuck on this for 6 days and am ready to throw in all into the to hard basket, surely HA shouldn't be this problematic?
There, I've said it now I feel better....
So what's the problem, I can upload the file using WINSCP but no matter what I've tried it won't un-tar and over write the existing files in the Reactor Directory.
I receive the following error message which may as well be written in Martian 🙂 in my case.
Command 'tar -xz --directory="reactor" -f "reactor-0.1-21101-0db64f0-generic.tar.gz"'
failed with return code 2 and error message
tar: reactor: Cannot mkdir: Permission denied
tar: reactor: Cannot mkdir: Permission denied
tar: reactor/INSTALL.md: Cannot open: No such file or directory
tar: reactor: Cannot mkdir: Permission denied
tar: reactor/LICENSE.md: Cannot open: No such file or directory
tar: reactor: Cannot mkdir: Permission denied
cut for sanity sake....This goes on for ad infinitum for every file.
I tried with both users, no change, can anyone decipher this and explain why WINSCP won't untar the file?
-
-
So my house only has 2 wire lighting and due to the way it's been installed, plus our flooring options, conversion to 3 wire is not practicable in any case that I want (hope I got those the right way around!)
So it's only dimmer units for me (boo hiss!) even though I'm only ever using them as on and off.So what's going to happen if I put a non-dimmable LED bulb on a dimmer? is the dimmer going to get upset or will the bulb just come on at 100%? I'm never going to ask the bulb to actually dim, I only want on or off.
Thoughts?
Cheers
C
-
Hi all
I’ve recently started to build out my own ‘Homer’ dashboard (https://github.com/bastienwirtz/homer) and I must admit I really like what it’s given me.
Thinking about future use-cases. I can see potential for this being an alternative (albeit simple ) UI for Vera/OpenLuup..
Is anyone else using Homer ?
-
How can I do this?
The topic in the instructions is very limited.Other Controllers
Other controllers that you may find as add-ins will each have their own specific configuration instructions. Please refer to their accompanying documentation.What information should I be looking for?
I've tried port 1880 which is used for node-red, assuming that this is a listening port - no go. Really not sure how to go about this as everything I do is mostly trial & error.
BTW, I added my Vera Lite into the mix successfully, HS4 would make it a trifecta!
-
Latest Vera Ecobee Plugin:
rafale77/vera-ecobee rafale77/vera-ecobeeVera Plugin for ecobee Thermostat. Contribute to rafale77/vera-ecobee development by creating an account on GitHub.
-
First I want to say thank you to this group. You have given me ideas and help along the HA path for a long time.
I'm an old Vera user and planning to decouple from MIOS cloud now or after 7.32 but I'm stuck at how to push messages out.
I'm using Reactor and Scenes for Vera native messaging. What's a good solution going forward?Also want to mention that after reading the Decoupling document I have built a NTP GPS server on a Pi3B and enjoyed learning more about Linux along the way. I have it stabilized after learning 100 different ways.
Thanks
-
Hi Everyone,
In the Vera Reactor logic, I used to use the operator "updates" in a lock condition.
If I entered the door and the code used was "Mike," it would hold the condition true indefinitely because "Mike" was the last stored value. Since it is held indefinitely, setting the condition to pulsed would not allow the condition to fire again because it never went false. If I entered a different code, the condition would go false, then entering "Mike" again would cause the condition to go true.
I did this using the operator "updates" in an AND condition along with the lock code. The code condition would stay true with "Mike," and when "Mike" is entered consecutively, the "updates" condition will go true each time, and then the whole condition would go true, triggering the action.
Since "updates" no longer appears to be an operator, how would I do this in the new logic? I think I remember a discussion about this, but I searched and can't seem to find it.
I'm not a programmer, so I am probably missing the easy way to do this.
-
Posted this in Vera forum with no response:
Seeing this in reactor UI:
A newer version of the device information database is available. Please use the update function on the Tools tab to get it. This process is quick and does not require a Luup reload or browser refresh–you can immediately come back here and go right back to work! The new version is 865.877, and you are currently using 557.352…Hit update in Tools and get an error: “The update could not be retrieved. If this problem persists, consult the documentation.”
Looked through logs and not seeing anything specific. You have a keyword I should search for?
-
I have created a Global Reaction with this LUA code for my Vera to run.
However when I run the Reaction nothing happens. I can't see anything in the log file either about this rules ID number.
If I run the same LUA code on Vera in the test window it works OK.
OR any other suggestions how I can set this up in a global Reaction (Scene) in MSR ?
Instead I could use the VeraScenes.lua file in the Vera startup library, but I am wondering why I can't just paste the LUA code directly in to the MSR rule.
Thanks
local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 419) --Status of Safe to Arm virtual switch if status == "0" then --Safe to Arm luup.inet.wget("http://SOME-HTTP-REQUEST") luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","SetHouseMode", {Mode = 2}, 0) --Set House Mode to Away luup.inet.wget('SOME-HTTP-REQUEST' ,5); else --Not Safe to Arm luup.inet.wget("SOME-HTTP-REQUEST") luup.inet.wget('SOME-HTTP-REQUEST' ,5); end -
For MSR users with SiteSensor still installed back on Vera, you might want to consider letting MSR take over those duties. Here's a quick run-down of how I imported one of my SiteSensor recipes into a Rule on MSR, using OpenWeather API* as an example.
STEP 1: Copy the Basics from Vera
(a) Go to your Vera > Devices, locate SiteSensor (the main instance, not one of its children devices) and click ► for details then click SETTINGS.
(b) Copy and paste (into Notepad or other text editor) the Request URL along with each of the defined expressions.STEP 2: Create a Rule on MSR
(c) Jump into Rule Sets and click "Create Rule". Click its title to rename the rule 'OpenWeather (API)" and click 'Rename'.
(d) Decide on appropriate Triggers (in my case, it's an OR group that includes an [INTERVAL] set to "Every 3 hours" plus a few [ENTITY ATTRIBUTE] entries reacting to things like entering/leaving home, waking up, etc.).
(e) In Set Reacion, create an [HTTP REQUEST] > [GET] action.
(f) Paste your old "Request URL" into the "Request URL" box.FYI GET calls to OpenWeather API* take the form:
http://api.openweathermap.org/data/2.5/weather?zip=<your_ZIP_code>&id=<your_Wx_ID>&appid=<app-id>&units=imperial(g) Create four new blank Expressions (name them openWx, Tx, Hx and Rx).
(h) Click SAVE & EXITSTEP 3: Process the Response
(i) Re-open rule "OpenWeather (API)" by clicking the 'Edit' icon.
(j) Within the [HTTP REQUEST] action, assign "Capture response to:" ► openWx
(k) Down in Expressions, click "[+]Add Expresssion" then enter the following:
Tx := round(openWx.main.temp,1)
// yields current outdoor temperature
Hx := round(openWx.main.humidity)
// yields current humidity conditions
Rx := openWx.rain ? ( openWx.rain['3h'] ? openWx.rain['3h'] : 0) : 0
// yields predicted rainfall, if present; otherwise 0
(l) Click SAVE & EXIT. Enjoy!Naturally, your specific needs and workflow will differ from the one I've outlined here. For instance, you may wish to explore the contents of the JSON object in openWx for additional data of interest to you, and define variables to match.
My goal here has been to illustrate some key concepts needed for moving from SiteSensor over to MSR:
Some syntax is the same, such as dot notation for object.item.access; Other syntax has changed, such as the use of ternary A ? B : C in place of IF (A, B, C); Manually setting an [INTERVAL] in lieu of SiteSensor's timed schedule;Pro tip: If your workflow demands that other Rules react to the output of the "OpenWeather (API)" rule, then be sure to create all of the aforementioned Expressions under "Global Expressions" instead, so they become accessible across all Rule Sets.
Once the transition is complete, you can either DISARM SiteSensor on Vera or remove it entirely with "Remove Device" (which will automatically remove all of its child devices).
*Additional reading:
OpenWeather API : https://openweathermap.org/api
FREE SUBSCRIPTION REQUIRED TO USE THIS SERVICEPRO TIP: See below for optimal way to incorporate OpenWeatherMap into your MSR workflow(s), by enabling the service directly in the reactor.yaml config file.
-
-
In my Vera config I have two SiteSensors (one for Ambient Wx, one for OpenWxMap) that point to two unique Reactor devices for controlling HVAC in my home. This is done for redundancy - if the Ambient API drops it returns zero data which then triggers a standalone Master API Reactor device to flip on the OWM SiteSensor and corresponding HVAC Reactor device to continue controlling the house conditions.
Once the Ambient API returns to available the Master API Reactor device flips back to the Ambient SiteSensor and corresponding HVAC Reactor device, turning OFF the SiteSensor for OWM to save on API calls.
I've been able to duplicate one half of this, including the Master API role, in MSR. But... here's the tricky part... I can't turn "off" the MSR Rule Sets for the OWM version. As such, HVAC is sent conflicting data and doesn't know what to do.
Before I go alls deep into explaining how all of this currently works, am I missing something somewhere that would allow me to trigger the on/off of MSR Rule Sets?
-