GOAL: Press a button on HABPannel that sends a shutdown command to Kodi running on a Windows machine the rule needs to wait for around two minutes for the machine to shutdown before finally turning off the socket that powers the machine
You change the state of an Item from HABPanel that is used to fire a rule.
Create an item (e.g. a Switch) that is not bound to anything but is used just to keep a state.
Map this Item on your HABPanel (on a Switch Widget) and turn it On/Off from there.
Then in your rule:
var Timer Kodi_Timer = null
val Integer Kodi_TimeOut = 2 //in minutes since the rule uses "now.plusMinutes"
rule "Shut Down Kodi !"
Item HABP_Switch changed from ON to OFF //this is your HABPanel Switch
logInfo("Kodi_Down", "Shutting Down Kodi !")
Win_Host.sendCommand(OFF) //this will cover the first shutdown step (for the Win machine)
Kodi_Timer = createTimer(now.plusMinutes(Kodi_TimeOut))
Power_Outlet.sendCommand(OFF) //this will cover the second shutdown step (for the power outlet)
Kodi_Timer = null
One option is the createTimer method as displayed in the rule example above.
There is also the “sleep” option but it’s not really recommended for your case (long timeout). (check @rlkoshak’s post here: Link)
Extra hint: You could bind your HABPanel switch to the same config as the Win_Host Item and do step 1 (send the shutdown command to the Win host) when you turn off the HABPanel Switch (and fire the rule at the same time). Then, just create the Timer and after it expires, the rule will send the 2nd command to the 2nd item.
Another Idea to trigger the switch off would be to use the network binding. If the machine isn’t online switch the power off (after a while…). this way you would avoid data loss if the power down of kodi is somehow delayed.
I’m sorry dim I still don’t understand what you have sent to me I’m learning as fast as I can I will keep reading over it and see if it makes more sense it did help me to trigger a rule from within Habpannel thanks for that I now understand how to do that
Could you Maby explain more simply how to create timer event (I know what you sent me is already simple I just don’t understand)
you seem to have created your rule in the web interface (PaperUI) - this is one way that is meant to be user friendly.
However, I prefer to use a rules file. I am also a beginner here. If you installed openhab on a linux machine (including raspberry Pi) then you should be able to ssh into that machine and access all the files. Type:
this will show you all the crucial folders in your openhab installation. Type:
You will now be in the rules folder and see any files already in there. You will probably have a file with extension .rules in there or you can make as many of these as you like in that folder. They all get read by openhab if they have the extension .rules
sudo nano Kodi.rules (or anything .rules if you want to just use one fie for all rules)
Sounds like you are progressing fast! You should not need to restart. Now if you migrate to another platfom, you can keep these files that you create.
On my linux system i can not have spaces in the file name. Not sure about windows. It will also not appear as a rule in paperui
Make sure your item names are exactly the same as in paperui. If you want to see if your rules file is loading then look up the rules section in openhab documentation and put some simple lines in that you know will work
I know very little about programming also but I would encourage you pursue as it will boost your learning. I shall try to explain:
If your file ends in .rules and is in your openhab config folder then it will run the code
rules start with a name (rule “Shut Down Kodi !”)
and end with an end (end)
In between these lines is where the magic happens:
When (something happens)
Then (do something)
in your case:
Item HABP_Switch changed from ON to OFF
HABP_Switch is the name of your dummy item that you need to make and will be the item (switch) that you use
Win_Host is the name of the item that turns ON/OFF your Kodi
Power_Outlet is the name of the item that controls your power outlet swtich
EVERYTHING is an item in openhab.
var Timer Kodi_Timer = null
val Integer Kodi_TimeOut = 2 //in minutes since the rule uses “now.plusMinutes”
The above just declares variables that will be needed to run your specific rule
My advice to you would be to experiment and understand items and then create some simple rules