Check External Website Status - Hab Panel

Hopefully someone can help me out, or point me in the right direction.

I’m blocking YouTube domains between certain hours of the day / night.

So I’m after something simple display ON or OFF for any one of these Domains on my Hab Panel.
Something similar to Network Binding, but for responses from external websites, & not limited to IPs or ports.

Unfortunately pings sent to the YouTube hostname, or to it’s IP, will always reply even when the domains are blocked. So my item is always “on”.

I’ve been trying to come up with a curl solution, or something to give me a response about the HTTP status code, but I just can’t get the outcome I’m after.

Please help!

Tell a bit more details about how you block the domains.
Are they being blocked in a way that DNS does not come back ( does not sound like it as you can ping them ) ? How does a browser behave in case they are blocked ?

You may try something like:

curl -o /dev/null -s -w "%{http_code}\n"

Which returns:


You can use this in a rule; evaluate the returned status code and based on the value set the ON/OFF status.

Can you interrogate whatever service is being used here to find out whether the required domains are blocked?

I’m using OpenDNS to filter domains based on defined rules.

Some devices in the household point to the OpenDNS addresses to use for DNS.

When the block is in place, YouTube (in this case) responds & tries to load, but the page will return an error or the content won’t load.
Though the IP addresses for the domains will still reply to pings.

I’ve tested curl commands & the HTTP headers for YouTube do change during the block / to outside the block period, but I’m not skilled enough to write something around that for OpenHAB.

Could you elaborate a bit on your example?
How can I trigger the response to react as an On / or Off?
I’m still pretty new to OpenHAB, sorry.

Try something like:



RET=`curl -o /dev/null -s -w %{http_code}`

if [ $RET -eq 403 ]
        curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://$openhab_ip:8080/rest/items/$openhab_item"
        curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://$openhab_ip:8080/rest/items/$openhab_item"

Code is not 100% tested but based on code I use in OH2 environment.
It is expected to get 403 code back in case OpenDNS blocks a page. Which is the case for some trials I did.
The above code could be entered in a shell script which is called from executeCommandLine in a rule. The rule could be executed a specific times ( short after your opendns rule is updated ) or every n-th minute/hour.

My OpenHab is running from a Windows machine. Will your example still execute properly?

Im getting no changes on a switch item.
And I get “NULL” displayed on a dummy item.

If I run curl -o /dev/null -s -w %{http_code} http://website during block hours on my Mac, I am getting 403.

And if I run it using the path to Curl on my OpenHab windows machine, being c:\curl\bin\curl.exe -o /dev/null -s -w %{http_code} http://website, during block hours, then I also get 403

Try first to construct the curl command by going to the REST API on your OH instance:
check for the: POST /items/{itemname}
there you can use your real item and switch it ON/OFF. Once that is working you can use the comand in a script.

I can’t seem to get to http://openhab_ip:8080/#!/developer/api-explorer
It just re-loads the landing page for choice between Basic, PaperUI, or HabPanel

But if I load http://openhab_ip:8080/rest/items/openhab_item I can see an output, which has the details of the item

Am I missing a step to do with rest api?

I was thinking you use OH3 instead of OH2. This is why the mentioned link does not work.
Instead of http://openhab_ip:8080/#!/developer/api-explorerplease use http://openhab_ip:8080/doc/index.html