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)
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.
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
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.
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 ifelse if and else. I’m not the best rules writer and keep this link bookmarked. Hope you find it helpful.
There are also some other good tutorials on the left side of the page.
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
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. 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.
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.