Door open

Hi all,
I am living on the top floor in an apartment, and to get into my flat i have hacked the intercom phone. I have then attached this to a relay that i control with a switch item:

Switch Div_DoorOpener "Door Opener" (Group_Hallway,Group_LightLogging) { gpio="pin:22" } //mappings=[ON="On"] //Relay 5

However i want to just push the switch item, then the PIN(Rpi) goes HIGH for around 6 seconds and then the pin go back to LOW

However I am having some problem with my rule on reboot, and changing the state of switch, sometimes its just flickers between high and low state on the pin

Here is my rule:

import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*

var Timer timer=null

rule "Opening Door"

when
    Item Div_DoorOpener changed from OFF to ON
then
	
	
if(Div_DoorOpener.state == OFF){
	sendCommand(Div_DoorOpener,ON)
	postUpdate((Div_DoorOpener,ON)

    timer = createTimer(now.plusSeconds(6)) [|
         sendCommand(Div_DoorOpener, OFF)
	 postUpdate((Div_DoorOpener,OFF)

    ]

}

else {
	//sendCommand(Div_DoorOpener, OFF)

}
end

Should I change my item to
Switch Div_DoorOpener "Door Opener" (Group_Hallway,Group_LightLogging) { gpio="pin:22" } { autoupdate="false" } mappings=[ON="Open"] //Relay 5

I also tried to initialize my switch:

rule “Initialize all items”
when
System started
then
logInfo( “Initializer”, “Started Timer …”)

createTimer(now.plusSeconds(45)) [|

    logInfo(    "Initializer", "... initializing!")
    //Wir warten 45 Sekunden, dann initalisieren wir alle die nicht aus der Datenbank befüllt wurden
    Group_LightLogging.members.filter( x | x.state == Uninitialized).forEach[ item |

        postUpdate( item, OFF)
    ]
]

end

Did I miss something, how should my item be defined and how should the rule look like to get it to work?

ANy hint will help:)

I use a few things such as this
The problem on my Pi is that the GPIO binding sets all the relays to ON at startup. So I need “startup.rules” that sets everything off once the system is settled. For you I’d suggest creating something like this

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
var Timer startTimer = null
var Timer NotificationsTimer = null
rule "reset all GPIO connected items on startup"
when
System started
then
{	postUpdate(DisableStartupNotifications, ON)
	startTimer = createTimer(now.plusSeconds(60)) [|
        sendCommand(Div_DoorOpener, OFF)
        sendCommand(DisableRelays, OFF)
        postUpdate(DisableStartupNotifications, OFF)
 ]}
end

you can then use “if DisableStartupNotifications.state == OFF” in your rules to stop things happening as the system starts, before things are in an known state.
I power all the GPIO relays via the normally closed contact on an extra relay called “DisableRelays” that way nothing works until startup.rules has finished

I use a separate rule for each item that I want to turn off again after a time period. In your case it would be something like

rule "Turn off door relay"
when
	Item Div_DoorOpener changed from OFF to ON
then
if (DisableStartupNotifications.state = OFF)
{	DoorTimer = createTimer(now.plusSeconds(6))[|
	sendCommand(Div_DoorOpener, OFF)
]}
end

In default.items the items could be

Switch Div_DoorOpener { gpio="pin:22 activelow:yes" }
Switch DisableRelays { gpio="pin:6 activelow:yes" }
Switch DisableStartupNotifications

Not doubt there are other ways of doing this, but this way works, and if (DisableStartupNotifications.state == OFF) stops a lot of stack dumping on startup as the rules get added to.

Then you can not have a circut breaker for each relay, or having large load on each relay… But the idea is good though.

So the startup rule will look like

rule "Initialize all items"
when
    System started
    then
   {
    logInfo( "Initializer", "Started Timer ...")
    postUpdate(DisableStartupNotifications, ON)
    createTimer(now.plusSeconds(45)) [|

        logInfo(    "Initializer", "... initializing!")
        //Wir warten 45 Sekunden, dann initalisieren wir alle die nicht aus der Datenbank befüllt wurden
        Group_LightLogging.members.filter( x | x.state == Uninitialized).forEach[ item |

            sendCommand( item, OFF)

        ]
        postUpdate(DisableStartupNotifications, OFF)
    ]}
    end

How should the switch item look like, when I want it to only have a button with the text Open?

You have to use mappings in your sitemap. Remove the mapping code from your item.

For example:

items:
Switch Div_DoorOpener "Door Opener" (Group_Hallway,Group_LightLogging) { gpio="pin:22" }

sitemap:
Switch item=Div_DoorOpener mappings=[ON="Open"]

I am bit lost, I tried doing this, but that displayed door item on top of my main page.

//Switch item=Div_DoorOpener mappings=[ON="Open"]
	Frame label="Main" {
		Group item=Group_LivingRoom label="Living Room" icon="video"
		Group item=Group_Kitchen label="Kitchen" icon="kitchen"
		Group item=Group_Bathroom label="Bathroom" icon="bath"
		Group item=Group_Bedroom label="Bedroom" icon="bedroom"	
		Group item=Group_MasterBedroom label="Master Bedroom" icon="bedroom"
		Group item=Group_Hallway label="Hallway" icon="groundfloor"
		Group item=Group_Balcony label="Balcony" icon="garden" 
		
	}

I power just the relay module with switched 5V via an additional relay. The outputs of the relays are wired and fused normally. I have the relays wired so they get 0V to turn them on from the Pi. I use buffered and isolated relays so the 3.3V output on the Pi doesn’t get loaded or fed back 5V from the 5V switched supply.

My code is somewhat simpler as I just create a timer for 60 seconds, then initialise the GPIO pins by sending off commands to each of them individually including the relay that provides power to the rest of the system when its released, I then wait an additional 90 seconds before I reset the DisableStartupNotifications to OFF to allow the system to become stable. I have over 100 items on my system so it needs some time on the Pi2 to stabilise.

It may be more efficient to use forEach but I am only a Java beginner so I have yet to learn how that works

I use ordinary switches for my push button items and I can see that the rule has turned them off again after the time delay.

[quote=“skatun, post:5, topic:6146, full:true”]
I am bit lost, I tried doing this, but that displayed door item on top of my main page.[/quote]

Unfortunately, that does not work with groups, at least what I’m aware of.
You have to manually put your items into a frame and then you are able to use mappings for that single switch.

Frame    {
        Text label="Test" icon="whatever"
            {
            Switch item=Testitem1
            Switch item=Testitem2
            Switch item=Testitem3
            Text item=Testtext1
            Text item=Testtext2
            Switch item=Div_DoorOpener mappings=[ON="Open"]
            }
        }

Just wanted to let you know Its been working smoothly for the last two weeks:) I added the the sendcommand(Div_DoorOpener,on) to IFTTT and it makes my life easy.

