Can someone give me an example on how to turn off a wifi plug/socket after x minutes?
I am using openhabian
I want to be able to do the following:
In the GUI on Classic UI or in the iOS/Android app, I want to be able to turn on the wifi plug and it should turn off after the number of minutes set in the GUI
This is currently my approach:
my rule:
var Timer myTimer = null
rule "my auto off rule"
when
Item WLanSteckdoseBRo_Switch changed
then
if (WLanSteckdoseBRo_Switch.state==OFF) {
myTimer.cancel
myTimer = null
}
else if (WLanSteckdoseBRo_Switch.state==ON) {
if (myTimer!=null) {
myTimer.cancel
myTimer = null
}
myTimer = createTimer(now.plusMinutes((myMinutesSteckdose.state as DecimalType)).intValue) [| //use now.plusSeconds() for testing
WLanSteckdoseBRo_Switch.sendCommand(OFF)
]
}
end
2017-12-16 18:24:41.903 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘my auto off rule’: An error occurred during the script execution: Could not invoke method: org.joda.time.DateTime.plusMinutes(int) on instance: 2017-12-16T18:24:41.901+01:00
@KidSquid but using the expire he hasn’t got the possibility to use a setpoint item to change the expiration time from a sitemap, correct?
@salexes
I do have something similar. I’ve got two valves for watering my garden. I can enable the irrigation via a switch in the sitemap and by using setpoint items I can configure the time the valves should be open.
My item (sorry for mixing german and Englisch - i need to get rid of that soon )
Number VentilHochbeet_Delay "Abschaltung Hochbeet [%d min]"
Number VentilJohannisbeeren_Delay "Abschaltung Johannisbeeren [%d min]"
The two setpoint items are for defining the time my valves should be closed.
The first Item enables the whole irrigation.
And finally my rule:
rule "Bewaesserung"
when
Item Gartenbewaesserung received command
then
if(receivedCommand==ON) {
var Ventil1_Delay = VentilHochbeet_Delay.state as DecimalType
var Ventil2_Delay = VentilJohannisbeeren_Delay.state as DecimalType
logInfo("Gartenbewaesserung","Bewaesserung gestartet")
createTimer(now.plusMinutes(Ventil1_Delay.intValue)) [
sendCommand(VentilHochbeet_Switch, OFF) //item created via PaperUI
logInfo("Gartenbewaesserung","Ventil Hochbeet - Aus")
]
createTimer(now.plusMinutes(Ventil2_Delay.intValue)) [
sendCommand(VentilJohannisbeeren_Switch, OFF) //item created via PaperUI
logInfo("Gartenbewaesserung","Ventil Johannisbeeren - Aus")
]
}
else if(receivedCommand==OFF) {
logInfo("Gartenbewaesserung", "Deaktiviert durch Benutzer")
sendCommand(VentilHochbeet_Switch, OFF)
sendCommand(VentilJohannisbeeren_Switch, OFF)
}
end
This was working the whole summer.
The only difference imho is that i’n using additional variables for storing the numbers of the setpoint items in my rule.
Have you set up a persistence service?
If not, myMinutesSteckdose is not initialized after reboot of openHab and therefore you either need to set up a persistence service or you check the value against null in your rule.