Controlling a heatpump (newbie)

I have only done very simple light rules before. :slight_smile:

Basically, I want to reduce the start/stops on the heatpump, letting it rest longer periods, and then run longer periods.

I have a separate temp sensor in the room, which is working and updating in basicui without problem:
Number CinemaTemp "Biorum [%.1f °C]" <temperature> (GPersist,GF_Cinema,gTemps) {mqtt="<[broker:/house/energy/01000590_t2:state:default]"}

Then I have my rule;

`rule “Turn on heatpump”

when
Item CinemaTemp received update
then
if( CinemaTemp.state < 18) {
logInfo(“cinema_heat_vent_rule”,“Temp below 18”)
sendCommand( GF_Cinema_Heat_Fan, 3 )
sendCommand( GF_Cinema_Heat_SetpointHeat, 20 )
sendCommand( GF_Cinema_Heat_Thermostat, 1 )
}
end

rule "Turn off heatpump"
when
Item CinemaTemp received update
then
logInfo(“cinema_heat_vent_rule”,“Temp updated”)
if( CinemaTemp.state > 20) {
logInfo(“cinema_heat_vent_rule”,“Temp above 20”)
sendCommand( GF_Cinema_Heat_Thermostat, 0 )
}

end
`

Now, the everything kind of works, but the rule triggers every 18 seconds when the mqtt source pushes the temp. This in turn pushes everything onto zwave, which is not too nice. This is regardless if the temp has actually changed or not.

I know of one solution - adding a dummy switch and use it as memory for having dealt with the temperature crossing, but are there any other solutions? Will a variable survive if I declare it, and how would I then do this?