Hi, I have to make a simple timed light on a light. So for example, after I launch an On command, it should be turned off after 1 minute.
I made a bell thanks to Expire, but the condition in the file item is fixed. So if I configure a light with expire this light will always be timed. Instead I need both on off and timed.
You will have to use a proxy Item for this, including a rule:
Switch myLight "Light [%s]" { channel="..." }
Switch myLightEx "Expire Light [%s]" { expire="1m,command=OFF" }
rule:
rule "ex light"
when
myLightEx received command
then
myLight.sendCommand(receivedCommand)
end
So you get a one way connection, by switching myLight, the light is switched manually, by switching myLightEx, the light is switched OFF after timeout.
Hi, thanks for the help but it doesn’t work. Once I configure myLightEx Switch “Expire Light [% s]” {expire = “1m, command = OFF”}
do I also have to enter the channel?
I’ve tried both ways but it doesn’t work. I see the 2 Switches but they both do the same function, then off after 1 minute.
What am I doing wrong?
Show us your item defintions, rule, and sitemap
I don’t have a sitemap file. In the example I entered a timing of 1 s.
In paper ui both switches associated with the same light come out but both work simultaneously without distinction.
You’ve both your switch items linked to the same channel. I don’t know why. Follow @Udo_Hartmann example.
If I don’t use the channel then in paper ui I don’t get the timed switch.
Please don’t use Paper UI Control, it’s not meant as a common UI but only for a fast check if Things work as suggested.
Ok I solved, but your example is a little vague.
1-I first created a rule to change the status of the expire switch using a virtual button.
Then I created 2 more rules.
the first Temp on and the second temp off.
The lamp on / off repeats the stao of that expire.
However thanks to your example with a bit of difficulty I solved.
?
items:
Switch myLight "Light [%s]" { channel="..." }
Switch myLightEx "Expire Light [%s]" { expire="1m,command=OFF" }
rules:
rule "ex light"
when
myLightEx received command
then
myLight.sendCommand(receivedCommand)
end
A sitemap (file name demo.sitemap
):
sitemap demo label="Demo sitemap" {
Switch item=myLight
Switch item=myLightEx
}
This will result in two switches at the sitemap (open it by using
http://ip.of.your.openhab:8080/basicui/app?sitemap=demo), the first switch is to switch the light manually, the second is to switch off automatically after one Minute.
OK thanks a lot, your example with sitemap is very clear and works perfectly. Except that I don’t want to use sitemap. I made the following automation with the rules.
When not present at home and the HikVision camera detects an intrusion alarm they must ring the bells at home for 1 minute.
Thanks your example everything worked.
Ah.
The common way would be to use an Item for presence, another for intrusion and a third for the bell. Then do the rule like that:
// Define global vars at top of rules file.
var Timer tIntruders = null // timer for AlarmBell
rule "intruders"
when
Item IntrusionDetection received command ON // Intrusion detected
then
if(Presence.state != ON) { // and not at home
if(tIntruders === null) // timer empty?
AlarmBell.sendCommand(ON) // start bell
tIntruders = createTimer(now.plusSeconds(60), [ | // schedule end of bell
AlarmBell.sendCommand(OFF) // stop bell
tIntruders = null // emptying timer
])
}
end
OK thank you very much