Variables vs Expressions - and what you can do with it

Since I’m just experimenting with it a bit, I thought I’d start a thread about it. There doesn’t seem to be any instructions/help for this (online help in the web frontend would be great). So let’s try to find out what you put where, what you can currently do with it and what you should modify to make better use of it.

Let’s start with the variables:

First you can choose between the variable types. As is usual with programming languages, you have to decide on a format such as Integer (integer values), Float (with decimal places), Boolean (True/False), and so on.

The variable now gets a name and a value (according to the selected format). What I noticed in this regard is that you can no longer change the name once it has been saved. I don’t know whether that’s intentional or whether it makes sense. I would imagine that it makes sense for the name to be fixed when using this variable in LUA scripts, as these no longer work after changing the name. But is this actually the scope of the variable at this point? Presumably the purpose of the variable definition in the web frontend is that you don’t have to write a LUA script yourself. If you write a LUA script yourself, you will probably write the variables directly into the script. However, if you use the variables in MeshBots, the name could be renamed automatically (this also works for device names).

Now the question is, what do I do with these variables?
These variables can be used as triggers, for example as a comparison value:

But why should you use a variable at this point instead of entering the value directly? One of the advantages would be, for example, if this variable was used in several MeshBots. If you now want to change this value, you don’t need to adjust it in all MeshBots, just change the variable.

Unfortunately, it is not yet possible to use variables in actions.

Now let’s move on to the expressions. Here too, a name is defined which cannot then be changed:

In contrast to variables, there is no data format to choose from. The expression is filled with data from the field “Please enter a valid LUA code with return statement”. It is expected that a value will be read out using a LUA code line. Practically, you can directly choose a device with the appropriate capability. Let’s take a thermostat with the current setpoint heating as an example:

After clicking on the Add Reference button, the following code is inserted:
image

But with this line you get an error message. The term “return” is still missing. Maybe this should also be inserted automatically when you add the device to the script.

With this you now get both the value and the unit in the expression:
image

In some cases it makes sense to leave out the unit, for example if you want to calculate values with different units. Then add the characters “.value” to the end of the script. And you get an expression without units:
image

Here you can also easily insert calculations of values.

Average values from multiple devices:
image

Or increase a value by a fixed value:
image

You can now use these expressions in the triggers of the MeshBots like you would with the variables:

Unfortunately, also the expressions cannot currently be used in the actions.

Now it would be interesting to know whether and for what you use variables and expressions.

The following examples spontaneously come to mind:

  • Global variables used in many meshbots, all of which should work with the same values. If you make changes, you only have to adjust the value in one place. It would now make sense if these variables could also be filled dynamically using a MeshBot Action.

  • Average room temperature. The room temperature can be calculated using an expression based on several temperature sensors distributed throughout the room

What scenarios could you imagine and what could/should be changed at this point so that the user can handle it with little or no programming knowledge?

2 Likes

We can set a Variables value in an Action

image

Agreed that might make it easier.

image

I tried to do that expression myself after your other thread. But I could not do it. I kept on getting an Invalid Params error when I tried for some reason.

That is true as we discovered the other day. I would like to be able to insert the value of an expression or the value of a variable for that matter into the setItemValue field of a device such as a virtual temp device.

I haven’t managed to do any of this with Ezlogic yet (Except #5). As I even haven’t tried yet or it was not currently possible.

Some examples from my MSR rules where I use “Expressions”

Note in MSR the Expressions are used both as variables and expressions. They are not two separate things like they are in Ezlogic.

  1. HTTP request used in a rule to query some end point device or service.

For example I have a rule that sends a HTTP command to my media servers local API to get the current Movie, TV Shows, Music Album counts etc.

The result of this HTTP request are stored in a variable.

The rule then parses out the bits of JSON data I want into other variables one for each etc.

The rule then sends that data to the Multi-String plugin on Vera to display that data in Vera UI7. I can then have a tile on my dashboard for the Media Server data etc.

We need Multi-String plugin type functionality in Ezlo dashboard its missing currently.

Note - Seems to be no easy way to parse out bits of returned data in Ezlogic, I had to use LUA script to do that. In MSR we can do it much more easily, in the rules UI using $ wild card thingy’s.

  1. I use a rule and an expression to get all the devices that are unreachable / offline, the rule then sends me a notification and TTS announcement. Same for low battery levels.

  2. Similar to #1 send a command via Shell terminal from a rules Action, to my router to get the current hardware Temps. store that data in a variable, parse out the bits of data into other variables then send those to Vera and the Multi-String plugin for display on the dashboard, also does notification when temps are too high.

  3. Send a HTTP command to a website to get my current WAN IP store it in a variable, rule has a “Changes” trigger and if my static IP changes to anything else then notify me.

  4. Send HTTP command to online weather service like OpenWeather, store data in a variable, parse a particular bit of data to another variable. use that variables value in your rules trigger etc.

  5. Send a terminal shell command from a rules Action, to run a script on my Linux (MSR) box to query my Playstation 4.

Note - In MSR not only can we store data in variables from HTTP commands, we can also store data returned from shell commands and scripts (very powerful indeed).

Store returned data into a variable, parse out data bits into other variables, send to Multi-String plugin in Vera to display that data on a dashboard tile. Like What is the PS4’s current power state? What game title or application is currently running etc?

These rules and script is also used to actually power ON the PS4 in conjunction with a Logitech Harmony Activiity. As by default universal remotes cannot power on the PS4. Sony limitation / block etc.

Just some example I do more in MSR with “Variables” aka Expressions.

I have some ideas for that, I have a rough idea of what is missing from the Ezlo system. I’ll have a think about it more first though.

I had overlooked that. What is not possible as an action is to pass a variable to a device. For example, setting the setpoint heating to the value of a variable. I can only assign a fixed value. Or writing a value from a device into the variable.

I created a feature request ticket for that. FYI ticket number was SSOA-283

2 Likes