How do you configure virtual devices?

Hello everyone,

I have just created an expression where the average value of two temperature sensors is calculated. Now I wanted to try to create a virtual temperature sensor to display this calculated value. The only thing I managed to do was create the sensor. But how do I feed it with data now? Are there any instructions for this? Can this be done via the web frontend, or is it only possible via the depths of some API?

image

Very good question! And I would like to know the answer too.

There are limitations with some of the virtual devices it seems and I have been nagging Ezlo about this for ages. The virtual devices are created using an internal plugin called test_plugin. That was originally used for internal testing of “devices” apparently.

The problem is that these virtual devices closely represent what a “real” device would be like on the system.

For example for a real temp sensor device you would not manually set a value on that real device would you.

So currently when you add a virtual temp sensor device to the system it behaves the same way. And it does not allow you to use that virtual temp sensor device in a Meshbot rules Action, as the device is just simply missing from the device list.

I just created this virtual device on my Controller.

image

And when looking in a Local Meshbot’s Action that device is not present.

image

The reason for this, you can see in the API, that for the Item “temperature” the hasSetter = False. This means that it cannot be displayed and used in a rules action and have its temp value set as you would want.

I have asked Ezlo to change this for a long time, but they haven’t done so. I can’t see the point in have a virtual device if you cannot set its value?

Virtual Temp Sensor API Info

Device Info:

_id: "66058f6c123e4314a63100ff"
batteryPowered: true
category: "temperature"
deviceTypeId: "test"
gatewayId: "620a6b8e123e431217766a50"
info: Object {}
name: "Virtual Temp Sensor 1"
parentDeviceId: ""
persistent: false
reachable: true
ready: true
roomId: "629b65ac123e4312b6b8b878"
security: "no"
status: "idle"
subcategory: ""
type: "sensor"

Items Info:

items:
0:
_id: "66058f6c123e4314a6310100"
deviceId: "66058f6c123e4314a63100ff"
hasGetter: true
hasSetter: false <<<<--------
name: "temp"
scale: "celsius"
show: true
value: 0
valueFormatted: "0"
valueType: "temperature"
1:
_id: "66058f6c123e4314a6310101"
deviceId: "66058f6c123e4314a63100ff"
hasGetter: true
hasSetter: false
maxValue: 100
minValue: 0
name: "battery"
show: true
value: 87
valueFormatted: "87"
valueType: "int"

Only other possible way maybe? Is to use the Ezlo HTTP Server API to send a HTTP command in the rules action back to the controller to set the value on the virtual temp device ??

The other option might have been to use a Cloud Meshbot rule instead of a Local one.

I am not sure why this is? But in a Cloud Meshbot rule the virtual temp sensor device can be selected in the Action.

However it does not have the required Capabilities to set a temp value, they seem to be just missing.

image

And the funny thing is I dont have this limitation or restriction in Multi System Reactor rules engine.

As MSR uses the Ezlo web sockets API for comms with the Ezlo controller and devices on there.

The Ezlo web socket API doesnt seem to have this restriction, so in an MSR rules action I could select that virtual temp sensor and push a value to it.

Yet I cannot do that in Ezlo’s own rules engine, which seems crazy.

MSR Rule Action -

image

Result -

image

This HTTP command works for me to set the virtual temp sensor to a value of 23.

You need to use the Temperature Item id number of your virtual device.

https://192.168.0.101:17000/v1/method/hub.item.value.set?_id=66058f6c123e4314a6310100&value_int=23

image

However not sure how helpful this is if at all.

Much more information about the Ezlo HTTP Server API here.

1 Like

@Odysee I have a work around hack for you to change the hasSetter value to TRUE.

Which results in the Temp sensor being available in the Meshbot Action to set its value.

Go to the Online API Tool here login select the controller where the virtual Temp device was created, modify this script and change the Device ID and the Item ID to that of your own virtual devices.

{
  "method": "hub.extensions.plugin.run",
  "id": "_ID_",
  "params": {
    "script": "HUB:test_plugin/scripts/modify_item",
    "scriptParams": {
      "item_id": "66058f6c123e4314a6310100",
      "item": {
        "device_id": "66058f6c123e4314a63100ff",
        "has_getter": true,
        "has_setter": true,
        "name": "temp",
        "show": true,
        "value_type": "int",
        "value": 0
      }
    }
  }
}

Use the “Custom” option in the API Tool and hit the send button.

Your virtual temp sensor will then appear in the Meshbot Action and you can set a value, I have tested it and it works.

image

Your next problem is now how to put that expression value into the virtual temp sensor device?

In the Action you can add a value number but how you would add the value from the expression I do not know.

And that last part of the puzzle we cant do it yet, which is what I thought. I have created a feature request ticket for it (# SSOA-283)

Here’s what the dev said.

“There is no such feature. Using variables or expressions in action was never implemented.
As a plan, need to support expressions/variables as a data source for setItemValue action.”

I can do it in MSR however OK. Which doesn’t help you if you are not using MSR rules engine.

image

Thank you for your commitment. I’m already failing because of the Item ID. I found the device ID under the device settings.

But as long as you still can’t take values from an expression, that obviously doesn’t help you much. Of course, it would be even more user-friendly if you could simply use an expression or something similar as a source for the virtual devices without having to use a MeshBot to update it every x minutes.

Yes I agree with what you say.

To find the Item ID numbers you can use the Online API Tool.

Select the option find Items filtered by device ID.

Use the device ID you have already discovered.

After pressing the Send button scroll down the page and expand the Response.

It should list two items for your Virtual Temp device.

One is the Temp item, thats the one you need. The other item is for the “battery”.

Not sure why it shows a battery for virtual devices but thats another story.