Blockly with incremental counter does not work

Post Reply
EricT
Posts: 35
Joined: Tuesday 01 May 2018 8:09
Target OS: Raspberry Pi
Domoticz version: 3.9440
Location: Rijen, The Netherlands
Contact:

Blockly with incremental counter does not work

Post by EricT » Tuesday 01 May 2018 9:11

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
Attachments
counter1.jpg
counter1.jpg (15.68 KiB) Viewed 647 times
counter log.jpg
counter log.jpg (15.06 KiB) Viewed 647 times
Device.png
Device.png (4.06 KiB) Viewed 647 times
Blockly.jpg
Blockly.jpg (35.92 KiB) Viewed 650 times
counter1.jpg
counter1.jpg (15.68 KiB) Viewed 650 times
counter log.jpg
counter log.jpg (15.06 KiB) Viewed 651 times
counter log.jpg
counter log.jpg (15.06 KiB) Viewed 651 times
Blockly.jpg
Blockly.jpg (35.92 KiB) Viewed 652 times
if it was easy everybody would do it

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest