Openhab burglar alarm diy! not a real one!

I know that openhab at a certain point had a python implementation but that did not get any traction. The point is am I am trying to solve a problem Wich requires a solution. Now should I get a proper alarm system ? Why when verisure and other companies make a business deceiving people into thinking they get an profesional system ! The other option is a company that at best you pay a yearly contract to get someone to call you to check if it’s a false alarm and else calls the police. The thing is if an idiot manages to get a driving licence but fully ignores what alcohol does what then should we not make cars anymore or only sell them to profesional drivers and hire one to drive us ? I am not trying to argue with you or put the community on my head but allot of things in life that are not used knowing the limitations or risks lead to bad results but in the right hands become useful tools.
And to close it imagine you get hold of some screwdrivers and start messing in the electric panel and you get yourself hurt who is to blame there you or the electrician?
Again I really apreciate the comments and just for fun the other weeks I had to fix a problem when the wife unknowingly used the VELUX shutters using openhab but the window was open towards outside (who fault is it the VELUX binding openhab or mine? ).

You mean a Python implementation of alarm rules? There’s never been an implementation of OH in Python. IIRC there was an implementation of some rules in the third party openHAB Helper Libraries in Jython but that library never did become an official part of the OH project.

OH should have known that the window was open and prevented the shutters from closing, issuing an alert of some sort for why. :wink:

Exactly

For future reference this is the fix that I did and made me start learning JavaScript because I also had knx button controlling the VELUX channels so the only solution was to disable the channel completely

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: Dressing_top_window
    type: core.ItemStateUpdateTrigger
  - id: "3"
    configuration:
      itemName: Master_top_window
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: |
        // UIDs of the Things 
        var dressingThingUID = 'velux:window:hub:Master_roller_dressing';
        var masterThingUID = 'velux:window:hub:Master_roller_bedroom';

        // Fetch the state of Dressing_top_window and Master_top_window
        var dressingWindowState = items.Dressing_top_window.state;
        var masterWindowState = items.Master_top_window.state;

        // Control the Dressing Thing based on Dressing_top_window's state
        var dressingThing = things.getThing(dressingThingUID);
        if (dressingWindowState === "OPEN") {
            dressingThing.setEnabled(false);
        } else if (dressingWindowState === "CLOSED") {
            dressingThing.setEnabled(true);
        }

        // Control the Master Thing based on Master_top_window's state
        var masterThing = things.getThing(masterThingUID);
        if (masterWindowState === "OPEN") {
            masterThing.setEnabled(false);
        } else if (masterWindowState === "CLOSED") {
            masterThing.setEnabled(true);
        }
    type: script.ScriptAction

If the person never consulted an electrician, then they’re to blame (since there’s literally no one else to assign blame to). If an electrician gave them a screwdriver and instructions for messing around in the electric panel–without talking about the dangers–then the electrician is to blame.

In this metaphor, you are the electrician. Hence my suggestion to accompany your instructions with some commentary on the limitations of a DIY alarm system. Again, it’s fine if you don’t want to do that. I just don’t see a reason not to.

Ok then help me put the warning in a clear way :pray: see above what I did.

There are other approaches but disabling the channel is a good one.

I probably would make the code above generic but if you’ve only two windows, meh, good enough is good enough. But you can make the code a little cleaner applying the 123 design pattern.

var dressingThingUID = 'velux:window:hub:Master_roller_dressing';
var masterThingUID = 'velux:window:hub:Master_roller_bedroom';

// 1. We always need to run the rule 

// 2. Calculate what needs to be done
// UIDs of the Things 
var window = event.itemName;
var thing = things.getThing(window.includes("Dressing") ? dressingThingUID : masterThingUID);

// 3. Do it
thing.setEnabled(event.itemState.toString() != "OPEN);

One can get clever in mapping thing names to Item names (e.g put the mapping in Item metadata, combine these all into an Equipment, etc.), but since there’s just two the above is pretty simple and straight forward. What the above does is get the name of the Item that triggered the rule. Then it gets the Thing associated with that Item based on whether the Item has “Dressing” in the name or not. If not it’s assumed to the the bedroom window.

Once you have the right Thing it’s just a matter of posting true/false based on the state change that triggered the rule which we have in event.

Another approach involves proxy items. Have a proxy item and a “real” item where the proxy Item is what gets shown on your sitemap/MainUI and used in rules and such to control the shutters. Then you have a very simple rule:

  1. triggered by commands to the proxy Items
  2. condition that only runs the rule if the corresponding window is CLOSED. Here is a great place to generate some sort of feedback to the user if the command is going to be refused (notification, announcement on a smart speaker, etc.) (I’m making assumptions on the Item naming scheme)
var windowName = event.itemName.replace('roller', 'window'); // assumes window and shutter names are the same except for that one word
if(items[windowName].state == "OPEN") {
  // send alert
  false;
}
true;

Without the alert it’s just

items[event.itemName.replace('roller', 'window')].state != "OPEN;
  1. simple script action that consists of this one liner: item[event.itemName.replace["_Proxy", ''].sendCommand(event.itemCommand.toString());

That’s in my first post:

You can probably reframe those paragraphs as a bullet-point list of pros and cons. Then you’re making people aware without pushing them away from your solution.

I might add this:

I believe I fulfill all your requirements now. Please check first post. Now on to learning more about rule templates.

1 Like

A more concise approach:

if(["ARMED_AWAY", "PENDING", "TRIGGERED", "ARMED_HOME"].includes(alarmState))

A more

concise way:

g_away.members.forEach( item => {
  if(item.state === "OPEN")
  ...
});

Though I’m pretty sure that won’t work in ECMAScript 5.1. In that case

g_away.members.stream().forEach( function(item) {
  if(item.state === "OPEN")
  ...
});

If this is turned into a rule template, this needs to be a log statement. Not all users will have the openhab cloud connector installed and configured.

The indentation is a little off here.

Use

if(triggeringItem.isUninitialized || alarmStateItem.isUninitialized)

More concise ways to access an Item:

items.Alarm_State.state
items['Alarm_State'].state

Unless these commands are intended to cause something to happen, these should probably be postUpdate.

Structurally you might consider centralizing the countdown timer stuff into a class. It always gets a little tricky when managing and understanding this type of code when it’s spread across the whole code base.

Because this is not using a real thread safe locking mechanism, there will be rare cases where two rules both acquire the lock and run at the same time. Make sure that the whole system doesn’t blow up in those rare circumstances.

If you do need full thread safe operations, you’ll either need to use a java.util.concurrent.locks.ReentrantLock, Semaphore, or the like, or you’ll need to put all these separate rules into a single rule which does the thread safe locking for you.

Also, beware that it may be the case that not all errors get bubbled up so you can catch them in your rule. If one of those were to occur, your rules will become locked forever (until reloaded at least).

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.