[SOLVED] Help with rules heating boost timer

Hello need a bit of help finishing off a rule for adding a boost to my heating rules

First rule that will take a value from habpanel and use it a timer

rule “Heating_T”
when
Item GHeating_T received command ON
then
var Number Heat_T = Heating_Timer.state as Number
var Count = Heat_T
while(Count >= 0) {
Heating_Timer.postUpdate(Count)
Count = Count - 1
if (Count <= 0) {
GHeating_T.sendCommand(OFF)
Heating_Timer.postUpdate(Heat_T)
}
Thread::sleep(60000)
}

end

second rule to turn heating on from a temp setpoint

rule “Heating”
when
Item GF_Hallway_Heating changed or
Item GHeating_T changed
then
var Number house_heat = GF_Hallway_Heating.state as Number
var Number heat_setpoint = Heating_SP.state as Number
val Number offset = 0.5
if(house_heat >= (heat_setpoint + offset)) {
GPIO_Heating.sendCommand(OFF)
}
else if(house_heat < (heat_setpoint - offset)){
GPIO_Heating.sendCommand(ON)
}
end

would like to know how to add in the GHeating_T tag so if it on it would turn on the GPIO_Heating.sendCommand(ON) in second rule

else if(house_heat < (heat_setpoint - offset)) or GHeating_T = ON {
GPIO_Heating.sendCommand(ON)

Thanks for any help Stuart

First of all, replace your first rule with this:

rule "Heating_T"
when
    Item GHeating_T received command ON
then
    var int Heat_T = {Heating_Timer.state as Number}.intValue
    createTimer(now.plusMinutes(Heat_T), [ |
            GHeating_T.sendCommand(OFF)
            Heating_Timer.postUpdate(Heat_T)
    ])
end

You are running a long, potentially very long while loop and during that time, the rule monopolises 1 thread and you only have 5 in total to run openHAB
This new rule is very simple, it converts Heating_Timer to an int
That’s because .plusMinutes(x) takes int as arguments

Then we create a timer that will execute from now plus Heating_Timer minutes.
The body of the timer contains the instructions you want to happen at that time.

Please refer to:

Your second point:

else if(house_heat < (heat_setpoint - offset)) || GHeating_T.state == ON {
    GPIO_Heating.sendCommand(ON)

But please use indents in your rules so that they can be read easily:

rule "Heating"
when
    Item GF_Hallway_Heating changed or
    Item GHeating_T changed
then
    var Number house_heat = GF_Hallway_Heating.state as Number
    var Number heat_setpoint = Heating_SP.state as Number
    val Number offset = 0.5
    if (house_heat >= (heat_setpoint + offset)) {
        GPIO_Heating.sendCommand(OFF)
    } else if (house_heat < (heat_setpoint - offset) || GHeating_T.state == ON) {
        GPIO_Heating.sendCommand(ON)
    }
end
1 Like

thank you
just testing now did just copy and paste from VS code but must have lost indents sorry about that

There are two cultures about indents.
Some people use tabs and some people use spaces.
I use spaces (4), this way it remains the same across different editors and when copying and pasting.

rule "Heating"
when
    Item GF_Hallway_Heating changed or
    Item GHeating_T changed
then
    var Number house_heat = GF_Hallway_Heating.state as Number
    var Number heat_setpoint = Heating_SP.state as Number
    val Number offset = 0.5
    if (house_heat >= (heat_setpoint + offset)) {
        GPIO_Heating.sendCommand(OFF)
    } else if (house_heat < (heat_setpoint - offset) || GHeating_T.state == ON) {
        GPIO_Heating.sendCommand(ON)
    }
end

need to add in a and GHeating_T.state == ON

if (house_heat >= (heat_setpoint + offset)) and (GHeating_T.state == OFF) {
GPIO_Heating.sendCommand(OFF)
other wise it just turns it off because of the elseif statement but may just re write it the other way round did try a new if statement but didn’t work like that

Here’s a link I use to help with when to use if else if and else. I’m not the best rules writer and keep this link bookmarked.:wink: Hope you find it helpful.
https://www.w3schools.com/js/js_if_else.asp

There are also some other good tutorials on the left side of the page.

thanks for the link it will help a lot :smile: just redoing code atm

See:

    if (house_heat >= (heat_setpoint + offset) && GHeating_T.state == OFF) {

it was the && that ii needed for that expression but i have broke openhab and cant access the panel or samba server so doing a fresh install on new memory card so will be a couple of days before i get everything back up and running just trying to access old memory card file for all my configs

If you can connect via ssh you can use openhab-cli to make a backup.

sudo openhab-cli backup --full

Then you have to find a way to move the file to somewhere other than the SD card. If no samba then try using FileZilla for the transfer. The backup can be found in /var/lib/openhab2/backups

thank you have ssh access just put the memory card in to pc and was using diskinternals to read the card but will do the back up and see if that works better
i think when i changed the heating boost plusMinutes to plusSeconds while it was running it broke it

To restore the backup:

Place the backup zip file into the backups folder 
then,
sudo systemctl stop openhab2.service
openhab-cli restore /path/to/zipped/backup (var/lib/openhab2/backups)
sudo systemctl start openhab2.service

Also, you may need to change the backup file permissions to transfer it, so if you hit that snag just use sudo chmod a+rw backups. Another thing you can try when making the backup is not use sudo just openhab-cli backup --full but I can’t guarantee that it works without sudo.

That shouldn’t have caused OH to fail.

After you have the backup moved to another location I would try cleaning the cache and reboot.

sudo systemctl stop openhab

sudo openhab-cli clean-cache

sudo reboot

This may fix your issue but I always recommend making a backup and do so often.:wink: Also good to keep several of them on hand in the event a recent backup is corrupted and you need one from a few weeks/months back.

thanks got the back up on my pc now just clearing cache and rebooting samba came back on but not the habpanel

after reboot no hab panel and started service again so will go for a fresh install and just put all my config files back in
thanks for the help tho

Did you see any error messages in the logs? Not sure how long you’ve waited since rebooting but when clearing the cache everything takes a few extra minutes to start up as the tmp file was also cleared.

log not loading but can see mqqt msgs being written on main login screen

This site can’t be reached

192.168.1.144 refused to connect.

ERR_CONNECTION_REFUSED

Looking like the SD card may be corrupt.:hushed:

Maybe try cloning the SD card as alternate backup then install a fresh OH image then restore the backup.

Here’s one way to clone, but there are a couple ways you can do it.

Redone system thanks for help rules work great :smile: