# Relay with pulse function over http

**URL:** <https://community.openhab.org/t/relay-with-pulse-function-over-http/57650>\
**Category:** Beginners\
**Tags:** relay, openhab2, http\
**Created:** [November 23, 2018, 7:55pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650 "2018-11-23T19:55:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 23, 2018, 7:55pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/1 "2018-11-23T19:55:14Z")

</div>

Hi,

I have a velleman vm201 8 channel relay controller. it can recieve commands over http. but i want to let it behave as a pulse function because all the lighting is controlled by pulse switches ( teleruptor ) in my house.

so it has to send a http command. to trigger the relay . a delay . and send the exact same http command to deactivate the relay . otherwise my push buttons in the house won’t work anymore. but the status in openhab must say switch on or off

switch on = http command ,delay, http command  
switch off = http command, delay, http command

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [November 23, 2018, 8:12pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/2 "2018-11-23T20:12:15Z")

</div>

You have an item that can send the command and need a rule for the delay, or you need to create both the item and the rule?

---

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 23, 2018, 8:59pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/3 "2018-11-23T20:59:43Z")

</div>

hi,

if you could i need both 🙂

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [November 23, 2018, 9:19pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/4 "2018-11-23T21:19:46Z")

</div>

I do not have a velleman device, I can help only with pointing toward the documentation. [https://www.openhab.org/v2.3/addons/bindings/k80551/#prerequisites](https://www.openhab.org/v2.3/addons/bindings/k80551/#prerequisites) The device model is different but it’s all I found regarding Velleman.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [November 23, 2018, 10:27pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/5 "2018-11-23T22:27:30Z")

</div>

> [@Jwauters](#):
>
> but the status in openhab must say switch on or off

That part is not going to work unless openHAB has some way to find out if the light is actually on or off. You can construct rules to toggle an Item on and off for each “press” of a button, but that will not stay in step with reality in case of a power cut or someone using a real wallswitch.

This thread might help

> [@Momentary Button state](https://community.openhab.org/t/momentary-button-state/27584):
>
> Hello, everyone. I try to make a push button whose state changes when pressed. The problem is that I press the push button for only 200 milseconds and then go back to the off state. This to do a real push button. So my push button is always off. I want him to change status every time it’s pushd Here are my config files Items Group Verlichting Switch keuken1 “keuken1” { gpio=“pin:17 debounce:10 activelow:no” } Rule rule “keuken1 is a switch” when Item keuken1 received command then …

---

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 24, 2018, 4:42pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/6 "2018-11-24T16:42:01Z")

</div>

thanks ,

but this one is for u usb controlled velleman relay card. the vm201 does not have that.

---

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 24, 2018, 4:46pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/7 "2018-11-24T16:46:58Z")

</div>

rossko57.

I am trying to learn the openhab platform. I know if i don’t connect my push buttons to the openhab platform he will not know the state of the lights. for learning purposes i already want to try if i can toggle the http command for the velleman vm201. regardless the push buttons. if i manage to let this work . i will invest more in learning en spending on hardware to also connect the push buttons in the house.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [November 24, 2018, 7:30pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/8 "2018-11-24T19:30:58Z")

</div>

Example

Items

```csv
// An Item to represent your light and go on your sitemap
Switch myLight "Light state"
// An Item to drive the pulse relay hardware
Switch myPulse "Pulse output" {binding to Velleman channel}

```

Rule

```php
rule "trigger pulse output"
when
	Item myLight changed
then
       // we want to toggle the hardware to match the change of virtual switch
       // so we simulate a button push and release
       myPulse.sendCommand(ON)
       Thread::sleep(200)
       myPulse.sendCommand(OFF)
end

```

---

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 26, 2018, 10:18am UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/9 "2018-11-26T10:18:39Z")

</div>

We are getting closer . Now when i turn it on the lights would go nuts. it repeats the rule over and over 😃

items

Switch Mypulse “Pulse output” {http=“\>[ON:GET:(h)ttp://192.168.2.48/cgi/leds.cgi?led=1:on] \>[OFF:POST:[http://192.168.2.48/cgi/leds.cgi?led=1:off](http://192.168.2.48/cgi/leds.cgi?led=1:off)]”}

rule

rule “trigger pulse output”  
when  
Item Mypulse changed  
then  
Mypulse.sendCommand(ON)  
Thread::sleep(200)  
Mypulse.sendCommand(OFF)  
end

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [November 26, 2018, 11:41am UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/10 "2018-11-26T11:41:17Z")

</div>

> [@Jwauters](#):
>
> Now when i turn it on the lights would go nuts. it repeats the rule over and over

Of course it does. Look at the trigger you have chosen for your rule.

Now look again at the TWO Items I suggested and the rule trigger Item that is different to the rule action Item.

---

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 26, 2018, 11:51am UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/11 "2018-11-26T11:51:52Z")

</div>

i don’t get it what i have to change.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [November 26, 2018, 11:58am UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/12 "2018-11-26T11:58:54Z")

</div>

Make two Items. One is not bound to anything, but this is the one to put into your sitemap as the controlling switch. It will represent the ON/OFF state of your actual light. It will accept commands to turn the light ON/OFF.

The other Item is to be bound to your Velleman relay, and it is to act as the simulated pushbutton. Push for on, push for off. You don’t need or want that in your sitemap.

The rule is to be triggered from the controlling Item.  
When the controlling Item changes, it simulates a push of the button, followed after a little while by releasing the button.

---

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 26, 2018, 1:05pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/14 "2018-11-26T13:05:15Z")

</div>

it works thank you , i made a mistake also with the http it was (h)ttp.

the whole openhab is harder than i tought . i want to control all my push buttons te switch te relays in the main board . ho boy 😮

---

<div class="post-metadata">

**Author:** ![Jwauters](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@Jwauters](https://community.openhab.org/u/Jwauters)\
**Post date:** [November 26, 2018, 6:20pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/15 "2018-11-26T18:20:02Z")

</div>

rossko

can i connect the pulse switches in the wall to the gpio pins of the raspberry pi 2 to controll to read the state?

wall pulse switch pulses gpio pin → command given to item to change UI state → UI commands the velleman relay card to pulse 🙂

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [November 26, 2018, 8:47pm UTC](https://community.openhab.org/t/relay-with-pulse-function-over-http/57650/16 "2018-11-26T20:47:10Z")

</div>

> [@Jwauters](#):
>
> can i connect the pulse switches in the wall to the gpio pins of the raspberry pi 2 to controll to read the state?

I expect so - IF you can disconnect the wallswitch wiring completely from the mains power.  
I’m not sure what the purpose is though? Reading if teh buttons are pressed will not tell you if the lights are on or not.

I don’t think that’s a good idea, because your lights cannot be operated if your openHAB is out of service for whatever reason, or even if you make a mistake in a rule or during an upgrade. There might be safety concerns about being in darkness.

Better to design openHAB as an add-on control system, that still allows ordinary reliable wallswitches as well.
