Hiya, I am currently creating some text-based rules in our OpenHAB3-setup to reduce our gas consumption.
The idea is that if a window is open longer than a set amount of time (in this case 2 minutes), the radiator(s) in that room should be set to 4 degrees celcius (which is the lowest setting allowed by our thermostats).
Once the window has been closed it should return to the previous value.
The problem is that I cannot get the previous temperature value stored.
When troubleshooting researching my issue, I found out that variables cannot be used outside the if (âŠ) statement. All my tries to store the variable (time_Buero) into a String item and retrieve it for use have failed miserable however. I created a new âStringâ item and stored value of the time_Buero variable into it by using postUpdate. This worked, however all my tried of extracting the data from the STring item back into the variable failed.
Maybe someone has a similar script that works?
Here is my script (without the storing of data into the variable):
var String time_Buero
var Timer timer_fenster_Buero = null
rule "Heizungssteuerung Buero"
when
Item Fenster_OG_AZ changed
then
logInfo("Heizung", "Fenster BĂŒro wurde bewegt")
if ((Fenster_OG_AZ.state == OPEN)
&& (Heizung_Buero_Setpoint.state != 4|°C))
{
logInfo("Heizung", "Buero Heizung ist an und Fenster wurde geöffnet")
val time_Buero = (ZonedDateTime.now())
logInfo("Heizung", "Heizung BĂŒro wird in 2 Minuten gedrosselt")
logInfo("Heizung", "Wert ist aktuell (" + (time_Buero) +"): "+ (Heizung_Buero_Setpoint.historicState(time_Buero,"influxdb").state.toString))
timer_fenster_Buero = createTimer(now.plusMinutes(2)) [ Heizung_Buero_Setpoint.sendCommand(4) ]
}
else
if (Fenster_OG_AZ.state == OPEN)
{
logInfo("Heizung", "Buero Heizung ist aus und Fenster wurde geöffnet")
}
else
if (Fenster_OG_AZ.state == CLOSED)
{
logInfo("Heizung", "Debug: " + (time_Buero))
logInfo("Heizung", "Buero Heizung ist aus und Fenster wurde geschlossen")
if(timer_fenster_Buero !== null)
{
timer_fenster_Buero.cancel()
timer_fenster_Buero = null
}
logInfo("Heizung", "Heizung BĂŒro wird auf den vorherigen Wert ("+ (Heizung_Buero_Setpoint.historicState(time_Buero).state.toString) +") von " + (time_Buero) + " gesetzt.")
Heizung_Buero_Setpoint.sendCommand(Heizung_Buero_Setpoint.historicState(time_Buero,"influxdb").state)
}
end
Here is the log output when the rule starts (Temperature has been set to a value >4 degrees celcius and the window has been opened):
2022-09-30 16:42:44.950 [INFO ] [rg.openhab.core.model.script.Heizung] - Fenster BĂŒro wurde bewegt
2022-09-30 16:42:44.954 [INFO ] [rg.openhab.core.model.script.Heizung] - Buero Heizung ist an und Fenster wurde geöffnet
2022-09-30 16:42:44.954 [INFO ] [rg.openhab.core.model.script.Heizung] - Heizung BĂŒro wird in 2 Minuten gedrosselt
2022-09-30 16:42:44.964 [INFO ] [rg.openhab.core.model.script.Heizung] - Wert ist aktuell (2022-09-30T16:42:44.954656+02:00[Europe/Berlin]): 10.0
Here is the log if the window is closed before the timer (2 minutes) is expired:
2022-09-30 16:42:47.128 [INFO ] [rg.openhab.core.model.script.Heizung] - Fenster BĂŒro wurde bewegt
2022-09-30 16:42:47.129 [INFO ] [rg.openhab.core.model.script.Heizung] - Debug: null
2022-09-30 16:42:47.129 [INFO ] [rg.openhab.core.model.script.Heizung] - Buero Heizung ist aus und Fenster wurde geschlossen
2022-09-30 16:42:47.133 [INFO ] [rg.openhab.core.model.script.Heizung] - Heizung BĂŒro wird auf den vorherigen Wert (10 °C) von null gesetzt.
Here is the log when the radiator thermostat has been set to 4 degrees celcius by the rule and the window has been closed:
2022-09-30 16:43:30.246 [INFO ] [rg.openhab.core.model.script.Heizung] - Fenster BĂŒro wurde bewegt
2022-09-30 16:43:30.246 [INFO ] [rg.openhab.core.model.script.Heizung] - Buero Heizung ist an und Fenster wurde geöffnet
2022-09-30 16:43:30.246 [INFO ] [rg.openhab.core.model.script.Heizung] - Heizung BĂŒro wird in 2 Minuten gedrosselt
2022-09-30 16:43:30.250 [INFO ] [rg.openhab.core.model.script.Heizung] - Wert ist aktuell (2022-09-30T16:43:30.246404+02:00[Europe/Berlin]): 10.0
2022-09-30 16:45:30.252 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Heizung_Buero_Setpoint' received command 4
2022-09-30 16:45:30.256 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Heizung_Buero_Setpoint' predicted to become 4
2022-09-30 16:45:30.263 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Heizung_Buero_Setpoint' changed from 10 °C to 4 °C
2022-09-30 16:45:58.144 [INFO ] [rg.openhab.core.model.script.Heizung] - Fenster BĂŒro wurde bewegt
2022-09-30 16:45:58.144 [INFO ] [rg.openhab.core.model.script.Heizung] - Debug: null
2022-09-30 16:45:58.144 [INFO ] [rg.openhab.core.model.script.Heizung] - Buero Heizung ist aus und Fenster wurde geschlossen
2022-09-30 16:45:58.147 [INFO ] [rg.openhab.core.model.script.Heizung] - Heizung BĂŒro wird auf den vorherigen Wert (4 °C) von null gesetzt.
2022-09-30 16:45:58.160 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'heizungbuero-1' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null in heizungbuero