So its about time to take it to next level:

1: Can I add some rights in myopenhab so that guest users can only access that one command, and can I also time limit that? So I can grant my family access for certain periods.

2: So i can trigger Div_DoorOpener when I enter an area, however this is Ok, but unpractical because it has a radius of at least 40 meter, and hence the door will open to early. So can i trigger it if I enter an area and I am standing still for 15s(no motion from accelerometer on phone)?

3: My basement is close to the entrance door, hence i could put a bluetooth dongle down there and have it communicate it with my openhab server upstairs. But how to do this?

Other ideas how to trigger Div_DoorOpener when I am getting close to the door with hands full of groceries?

@skatun i want to do exactly the same. Which relay do u use?

Any relay that triggers at 3.3V will do :slight_smile:

What i did was to solder two wire, on on each side of the button you use today and then take one wire toi common and the other to normally open

Mvh Kim

But what are you controling your relais with? Did you attach it to a Pi ?

I am looking for a zwave compatible relay because my pi location is not anywhere near the intercom :wink:

Ah, didnt think of that one that you can not hardwire your relay signal cables to the PI. You can always use the 5usd esp8622 and a relay connected to that one, puts you in at 9usd + casing or take a nexan or zwave relay.

ESP8622 sounds like a good & cheap idea

http://www.monoprice.com/mobile/product/details/11989?maincategoryid=122&categoryid=12212&subcategoryid=1221201&cpncd=

you can terminate the switch wire and use it as relay only.