My openHAB system has been working a treat. It does everything I need but now I need to add a new rule, which I’m having difficulty with. I’ve seen online other people have asked about the same rule I’m about to mention but I couldn’t see/understand the answers they were given.
Every few months my router needs a reboot to get it going again. It happened over the weekend and I figured it’s time I did someting about it.
Basically I want to ping various websites and if they can’t be reached I want my Z-Wave plug to switch off, wait a few minutes and switch back on…sound simple enough…
This is the rule I have to test my logic:
//Internet Is Down. Don't Panic
rule "Internet Is Down"
when
Item FF_Hallway_Light changed from OFF to ON
then
zwave_device_90b5462f_node3_switch_binary.sendCommand(OFF)
InternetIsDown.sendCommand(ON)
end
//Switch The Router Back On
rule "Turn The Internet Back On"
when
Item InternetIsDown changed to OFF
then
{
zwave_device_90b5462f_node3_switch_binary.sendCommand(ON)
}
end
For my testing I’ve used my Hallway switch to trigger the rule. It works perfectly, the switch turns off and after the timer has expired the switch turns itself back on.
All I need to know is what do I need to replace “Item FF_Hallway_Light changed from OFF to ON” with?
I have already added networkhelth.cfg file to my services:
nh=“www.google.com:80”
And I have added a switch to my items section:
Switch Network_GoogleWebsite “Google” (Status, Network) { nh=“www.Google.com:80” }
Sorry if this is an easy question, I just can’t get my head around it.
Thank you in advance for all your help and time
Ben
Use the Network binding. This replaced the Network Health binding years ago.
Configure a Thing to ping the URLs you want to ping. Link the Online Channel to a Switch Item (based on the names of your zwave Items it looks like you are using Simple Mode so an Item will probably be created for you). Use that Item changing to OFF as the trigger for your Internet Is Down Rule.
This is what I have now done…
In things I have created a file called Network.thing and added this line to the file:
network:device:devicename [ hostname="8.8.8.8, port=0, retry=1, timeout=5000, refresh_interval=60000, use_system_ping=“false”, dhcplisten=“true” ]
I have then added a Switch to my items file:
Switch InternetOnline { channel=“network:device:devicename:online” }
Finally I have changed my rule and added:
Item InternetOnline changed to OFF
So the rule now looks like this:
//Internet Is Down. Don’t Panic
rule “Internet Is Down”
when
Item InternetOnline changed to OFF
then
zwave_device_89b5462f_node3_switch_binary.sendCommand(OFF)
InternetIsDown.sendCommand(ON)
end
I then restarted my router to see if that would cause the plug to switch off but nothing happened. Obviously I’m missing a vital step.
Host 8.8.8.8 doesn’t listen on port 0. I don’t use nor recommend the use of .things files so I can’t help with the syntax, but according to the docs you should be defining either a pingdevice which doesn’t take a port at all or a servicedevice which does require a port and it has to be a valid port that is open on the host device you are pinging.
What version of the docs are you looking at? Do they correspond with the version of OH you are running? The configuration you are trying to use does not look anything like the way the binding readme says you should be defining it. (Hence why I recommend against .things files, you can’t get the syntax wrong through autodiscovery or defining Thing through PaperUI).
Comparing to your configuration you omitted the ‘Thing’ at the beginning of your line. Next to that I would recommend to start with a simple line, not adding all the additional commands.
I’ve now added Thing to the start of the line (good spot Maurits).
The I thought I’d force the rule to run every minute to see if that was the problem.
My rule now looks like this:
//Internet Is Down. Don't Panic
rule "Internet Is Down"
when
Time cron "0 0/1 * * * ?" // every minute
then
if
Item (InternetDown !== OFF)
{
zwave_device_90b5462f_node3_switch_binary.sendCommand(OFF)
InternetIsDown.sendCommand(ON)
}
end
But now when I save it I’m getting this error:
2019-11-26 18:17:49.928 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘InternetDown.rules’ has errors, therefore ignoring it: [8,2]: mismatched input ‘Item’ expecting ‘(’
[8,8]: no viable alternative at input ‘InternetDown’
I really thought this would just be simply replacing the light switch trigger with a ping time out but it looks like it’s more involved than that.
There is no need to run the Rule every minute. The Item will be updated every minute (or how often you configure the Thing to update). And what will running the Rule every minute prove? If the Item isn’t updating, checking it every minute isn’t going to change anything.
If all you’ve changed was adding Thing to the start of your Thing definition than you have missed the point. Your entire Thing definition is wrong. Copy Mauritis’s Thing exactly as he posted it.
This is all really basic openHAB stuff. You have a binding. You properly configure the Binding’s Things. You link the Things to Items. You trigger Rules based on events on the Items.
The root problem, given the information posted thus far, is that you are using everything but the documentation for the Network binding to try to create the Thing definition.
//Internet Is Down. Don't Panic
rule "Internet Is Down"
when
Item MyDevice changed to OFF
then
zwave_device_90b5462f_node3_switch_binary.sendCommand(OFF)
InternetIsDown.sendCommand(ON)
end
Does this look OK so far? Is there a step I am missing?
that means the item was linked to the channel successfully
I think what Rich is looking for here is when the the item MyDevice changes to off, you should see an entry in the log telling you the item has changed