Myopenhab connection state

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
That’s working fine.

1 Like

Almost the same here :slight_smile: (Renault ZOE)

1 Like

By the way, when trigegring a switch I use nowadays the http binding instead of curl:
{http=">[ON:GET:}] >[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 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     = '';
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->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 );

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

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

[09:45:59] openhabian@homer:/etc/openhab2/scripts$ perl -w
Error GETing Internal Server Error at 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 “” 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.

Thanks again for your help.
the print returns the login page.
So, you mean it’s different?

I will send you the file in a PM soon.
And I will look into both - the German and English site to be on the safe side :wink:

That’s awesome.
I start to understand what your script is doing :slight_smile:

Using the shell to try it step by step works until I hit submit :frowning:
(the feature of generating the script of the manually executed steps is brilliant!)

The error refers to this part
my $res = $self->agent->submit;


@Wolfgang_S Is it maybe a problem, that the form shows UNDEF?>form 1
  _csrf=xxxxx (hidden readonly)
  username=                      (text)
  password=                      (password)
  submit=<UNDEF>                 (submit)

When I fillout user and password like 'password' the error does not appear with click submit.
However creating a script out of this input, leads of course to ''password''

So, could it be possible that special characters cause the issue?
(my password contains a & and the email-adress of course @)

If I replace ‘@’ with ‘%40’ in my email / password the following error disappears:
Error GETing Internal Server Error at ./ line 20.

However, I get new errors:

Use of uninitialized value $status[0] in substitution (s///) at ./ line 27.
Use of uninitialized value $status[0] in substitution (s///) at ./ line 28.
Use of uninitialized value $status[0] in print at ./ line 30.

Which is possibly related to the fact, that the login did not succeed.
I can see this when running the shell manually, because after submitting, I am still on /login and cannot open / get /events?source=openhab

Is it possible that submit does not work, because there are two submit on the same page (log in and register confirmation)

Both buttons look the same and I don’t know how to “click” / identify the right one:
Sign in:
<button name="submit" type="submit" class="btn" id="submit">Sign in</button>

<button name="submit" type="submit" class="btn" id="submit">Register</button>

In case I remeber right you can enter forms when you are in the Mechanize shell.This should show both forms. It is possible to select one of them ( should be described in the articles ).
Normally submit buttons have a name or identifier that you can use to ‘click’ on the correct one.
But I think they are in different forms.

In case you are behind the submit you again can use the print content statement to check what was sent back by the sever. It should contain the Online / Offline part. If that is not in or the regular expression that is used in the parsing part does not match then this will end up in messages saying that something is undefined. Using the print statement you should be able to check if the login/submit was successfull or not.

That’S correct.
Sign in is in form 1 and Register is in form 2.
I have succesfully gone into form 1 (in shell), used fillout and the form itself showed the right credentials when calling the form 1 again.

However - as you stated above - the submit is not successful, so the REGEX does not work.

So I am wondering how to ensure that the submit button from form 1 is used.
How to specify the button with like:
$agent->click(value => "Sign in");

I don’t get it wo work (in the shell)

I can use fillout to update the username and password:>form 1
  _csrf=NPi3N3Ul-NrkTbcFYXfujfEETTpANipOsguw (hidden readonly)
  username=xxxxxx           (text)
  password=yyyyyy           (password)
  submit=<UNDEF>            (submit)

with “click submit” it’s send somewhere, because the filled-in data is gone.
But I can not go beyond login (it just goes back to login :frowning: ):>get
                                                                                                                        >form 1
  _csrf=xxxx (hidden readonly)
  username=                      (text)
  password=                      (password)
  submit=<UNDEF>                 (submit)