Myopenhab connection state

Tags: #<Tag:0x00007fe73610a9a8>

All,

I recently had issues of Alexa not beeing able to connect to OH through myopenhab.org.
So I would like to monitor the connection state.
What’s the easiest way to “read” the state out of myopenhab.org.
https://myopenhab.org/events?source=openhab

I tried the URL above with http binding and Basic authentication, but myopenhab.org still asks for authentication.

Is there an easy way to get ONLINE / OFFLINE state of myopenhab.org to my OH instance at home?

Thank you, @sihui
The general online state of myopenhab.org was not what I meant.
I monitor this with {channel="network:servicedevice:myopenhab:online"}

What I was after is the state displayed in my myopenhab.org events:


So the actual connection state between myopenhab.org and my raspberry pi with OH.

Okay :slight_smile:
Did you also try the base64-encoding?

No I didn’t - thanks.
But instead I tried it with curl:
curl -u "username:password" https://myopenhab.org/events

In this case it should work anyway right?
But I get:
Found. Redirecting to /login

I am only using cURL to send commands to my electric car, no idea how this may work for reading stuff.

Thanks fior your help.
I usually use curl quite a bit.
for instance the query the temperature at the location of my car to trigger the heater if needed:
curl -s http://api.openweathermap.org/data/2.5/weather?lat=...
That’s working fine.

1 Like

Almost the same here :slight_smile: (Renault ZOE)

1 Like

:slight_smile:
By the way, when trigegring a switch I use nowadays the http binding instead of curl:
{http=">[ON:GET:http://192.168.68.34:...}] >[OFF:GET:http:...

Yeah, I was thinking about that, too. But I will wait for the http2 binding to not have double the work :slight_smile:

right - almost forgot.
I am desperately waiting for it either :slight_smile:

I am not using the myopenhab.org cloud but the local cloud so it cold be that the following script needs to be adapted to work with the public cloud. At least I used /events?source=openhab to test it with the local cloud.


!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
use WWW::Mechanize::FormFiller;
use URI::URL;

my $BASEURL     = 'https://myopenhab.org';
my $USER        = 'YourUserAccountHere';
my $PASSWORD    = 'YourPasswordHere';

my $LOGINURL    = $BASEURL . '/login';
my $ONLINEURL   = $BASEURL . '/events?source=openhab';

my $agent = WWW::Mechanize->new( autocheck => 1 );
my $formfiller = WWW::Mechanize::FormFiller->new();
$agent->env_proxy();

$agent->get( $LOGINURL );
$agent->form_number(1) if $agent->forms and scalar @{$agent->forms};
$formfiller->add_filler( 'username' => Fixed => $USER );
$formfiller->add_filler( 'password' => Fixed => $PASSWORD );
$formfiller->fill_form($agent->current_form);
$agent->submit();

$agent->get( $ONLINEURL );

my $status = $agent->content();
my @status = split ("\n", $status);
@status    = grep( /events\?source=openhab/, @status );
$status[0] =~ s#</a>.*##;
$status[0] =~ s#.*>##;

print( $status[0], "\n" );

Thanks, @Wolfgang_S
I will give it a try.
Just out of curiosity - what is the “local” cloud you are referring too?

EDIT:
After installing the MECHANIZE libs the script starts running, but ends with an error:

[09:45:59] openhabian@homer:/etc/openhab2/scripts$ perl -w MyOHCld_State.pl
Error GETing https://myopenhab.org/: Internal Server Error at MyOHCld_State.pl line 23.

I assume @Wolfgang_S is running his own instance of the openhab Cloud

You can connect to your own cloud instance so you are not running on “myopenhab.org” instance

Ah, thanks.
For me personally I just need connectivity from outside (and Alexa).
So a local cloud would not make sense to my case, because you would need to open ports then (unless I missed something).

IMO I think that is a perfectly acceptable choice. I have limited items that I control through the myopenhab cloud.

the online cloud, I assume?

Yes that one :slight_smile:

Me too - just the ones to Alexa.
And I have created a switch to disconnect Alexa, when I am not at home to prevent her messing up my appartment :wink:

looks like there is a difference between public and local/private cloud.
Submitting the form then returns an error.

Could you enter the following line:

print( $agent->content() );

before the row that contains $agent->submit();
This then should print out the content of the login page.
You may sent a message with that content to my address.
Please make sure that your password is not in that file ( just in case that is printed out, too ).

You also could follow the instructions in this Linux Magazin article ( in german )


That’s the way how I constructed the basics of that script.

In case you prefer to read an english article here is one


In case you need further assistance please let me know.