This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

problems with scripts
#1
Good morning,
I need to create an alarm system in an event-driven script using group address 32/1/1.

I'm using two variables called `value` and `value2`. `value2` holds the value of group address 32/1/1, and `value` captures the state of a gate (true/false), which is a value of 01.001 (toggle).
As you can see, I'm trying to write a value of 3 or 0 to group address 32/1/1, depending on the value of `value`, using an `if` and an `else` statement.

The problem I'm encountering is that if the `if` statement is true, the value of address 32/1/1 fluctuates constantly between 0 and 3 (as if it were in a loop), instead of remaining stable at 3. I don't understand what's happening, and I also think Logic Machine 5's memory is being overloaded.


Any help would be greatly appreciated.

Attached Files Thumbnail(s)
       
Reply
#2
Because you created a loop. Event script is triggered when it receives a telegram to the trigger group and you writing back to your trigger group. Disable the script, sync project and reboot LM. What is the logic you trying to achieve?
------------------------------
Ctrl+F5
Reply
#3
I'll try to explain what I want. Basically, it's about designing an alarm system that alerts the BMS that there's an intruder in the home. For this purpose, I have a variable representing the value of a presence sensor (0 = no presence, 1 = presence), a variable for the door contact (0 = door open, 1 = door closed), and a variable for the home's status (0 = unoccupied, 1 = rented, 2 = home under maintenance, and 3 = home occupied).

The idea is that if the home is unoccupied (0) and the door is open (0), or if the home is unoccupied (0) and the presence detector detects someone (1), the home's status should change to 3 (home occupied), and a notification of this change should be displayed on the screen.

The problem is that I'm stuck in a loop, and I don't know why.

The door and presence detector variables are type 01.001 switch and for some reason overloaded

Attached Files Thumbnail(s)
       
Reply
#4
You basically must create additional object where you will write the final result of your logic. You have 3 inputs values, door, occupancy and presence detection. TAG all 3 objects and then your event script trigger should this tag. Select it after editing event script settings and in Group address / tag: you will find it on the bottom. Create 4th object to which you will write result of your logic. DO not add TAG to it otherwise you will have another loop.
------------------------------
Ctrl+F5
Reply
#5
You're absolutely right, it worked, although I still don't understand how I was able to create an event-based script loop without using any while or for structure.
Reply
#6
When you write from a script to an object or tag that triggers the event of that same script it will re-trigger over and over again, hence the loop..
Reply
#7
I'm using resident functions because for some reason the event-based functions aren't responding well to those events; the final code I used looks like this:

-- Leer valores KNX
local puerta = grp.getvalue('1/0/14') -- 0 = abierta, 1 = cerrada
local presencia = grp.getvalue('1/0/13') -- 0 = no hay nadie, 1 = presencia
local estado = grp.getvalue('32/1/1') -- 0..3
local alarma =grp.getvalue('32/3/12')

log (estado)
log(puerta)
log(presencia)
log(alarma)

-- DETECCIÓN DE OCUPACIÓN INDEBIDA
if estado == 0 then -- Si no está alquilada la vivienda -- -- Y --
if puerta == false or presencia == true then -- Si la puerta esta abierta O el sensor de presencia detecta presencia --
grp.write('32/1/1', 3) -- Se activa el sistema antiocupación --
alert('Alerta, Vivienda 1ºB OCUPADA')
grp.write('32/3/12', true)
end
end

-- PROBLEMA RESUELTO → VOLVER A NO ALQUILADA
if estado == 3 then
if puerta == true and presencia == false then
grp.write('32/1/1', 0)
grp.write('32/3/12', false)
end
end


I was writing the event-based scripts in the same addresses, in this case, on 32/3/12, and the scripts are not running automatically.
Reply
#8
Well this is not how i would solve it.. event based scripting works as a charm when done correctly, you should figure out what goes wrong in your script instead of a resident script that is checking all the time for an event.. but thats just my 50ct..
Reply


Forum Jump: