Howto trigger blockly from lua script (Alarm Example)

Moderator: leecollings

Post Reply
peter
Posts: 2
Joined: Monday 15 February 2016 20:55
Target OS: Linux
Domoticz version:
Contact:

Howto trigger blockly from lua script (Alarm Example)

Post 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 1462 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.
User avatar
jvdz
Posts: 2330
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
peter
Posts: 2
Joined: Monday 15 February 2016 20:55
Target OS: Linux
Domoticz version:
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest