Control a relay


#1

Hello to You all,

I’d like to control a relay while i’m pressing the button on sitemap.

when i’m pushing the button the relay is ON, when i let go the button the relay is OFF.

Can anyone help me, how to do this.

Best regards


#2

Please show us your code.


#3

I just have the code that switch ON when i press the button, not the one i would like!!!


#4

I can help fix it. Just show us the code.


#5

Hi
I to would like to be able to add a momentary button to my openhab. I have just followed the MK smart house GPIO tutorial so only have the very same code to operate the items and pins mentioned there.

Switch LED “LED” { gpio=“pin:21” }

//Relays
Switch channel1 “Channel 1” { gpio=“pin:26 activelow:yes initialValue:low” }
Switch channel2 “Channel 2” { gpio=“pin:19 activelow:yes initialValue:low” }
Switch channel3 “Channel 3” { gpio=“pin:13 activelow:yes initialValue:low” }
Switch channel4 “Channel 4” { gpio=“pin:6 activelow:no initialValue:low” }

Contact DoorSensor “Door Sensor [%s]” { gpio=“pin:16 debounce:10 activelow:yes” }
Contact Button “Button [%s]” { gpio=“pin:24 activelow:yes” }

I would like to know if there is a away to add/alter the relay Channel 4 code to replace the on/off switch with a button that latches the relay only when touched/clicked. Or i guess even if you could enter a time delay for the switch to turn back off. (I would like to use channel 4 to operate the garage door)

Kind Regards


#6

So I’ve sort of Managed to sort this one out myself, but as it took a lot more reading and research than i thought it would, so ill put my solution up here.
as stated above i followed the MK Smarthouse GPIO Binding tutorial to start with, then changed a few things.
The whole idea of this was for garage door control and to monitor when/if it is open.
My sketch has changed due to only needing the reed switch and one channel/relay to be operated.

First step is to install another binding in paper UI called Expire Binding.

Then i edited my items and sitemaps files

ITEMS FILE

//Relays
Switch Garage_Gate { gpio=“pin:26 activelow:no initialValue:low”, expire=“1s,command=OFF” }
Contact DoorSensor “Door Sensor [%s]” { gpio=“pin:16 debounce:10 activelow:yes” }

SITEMAP

{
Switch item=Garage_Gate label=“Garage Door” mappings=[ON=“Open/Close”]
Text item=DoorSensor
}

Hope this helps a few people as stuck for a simple solution as i was.