This is another idea how to configure sort of settings to control our lights. In my apartment all the time someone forgets to turn off lights. As I replaced all wall switches with Sonoff Touch Wall switches I tried to figure out new settings section in OpenHAB GUI to set auto-OFF light after certain time.
First let’s create items:
.items
1 2 3 4 5 6 |
//auto off timers Number myTimer_kitchen "Kuchnia OFF [%d]" <time> // no binding needed Number myTimer_bathroom "Łazienka OFF [%d]" <time> // no binding needed Number myTimer_bedroom "Sypialnia OFF [%d]" <time> // no binding needed |
.sitemap
Setpoint
type generates switch with stepping setting. Her every 15 minutes.
1 2 3 4 5 6 7 8 9 10 |
Frame label="Settings" { Text label="Auto OFF timers" icon="time"{ Setpoint item=myTimer_kitchen step=15 minValue=0 maxValue=240 Setpoint item=myTimer_bathroom step=15 minValue=0 maxValue=240 Setpoint item=myTimer_bedroom step=15 minValue=0 maxValue=240 } Group item=Settings } |
.rules
Rules are only for kitchen 2 lights. Once one of the light turn on stopAlarmTimer
is starting for the number of minutes taken from Item myTimer_kitchen.state
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
var Timer stopAlarmTimer = null var Timer stopAlarmTimer2 = null // // rule "Auto off kitchen light 1 after X minutes" when // Member of GF_Kitchen_Ceiling_Lights received command Item sonoffwall5_p1 changed then if ( myTimer_kitchen.state > 0 ){ if (sonoffwall5_p1.state==OFF) { stopAlarmTimer?.cancel stopAlarmTimer = null logInfo("rules","Timer set to 0") } else if (sonoffwall5_p1.state==ON) { if (stopAlarmTimer!=null) { stopAlarmTimer.cancel stopAlarmTimer = null logInfo("rules","Timer reset to 0") } logInfo("rules","Timer executed for " + myTimer_kitchen.state + "m") stopAlarmTimer = createTimer(now.plusMinutes((myTimer_kitchen.state as DecimalType).intValue)) [ | sonoffwall5_p1.sendCommand(OFF) ] } } end rule "Auto off kitchen light 2 after X minutes" when // Member of GF_Kitchen_Ceiling_Lights received command Item sonoffwall5_p2 changed then if ( myTimer_kitchen.state > 0 ){ if (sonoffwall5_p2.state==OFF) { stopAlarmTimer2?.cancel stopAlarmTimer2 = null logInfo("rules","Timer set to 0") } else if (sonoffwall5_p2.state==ON) { if (stopAlarmTimer2!=null) { stopAlarmTimer2.cancel stopAlarmTimer2 = null logInfo("rules","Timer reset to 0") } logInfo("rules","Timer executed for " + myTimer_kitchen.state + "m") stopAlarmTimer2 = createTimer(now.plusMinutes((myTimer_kitchen.state as DecimalType).intValue)) [ | sonoffwall5_p2.sendCommand(OFF) ] } } end // |
final result
Source
https://community.openhab.org/t/turn-light-off-based-on-timer/9558/30
https://community.openhab.org/t/trrying-to-turn-a-device-off-after-a-certain-amount-of-time/36217