Soron
(Jan)
December 18, 2018, 3:44pm
1
Hi Guys,
i need again your help. Im trying to figure out how to activate a Relay daily at a specific time then have it running X seconds and then turn off.
Relais3 is the item in question here.
Now i need the starting condition (here Time) but i dont know if this works or if a cronjob has to be done here.
My code so far is:
rule “Relais off”
import Time
when
Time(16:31)
then
Relais3.sendCommand(ON)
createTimer(now.plusMillis(10000), [|
Relais3.sendCommand(OFF)
])
end
Hope you can help me out here.
Maurits28
(Maurits)
December 18, 2018, 3:51pm
2
You should use a cronjob to switch it on, and another rule with a cronjob to switch it off, or you use a timer. Maybe also the expire binding could help you.
Read the docs and good luck!
H102
(CM6.5 H102)
December 18, 2018, 4:33pm
3
@Soron Rule to run every day at 16:31
rule “Relais off”
when
Time cron "0 31 16 ? * *"
then
Relais3.sendCommand(ON)
createTimer(now.plusMillis(10000), [|
Relais3.sendCommand(OFF)
])
end
vzorglub
(Vincent Regaud)
December 19, 2018, 7:42am
4
Please
See:
Read the docs before asking questions, please!!
H102
(CM6.5 H102)
December 19, 2018, 2:52pm
5
After reading the doc’s if your still not sure about the rule with a timer here is a working example. You needed to create the var Timer like below.
var Timer startTimer = null
rule “Relais off”
when
Time cron "0 31 16 ? * *"
then
Relais3.sendCommand(ON)
startTimer = createTimer(now.plusMillis(10000), [|
Relais3.sendCommand(OFF)
startTimer = null
])
end
Also, here’s a link that will help with writing rules. Lots of examples and explanations.
Please see Design Pattern: What is a Design Pattern and How Do I Use Them for details on what a DP is and how to use it.
Problem Statement
Do Not Repeat Yourself (DRY)
Often an inexperienced programmer will find that a naive and straight forward approach to writing Rules DSL Rules results in a lot of duplicated code. Often experienced programmers find that the usual tools to avoid duplicated code like data structures and classes are not available in Rules DSL and they end up fighting the lang…
Soron
(Jan)
December 19, 2018, 2:54pm
6
Thanks H102 so far that works.
Now to the real problems begin.
1.) I need to make the time variable so I can set it myself in openhabpanel
2.) and also adjust the timer how long it will stay on.
Any suggestion will be greatly appreciated.
H102
(CM6.5 H102)
December 19, 2018, 3:02pm
7
Search the forum to see if this has been done before. If you can’t find what your looking for then start a new topic.