How to creat a calculating virtual device

So, i have try with the device in place and it work :wink:
Big big big thanks to you @akbooer

I have just an other problem, the device is away than the zwave network (vera edge have less scope than my first eedomus) because i have try it 3 years ago and it worked with eedomus.

Just to be perfect, how can i reduc the number behind the decimal? (see the picture)
Idealy, I would have only one decimal like 10,1%

PS: I modified the first post with a tutorial , it will save the gents have to read the entire thread

If I read correctly, you want to round the value to a certain number of decimals
 then you could use the following function:

function round(value, decimals) decimals = tonumber(decimals) or 0 return math.floor(tonumber(value) * 10 ^ decimals + 0.5) / 10 ^ decimals end

for example, calling the function like print(round(5.68, 1)) should show 5.7

Glad it works!

For rounding, you can simply use:

x = ("%0.1f"): format (x)


which will give you one decimal place.


Edit: note that this also works correctly for negative numbers , rounding away from zero.

local round = "%0.0f"

print (round: format ( 1.6))
print (round: format (-1.6))

giving the output

2
-2

[quote=“RichardTSchaefer, post:2, topic:192683”]Use existing plugins 


Use the PLEG plugin for the computation
Use the MultiString plugin for the display[/quote]

How do you use pleg to write out the value?

I can get pleg to do computation and do an action if the result is higher/lower that a value but I’d love to be able to send my average house temperature to tasker via the multi string plugin

[quote=“akbooer, post:23, topic:192683”]Glad it works!

For rounding, you can simply use:

x = ("%0.1f"): format (x)


which will give you one decimal place.[/quote]

How can i add this to the LUA code?
Sorry for my newbie attitude

Hello all and particulary @akbooer

I tried to integrate your rounding code but I did not happen.
I 'd ask well one last little helping hands to finish this topic

thank you in advance

I have try this but don’t work

[code]-- VMC efficiency calculation

local ID = {
Outside = 21, – the new outside air
Supply = 20, – the new supply air
Dirty = 22, – the dirty indoor air
Result = 23, – PICK YOUR OUTPUT DEVICE ID HERE
}

local SID = {
temperature = “urn:upnp-org:serviceId:TemperatureSensor1”,
efficiency = “urn:micasaverde-com:serviceId:HumiditySensor1”,
}

local function get_temp (id)
local t = luup.variable_get (SID.temperature,“CurrentTemperature”,id)
return t
end

local outside_temp = get_temp (ID.Outside)
local supply_temp = get_temp (ID.Supply)
local dirty_temp = get_temp (ID.Dirty)

if dirty_temp > outside_temp then
local VMC_efficiency = ((supply_temp - outside_temp)/(dirty_temp - outside_temp))*200
local round = “%0.0f”
print (round: format ( 1.6))
print (round: format (-1.6))
luup.variable_set (SID.efficiency, “CurrentLevel”, VMC_efficiency, ID.Result)
end[/code]

You haven’t applied the rounding to the variable you are setting!

VMC_efficiency = round:format (VMC_efficiency)

and you don’t need the print statements!

Time to go and learn more about the Lua language.