Unable to save current value thermostat if door is closed again

Dear community,
I struggling with myself - I am trying to create a rule for the heater in the bedroom. So If I open the balcony door in the morning to get fresh air I want to reduce the targetTemperature of the heater thermostat.

In myRules I created a global variable so that I can save the value if I open the door

var Number heaterTemp = null

The code of the two rules open and close look like this:

rule "lower heater in bedroom if door is open"
when
    Item Balkonture_OpenClose changed from CLOSED to OPEN
then
    logInfo("DoorOpenRule", Balkonture_OpenClose.state.toString)
    heaterTemp = HeizkorperSchlafzimmer_ActualTemperature
    logInfo("DoorOpenRule", heaterTemp.state.toString)
    sendCommand(HeizkorperSchlafzimmer_SetTemperature,5)
end

rule "reactivate heater in bedroom when door is closed"
when
    Item Balkonture_OpenClose changed from OPEN to CLOSED
then
    logInfo("DoorCloseRule",Balkonture_OpenClose.state.toString)
    sendCommand(HeizkorperSchlafzimmer_SetTemperature,heaterTemp)
end

I am not able to see the logInfo because the state.toString is not working
If I comment out all the logInfo the rule is running into an issue if I set the temperature back to the one of the var heaterTemp

Why, what does it do instead?

Is that an Item, wouldn’t you be interested in the state?

sendCommand(HeizkorperSchlafzimmer_SetTemperature,heaterTemp)
You can’t command one Item by sending it a whole other Item.

Hi rossko57,
you are right the problem was the item I was calling. I modified the code and now it is working

var Number heaterTemp = 0
rule "lower heater in bedroom if door is open"
when
    Item Balkonture_OpenClose changed from CLOSED to OPEN
then
    logInfo("DoorOpenRule", Balkonture_OpenClose.state.toString)
    heaterTemp = HeizkorperSchlafzimmer_ActualTemperature.state
    logInfo("DoorOpenRule", "The targetTemperature was {}",heaterTemp)
    sendCommand(HeizkorperSchlafzimmer_SetTemperature,5)
end

rule "reactivate heater in bedroom when door is closed"
when
    Item Balkonture_OpenClose changed from OPEN to CLOSED
then
    logInfo("DoorCloseRule",Balkonture_OpenClose.state.toString)
    sendCommand(HeizkorperSchlafzimmer_SetTemperature,heaterTemp)
end