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.

Assign Priority to a physical switch vs Motion sensor in a script?
#1
Hi,
Looking for some help to determine if a particular light/group address was last turned on via a physical switch, or via a PIR motion sensor (which is a different address).
I need the switch to 'Win' i.e if a user turned on a light via a switch, leave it on when the PIR motion even expires. Is this possible?

This is a C-bus system not KNX, but more or less the same in terms of principles and addresses...
The real lighting GA is assigned to a bus relay output, and also to 4 physical buttons over various switch plates. Each button has a local LED and works great to indicate the state of the actual light, so I don't want to interfere with this.  

The PIR is a normal dumb/electrical device (non-bus aware itself) but is connected via a volt-free bus-auxiliary input, and effectively works like a bell-push event as seen by the logic machine / SHAC. It's simply Motion = 1, No motion = 0. The length of time the PIR signal stays at 1 (motion detected) is determined via a mechanical dial on the PIR itself, can't be influenced via LM...

I have this basic construct of what I need to do, but I'm missing the magic of determining what the last device to turn the light on really was...
Any help is greatly appreciated. 

Code:
-- Control of main GA via a PIR Slave GA

local Master = 35     -- Utility Room Light Group Address (all existing switch buttons use this Group)
local Slave = 73    -- PIR Group Address (This event script is linked to this address)
local Nw = 0
local Group = 56

value = event.getvalue()

--if light is currently off, turn it on
if (GetCBusLevel (Nw,Group,Master) = 0) and (value >=1) -- Similar to standard grp.getvalue in standard LM...
then
  --set Master GA On
  SetCBusState(Nw, Group, Master, true)    -- Similar to standard grp.write in standard LM..
end


--PIR Goes off - if light is currently on, and was turned on via motion sensor and not a switch, turn it off
if (GetCBusLevel (Nw,Group,Master) >= 1) and (value = 0)
 
  -- Here I would like to determine somehow if light/GA was turned on via a physical button, or the PIR
  -- The physical switch should 'win' - if a person turned on light manually via a button, leave it on.
 
then
  --set Master GA Off
  SetCBusState(Nw, Group, Master, false)
end
Reply
#2
In KNX we can check what physical address did sent the telegram, no idea if you can do the same in cbus. The simplest solution would be to use separate control groups, one for switch, second for PIR and third for the light. The control would be done by the script then.
------------------------------
Ctrl+F5
Reply
#3
Hi, I had tried the three-group method already, but it leads to problems with the local LED indicators on the switches. Not sure how KNX works exactly, but in C-Bus, you basically just have one address for a group. You assign this group to any button you need to control the light, and then also assign the same group address to the relevant channel on your physical output unit. So it all keeps in sync that way...if GA 35 is 'On', all the LEDs on your buttons assigned to 35 are also on, and the output module you assigned as 35 is also on. Turn 35 off, and the relevant output goes off, and all the LEDs on the switches too.. there is no need to really map or cross-connect switch buttons to outputs, they just share the same address to begin with. 

That's kinda my problem, I wanted to continue to use this native basic configuration as there are a number of different switches already configured, and some other visualizations etc. that i didn't want to have to mess with. I was just trying to reduce the number of changes required to the system overall, for something I thought was a bit easier than it appears to be Smile ... If this was like an industrial PLC I'd use some Set/Reset blocks and some rising and falling edge triggers...just struggling to adopt this approach to LUA code..I'll keep at it, but thanks for the suggestion
Reply
#4
If you can get the sending device address then you can save it using storage.set when ON command is received. Then use storage.get to retrieve the address of the device that turned the lights ON when OFF command is received.
Reply
#5
Hi, Thanks for the idea. I did that and it works great. I made two Event scripts, one for the real lighting group 35, and another for the slave PIR group 73. 
In the event script for 35, I first check the event sender to make sure it really came from the physical bus or the visualization, then I create/set a storage object and set it to true when the switch turns on, or false when off. 
Normal bus/system functionality turns the actual light on/off. 

In the other event script for the PIR group 73, I turn on the light when this event value is '1' but if it is '0', I have a nested "If" to additionally check if the storage pseudo-blocker object is true or false before attempting to control the light. Works Perfect, and no rework is required to any other part of the system. 

Thanks again!
Reply


Forum Jump: