Page 1 of 1

Howto trigger blockly from lua script (Alarm Example)

Posted: Monday 15 February 2016 21:17
by peter
I followed the Alarm Setup guide from https://www.domoticz.com/wiki/Alarm_Setup, but blockly is not triggered.
Basically on a device change (a PIR sensor) a user variable AlarmDetected is set to 1. Blockly should handle this and perform an action.
I assume this does not work to prevent event loops, setting a user variable from a lua script will not again trigger blockly.
(Or I am clearly doing something wrong...)

My use case is that I would like to trigger blocky from lua so that some part of my function can be in lua and some part in blockly.

I use Domoticz v2.4607 (git pull of today) on linux.
My lua script:

Code: Select all

commandArray = {}
print('DEBUG: script_device_toggle')
tc=next(devicechanged)
PIR_switch=tostring(tc)
if (PIR_switch:sub(1,3) == 'PIR') then

  if(uservariables['AlarmDetected'] == 1) then
    commandArray['Variable:AlarmDetected'] = '0'
    print('DEBUG: script_device_toggle Set AlarmDetected 0')
  else
    commandArray['Variable:AlarmDetected'] = '1'
    print('DEBUG: script_device_toggle Set AlarmDetected 1')
  end
end
return commandArray
My blockly:
blockly.png
blockly.png (11.33 KiB) Viewed 1466 times
When I trigger the user variable from the webpage, "Blocky Alarm Detected" is written to the debug log. When the user variable is triggered from the script it is not. Am I overlooking something or made a mistake? I can code the complete functionality in a lua script but would like to combine lua & blockly.

Re: Howto trigger blockly from lua script (Alarm Example)

Posted: Monday 15 February 2016 22:40
by jvdz
A LUA script updating a Variable will not trigger the event system running the variable scripts. In this example maybe good as your script would indefinitely trigger itself as it always updates AlarmDetected. ;)
You could do it by commandArray['OpenURL']= performing a variable update through a json call.

Jos

Re: Howto trigger blockly from lua script (Alarm Example)

Posted: Tuesday 16 February 2016 22:19
by peter
Thanks for the help Jos! I assumed as much, thanks for pointing me towards an alternative trigger mechanism.
Did the event system of Domoticz change over time, thereby invalidating the example provided in the Alarm Setup Guide (wiki).
I like the guide it helped me getting my alarm system up & running pretty quick.

Peter.