[SOLVED] Last rule I need to make this fully autonomus

Hi Guys

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 :frowning: so an Item will probably be created for you). Use that Item changing to OFF as the trigger for your Internet Is Down Rule.

Thank you for the quick reply.

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. :persevere:

Discover the events.log , which shows you what your Item is doing (if anything). Then you’ll have better idea of what to look into.

Hi Rossko57

I’ve been looking at my event log and it doesn’t seem to be pinging anything!
I think I’m missing a trigger to first set it off.

Ben

Okay, so the rule is of no interest yet. We only know what you tell us.

Have you installed the network (version 2.x) binding? Any messages from that in openhab.log?

I’ve installed network binding. It looks like it’s installed successfully, no error messages.

Maybe I need to reboot my Pi

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).

I’ve just been looking here https://www.openhab.org/docs/configuration/ and searching Google.

I think I’ve been reading old posts and trying to copy the information. Probably where I’m getting confused.

I use this *.thing configuration to ping google.com. Works like a charm.

Thing network:pingdevice:internet [ hostname="www.google.com", retry=4]

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.

2 Likes

I’m getting myself is a right mess now. :worried:

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.

Thank you for all your help/time.

Ben

That’s because your Rule makes no sense.

What is

Item  (InternetDown !== OFF)

supposed to mean? Do you mean

if(InternetDown.state != OFF)

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.

You know what the problem was. Your Item wasn’t working. Is it working now? Look in events.log . Changing the rule won’t make your Item work.

I think we are almost there…I’ve saved everything down and I’m no longer getting errors. But it’s still doesn’t appear to be working.

Here’s what I have so far:

Thing

Thing network:pingdevice:internet [ hostname="www.Google.com", retry=4]

Item

Switch MyDevice { channel="network:pingdevice:internet:online" }

Rule

//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?

So far it looks OK. The capital “G” in the URL is different but probably not a problem. I don’t think DNS is case sensitive.

What does events.log say is going on with MyDevice?

This is what appeared in the event log when I saved the MyDevice.items file:

2019-11-26 21:43:04.454 [.ItemChannelLinkAddedEvent] - Link 'MyDevice-network:pingdevice:internet:online' has been added.

Is that what was expected?

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

I’ve just unplugged the phone line from my router, rather that reboot it. I’ve been watching the logs and it hasn’t updated.

It looks like it isn’t trying to ping google. Should I not have added a time somewhere? Asking it to ping every 5 minutes or so?

The default refreshInterval is a minute. Put MyDevice on your sitemap or query it’s current state using the REST API.