I can do that with TimeofDay, but what about armed? Because I have 8 proxies for the cameras, one for each camera. Im not sure how I’d check if the triggeringItem is also armed. Does that make sense?
I don’t really understand. Getting name Patio_armed from name Patio is pretty straightforward and exampled in Paul’s rule. (Albeit it needs source + “_extra” syntax fixing)
Yes of course. Have you tried? Maybe do it in steps, all the parts are already shown in this thread. Trigger a rule. Get the triggering Item name. Use that to build the armed item name. Use that to fetch the Item from a group. Now you can construct an if() evaluation of that Item’s state. Then you can turn the light on (or not).
I can’t try because I dont have access to the system as yet. OK, so I can construct the Armed item from the triggeringItem as the names are the same, the Armed just has _Armed prepended to the end.
rule "Motion activated Lights using CCTV Cameras"
when
Member of gMotionSensors received command ON
then
logInfo("Motion.rules", triggeringItem.name + " detected motion.")
if (vTimeOfDay.state == "EVENING" || vTimeOfDay.state == "NIGHT") {
val source = triggeringItem.name
val armed = triggeringItem.name+"_Armed" as SwitchItem
}
if (armed.state == ON){
Does that look ok? I will need to change the Light names to match the triggeringItem to some degree I would guess. I don’t really understand the logic in Paul’s example with respect to:
val _Cam = gMotionSensors.members.findFirst[ cam | cam.name == source"_Cam" ]
val _Light = gAllLights.members.findFirst[ light | light.name == source"_Sw" ]
Nope. armed in your rule is just a string, the name of the Item you want. It doesn’t have a .state, it’s just a string not an Item.
There are at least two ways to get hold of the actual Item with that name (so that you can in turn get hold of its state),
You can select it from a group of which it is a member, as already shown in in this thread, or you can use a registry action.
Learning a language is incredibly difficult for someone without programming background so apologies for what may seem extremely trivial to you.
import org.eclipse.smarthome.model.script.ScriptServiceUtil
val _Armed = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name+"_Armed") as SwitchItem
To end up with:
import org.eclipse.smarthome.model.script.ScriptServiceUtil
rule "Motion activated Lights using CCTV Cameras"
when
Member of gMotionSensors received command ON
then
logInfo("Motion.rules", triggeringItem.name + " detected motion.")
if (vTimeOfDay.state == "EVENING" || vTimeOfDay.state == "NIGHT") {
val source = triggeringItem.name
val _Armed = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name+"_Armed") as SwitchItem
}
if (_Armed.state == ON){
I can only speak from my own experience and I use the name to make things easy, have two lights one called _Sw1 and one called _Sw2 does not really help when trying to make things generic.
I am sure some genius around here can assist but its beyond my abilities, whereas the way I described is how I do all of my generic rules pretty much.
Take the easy way or continue down the harder road.
You’re helping Paul. Don’t be sorry. Yes I think I’ll have to rename my lights to match my motion sensors and camera names with underscores to allow the user of triggeritem.name
the delimiter is an underscore, this is useful and supper easy to locate when breaking the name into different parts inside rules.
The first part is an abbreviation for the location, e.g LR - Livingrroom, BR1 equals Bedroom 1 and KT equals Kitchen.
The second part equals the device type.
4.The final part is the specific cahannel so if its simply the device on /off you could use ‘Switch’ or for such a default actual just omit it. I went with omitting it but if I started again I would give using ‘Switch’ a go. other obvious actions are Online, LastSeen and Brightness.
putting that all together ends with names like this
KT_PIR_Detect
so Kitchen PIR sensor Detect
Or BR1_Fan_Switch
Bedroom 1 fan switch
Hope the naming syntax makes sense.
now to grab a part of a triggering name item which is part of a group you simply do this
val location = triggeringItem.name.split("").get(0)
val device= triggeringItem.name.split("").get(1)
val action= triggeringItem.name.split("_").get(3)
The three values now contain the individual parts for the triggered item.
These parts can be used to make up other item names so say you have a motion detector trigger in the Library and you want the library light to come on.
if (__Cam==ON) {
sendConnand(_Light,ON)
}
This assumes that you have made _Cam match the Motion Detector of the triggering Camera, and the _Light is trhe deterrent light you want turned on in this event.
I really think you need to start slowly and get access to a system before you try such an advanced topic, with a little playing you will figure it out.
val location = triggeringItem.name.split("").get(0) (So, this returns KT?)
val device= triggeringItem.name.split(" “).get(1) (So, this returns PIR?)
val action= triggeringItem.name.split(”_").get(3) (So, this returns Detect?)
Why have the underscore the the last one but not the first ones. I don’t see any consistency.
I think that’s just what the forum has done to underscores outside of code fences.
Like the way it will hide <angles> if you don’t fence them.
The third part should be get(2) as well.
But you’ve grasped the idea of the split / get tools, it’s just string manipulation.
the split command splits up a string into chunks. The item in the parenthesis is the delimiter. It is a string, enclosed in double quotations. In other words, the character in the delimiter string is where we want the string to be split up at. The command returns a array of strings which are the resulting chunks of the string. Each member of the array is one chunk of the string. The dot get and a number enclosed in parenthesis is which member of the array we want. The array is zero based so if we wanted to get the first chunk we would say .get (0) If we want the second chunk, we say .get(1) and so on
I think the correct syntax is:
val location = triggeringItem.name.split("_").get(0)
val device= triggeringItem.name.split("_").get(1)
val action= triggeringItem.name.split("_").get(2)
It is difficult, but, the cool thing is once you grasp programming logic, they all work the same just different syntax for different languages. So… it is a skill you can use for the rest of your life
to me is fun
Yes I have access now, but I dont have a rule I can implement, I’m still confused
rule "Motion activated Lights using CCTV Cameras"
when
Member of gMotionSensors received command ON
then
logInfo("Motion.rules", triggeringItem.name + " detected motion.")
if (vTimeOfDay.state == "EVENING" || vTimeOfDay.state == "NIGHT") {
val source = triggeringItem.name.split("_").get(0)
val _Armed = gMotionSensors.members.findFirst[ arm | armed.name == source"_Armed" ]
logInfo("Motion.rules", _armed.name + " Sensor")
}
end
I would imagine, that when a group member receives command ON, that in the final log, I should see the name of the Armed item that corrosponds to the triggeringItem, but I see nothing