Calculations with dzVents  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Podarcis
Posts: 7
Joined: Sunday 26 April 2015 18:05
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Calculations with dzVents

Post by Podarcis »

Hi All,

I need some help with a relative simple dventz script.

I have 2 sensors;

IDX347, which is the current percentage charge of the battery of my Renault ZOE,
IDX353, which has the current range
IDX518, in this dummy sensor I would like do calculate the predicted max range of my car. Should be calculated by (Range/%charge)*100).

I tried to do it the following way;

Code: Select all

return {

   on = { timer = { "every 2 minutes" }},     -- Change to your liking to 1,2,3,4,5,6,10,12,15 or 20  

   execute = function(dz, item)

       local Predicted_MaxRange = dz.devices(516)
       local rangeZOE           = dz.devices(353)
       local accuZOE            = dz.devices(347)

       local Predicted_Maxrange = ((rangeZOE / accuZOE) * 100 )
       
       domoticz.log('----predicted maxrange------------------')
       domoticz.log(Predicted_Maxrange)
       domoticz.log('----------------------')

   end
}
This doesn't seem to work (ok, I still have to figure out to put in the result in IDX516, but by printing it in the LOG I at least should know that I'm on the right track. However, I get an error;

Code: Select all

2019-07-08 18:08:00.461 Status: dzVents: Info: ------ Start internal script: Predicted_max_range_ZOE:, trigger: every 2 minutes
2019-07-08 18:08:00.468 Status: dzVents: Error (2.4.22): An error occured when calling event handler Predicted_max_range_ZOE
2019-07-08 18:08:00.468 Status: dzVents: Error (2.4.22): ...ts/dzVents/generated_scripts/Predicted_max_range_ZOE.lua:19: attempt to perform arithmetic on local 'rangeZOE' (a table value)
2019-07-08 18:08:00.468 Status: dzVents: Info: ------ Finished Predicted_max_range_ZOE
Can somebody help me?

Thanks,
David
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Calculations with dzVents  [Solved]

Post by waaren »

Podarcis wrote: Monday 08 July 2019 18:29 IDX347, which is the current percentage charge of the battery of my Renault ZOE,
IDX353, which has the current range
This doesn't seem to work (ok, I still have to figure out to put in the result in IDX516, but by printing it in the LOG I at least should know that I'm on the right track. However, I get an error;
Your script tries to compute the product of two devices (tables) depending on the type of these devices you probably want to compute the product of field values.

For example if rangeZoe is percentage devices and accuZoe is a counter device you would have to change line 11 from

Code: Select all

local Predicted_Maxrange = ((rangeZOE / accuZOE) * 100 )
to

Code: Select all

local Predicted_Maxrange = ((rangeZOE.percentage / accuZOE.counter) * 100 )
Have a look at the wiki for all possible fields and methods for your specific devicetype(s)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest