- Platform information:
- Hardware: Raspberry Pi 3
- OS: Raspbian
- Java Runtime Environment: build 1.8.0_65-b17
- openHAB version: 2.3.0
- Issue of the topic:
Hello, I just recently started with Openhab for a class project, I’m totally new in this so I apologize in advance if the code is hard to read or if there’s some huge/easy to spot mistakes.
What I’m trying to do is to activate blinders based on luminance. I have a relay with 3 switches, one ups the blinder, one downs it and the other does apparently nothing.
My problem is the following: I’m trying to make it so the switches that activate the blinders, deactivate after 20 seconds (which is approximately the time that it takes the blinder to go full down and full up). My reasoning for this is that if you activate the switch that downs the blinder for example and it stays on, when you try to get up the blinder it won’t work because the “down” switch is already activated, so there’s a conflict. That’s why I want them to be turned off after 20 seconds.
I wrote some rules to make this work, and it works perfectly for the “down” switch, once it’s activated and 20 seconds pass, it deactivates. BUT the same doesn’t happen to the “up” switch, I’ve checked for errors, checked the logs, tried to do a couple of workarounds but couldn’t do it.
I’ll leave the code here, feel free to tell me how to improve it even if it doesn’t directly approach my problem, I’m very interested and invested in this, and please do tell me if you need more info or if something about this post is wrong. Oh, and sorry, some parts of the code are in Spanish since that’s where I’m from. I wrote some comments to try to clear some things up.
//Declaring vars for the timers
var Timer TempBajada = null
var Timer TempSubida = null
// The purpose of this rule is to down a blinder when it's below 50 luminance and to get it up when it's above 50 luminance
rule "Subir y bajar persiana"
when
Item ZWaveNode2ZW100Multisensor6_SensorLuminance changed
then
if (ZWaveNode2ZW100Multisensor6_SensorLuminance.state <50) {
ZWaveNode12ZMNHBDFlush2Relays_Switch.sendCommand(ON)
}
if (ZWaveNode2ZW100Multisensor6_SensorLuminance.state >50) {
ZWaveNode12ZMNHBDFlush2Relays_Switch2.sendCommand(ON)
}
end
//The purpose of this rule is to turn off the switch 20 seconds later of being switched on, so that other orders can be issued later
rule "Apagar switch bajada"
when
Item ZWaveNode12ZMNHBDFlush2Relays_Switch changed to ON
then
if (TempBajada === null) {
TempBajada = createTimer(now.plusSeconds (20))[
ZWaveNode12ZMNHBDFlush2Relays_Switch.sendCommand(OFF)
]
}
end
//Same thing as before but for the get blinder up switch
rule "Apagar switch subida"
when
Item ZWaveNode12ZMNHBDFlush2Relays_Switch2 changed to ON
then
if (TempSubida === null) {
TempSubida = createTimer(now.plusSeconds (20))[
ZWaveNode12ZMNHBDFlush2Relays_Switch2.sendCommand(OFF)
]
}
end