I need a bit of help with a problem.
I have successfully connected a Relais Board in Openhabian2 and can switch the Relais on and off.
However one Relais should only give a short Impuls (switched on for 0,5 Seconds or less) in order to activate a device begind it.
The Relais are defined as follows within the “Relais.Items” File
The Rule is so far set as follow. (Test with 2 Seconds)
import time
var timeout = 2 // sec
Rule "RELAIS2 auto aus"
when
item RELAIS2.state == "ON"
then
createTimer(now.plusSeconds(timeout))
[| RELAIS2.state == "OFF"]
end
let me recap this quickly: you have a device that should be triggered by a relais. It is triggered when the relais is turned on for a short interval (for example 0.5 seconds). Your problem right now is, that you only have commands to turn the relais on or off. Is this correct?
In case it is: Have you considered using a trigger channel to send a short impuls? I guess you can send the “on” - signal (maybe adress another channel for this. I don’t know your device nor your channels or items) when the trigger is pressed, and the “off” - signal, when the trigger is released. If I’m correct it should act like a virtual switch…
Your first rule could not work, because the when part is a state. It must be an event.
Your first rule could not work, because Relais2 and RELAIS2 are different Items. OpenHAB is case sensitive.
Second rule getting closer - it’s triggered by an event.
But if you want to send a command to a GPIO pin, then you need to send a command. A postUpdate does not send a command to the GPIO.
The sendCommand part you do have is mangled, unwanted ==, missing bracket etc.
The expire binding minimum “pulse” is 1 second and the OP wants 500ms even though there is a 2s timer in the rule.
NO IMPORTS NEEDED
val relay2timeout = 500 // 500 ms
rule "RELAIS2 auto aus"
when
Item RELAIS2 changed to ON
then
createTimer(now.plusMillis(relay2timeout), | [
RELAIS2.sendCommand(OFF)
])
end
Thank you all for the suggestions. @TheTmirror
I have read about virtualk switches there but never found an example. I started this whole experiment 1 week ago as a total newbie.
I have now 8 Relais 2 Onewire Temperature sensors with a Graphana graph etc. So i made good progress and was happy.
But at this im stuck
The Expire binding is installed.
I tried now the Rule from vzorglub and still no success, the Relais stays on.
In the future i want to user othger relays to automativcally be activated in events so the actual timer in this case is not that important. (except if there are problems below 1 sec)
The problem here might be that there is Relais2 and RELAIS2 and im not sure which one had to be used as name in the rule.
The item name is relais2
The item label is "RELAIS2"
val relay2timeout = 500 // 500 ms
rule "RELAIS2 auto aus"
when
Item Relais2 changed to ON
then
createTimer(now.plusMillis(relay2timeout), | [
Relais2.sendCommand(OFF)
])
end
Hi Vincent.
I think I am missing something.
I don’t want to high jack the topic?
My rule :
val relay2timeout = 500 // 500 ms
rule "RELAIS2 auto aus"
when
Item Arm_away changed to ON
then
createTimer(now.plusMillis(relay2timeout), | ([
Arm_away.sendCommand(OFF)
])
end
I tried to get the log. as I am not sure what is wrong. it keeps on saying expecting a ) or end ?
and then just ignores the rule
what am I doing wrong
Removed the bracket at beginning of timer lambda
Forced the relay2timeout type to int as the .plusMills() methad only accept int as argument (Just in case)
val int relay2timeout = 500 // 500 ms
rule "RELAIS2 auto aus"
when
Item Arm_away changed to ON
then
createTimer(now.plusMillis(relay2timeout), | [
Arm_away.sendCommand(OFF)
])
end
With Different timing attributes in them ?
This Rule Looks after 4 Relays that activates Contacts on a modified Alarm Remote.
and some of the contacts might need a shorter or longer press simulation.