Page 1 of 1

Blockly with incremental counter does not work

Posted: Tuesday 01 May 2018 9:11
by EricT
Hi all,

I am new to Domoticz and I cannot get my Blockly with a incremental counter to work, I hope someone can help me out.

I use a motion detector and I want to set a threshold before an email message is send, therefore I want to use a counter that counts the number of times the motion detector is activated. I have created a dummy counter and the Lua event used for updating the counter is set as “Device”.

However I keep receiving the error: "
EventSystem: Lua script error (Blockly), Name: testing counter read_1 => [string "result = 0; weekday = os.date('*t')['wday']; ..."]:1: attempt to index global 'utilitydevice' (a nil value)"


Here is my Blockly, Hardware set up and the Lua code I use to update the counter:
Image

Code: Select all

commandArray = {}

local virtualcounter_idx = "30"
local virtualcounter_name = "counter1"
local switchName = "On signal motion sensor"

if devicechanged[switchName] == 'On' then

-- Get current value
   count_value = tostring(otherdevices_svalues[virtualcounter_name])
   print("old value counter1= " .. count_value)

-- Calculate new value
   count_value = count_value + 1
   print("new value counter1= " .. count_value)

-- Update virtual counter device
   ts = virtualcounter_idx .. "|0|" .. tostring(count_value)
   commandArray['UpdateDevice'] = ts
   print ("ts counter1= " ..ts)

end

return commandArray

Image
Image
Image
Image