nikintharan / openhab

Automatically exported from code.google.com/p/openhab
0 stars 0 forks source link

Implement Action for notifymyandroid.com #345

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

NMA (https://www.notifymyandroid.com) is a platform that allows you to delivery 
push notifications to your Android device.

it has een open api: https://www.notifymyandroid.com/api.jsp

there are also ready made libs https://www.notifymyandroid.com/dev.jsp

Original issue reported on code.google.com by SJo...@gmail.com on 19 Jun 2013 at 10:42

GoogleCodeExporter commented 8 years ago
I think this wouldn't be implemented in a binding, but as an action. Since I'm 
also interested in this I could have look, but it looks simple enough.

Original comment by till.klo...@gmail.com on 19 Jun 2013 at 10:57

GoogleCodeExporter commented 8 years ago
That would be awesome!

Original comment by SJo...@gmail.com on 19 Jun 2013 at 11:17

GoogleCodeExporter commented 8 years ago
I'm not that deep into that Android Development. But how does NMA correlate 
with GCM mentioned in  http://code.google.com/p/openhab/issues/detail?id=286?

Original comment by teichsta on 19 Jun 2013 at 11:19

GoogleCodeExporter commented 8 years ago
GCM is used as a backend for NMA. But NMA uses this mainly to notify the user 
(although apps can listen for these notifications and do something). A real GCM 
implementation would enable much more complex setups like updating widgets on 
an Android device. So I don't think this really conflicts. NMA will be a neat 
notification mechanism for Android owners.

Original comment by till.klo...@gmail.com on 19 Jun 2013 at 11:33

GoogleCodeExporter commented 8 years ago
ok, thanks!

Original comment by teichsta on 19 Jun 2013 at 11:36

GoogleCodeExporter commented 8 years ago
Till, any plans when to start with it? Just for information ...

Original comment by teichsta on 19 Jun 2013 at 11:37

GoogleCodeExporter commented 8 years ago
I think this will be a nice task after I finished Tasker support for 
HABSweetie, so probably at the end of next week.
This could then be merged together with the CUL binding. Parsing the binding 
config is tested a bit. 

Original comment by till.klo...@gmail.com on 19 Jun 2013 at 11:42

GoogleCodeExporter commented 8 years ago
FYI: I have recently created a new branch with a refactoring to make it 
possible to dynamically add new actions (just as you can add new bindings): 
https://code.google.com/p/openhab/source/list?name=1.3.0-modularactions

This approach should be taken for all new actions being implemented. I still 
have a bit of work left on it, but hope that I'll be through by the end of next 
week.

Original comment by kai.openhab on 19 Jun 2013 at 11:42

GoogleCodeExporter commented 8 years ago
Great I will look into the branch. Is any documentation available?

Original comment by till.klo...@gmail.com on 19 Jun 2013 at 12:14

GoogleCodeExporter commented 8 years ago
No, not yet! But the way how you implement the code in your action is not 
impacted - only how you integrate the action into openHAB. So you can already 
start with the implementation and I'll inform you as soon as I am done with my 
refactoring.

Original comment by kai.openhab on 19 Jun 2013 at 12:16

GoogleCodeExporter commented 8 years ago
I will have a look at the AudioAction and try to stay close to that example.

Original comment by till.klo...@gmail.com on 19 Jun 2013 at 1:58

GoogleCodeExporter commented 8 years ago

Original comment by teichsta on 13 Aug 2013 at 7:43

GoogleCodeExporter commented 8 years ago
maybe it`s bether to use https://pushover.net/ it respons quicker and it is for 
Iphone & android.

Original comment by SJo...@gmail.com on 13 Aug 2013 at 9:44

GoogleCodeExporter commented 8 years ago
Maybe but their traffic limitations are quite hard. They allow 7500 messages by 
month which means 10 per hour which sound quite limiting to me, right? 
Additional 10.000 messages can by bought for $50 …

Original comment by teichsta on 13 Aug 2013 at 9:55

GoogleCodeExporter commented 8 years ago
http://imgur.com/c7NJRa2?tags

Let the user decide.

Pushover is not free (on android).
This my be a deal-breaker for some users, too.

Original comment by christop...@gmail.com on 13 Aug 2013 at 9:58

GoogleCodeExporter commented 8 years ago
No one is saying that no one should make an action for PushOver. So you could 
open another issue for this. I never experiences problems with NMA and payed 
for the pro version, so I will stick with NMA. Btw. the NMA action should be 
ready tomorrow evening. Then I will commit my changes to my fork.

Original comment by till.klo...@gmail.com on 14 Aug 2013 at 8:43

GoogleCodeExporter commented 8 years ago
Cool, good news! I will be happy reviewing the new Action :-)

Original comment by teichsta on 14 Aug 2013 at 8:58

GoogleCodeExporter commented 8 years ago
I just pushed the last changes to my clone. The action is already in action on 
my instance and seems to work fine.

Original comment by till.klo...@gmail.com on 15 Aug 2013 at 5:46

GoogleCodeExporter commented 8 years ago
merged the code into default (see 
http://code.google.com/p/openhab/source/detail?r=ed477439d2c55659f9ebc9bcc17b1a7
c9713dc3b). Could you please:

* add documentation to the nma parameters in openhab_default.cfg
* add NMA-Action to http://code.google.com/p/openhab/wiki/Actions

After that this issue could be closed.

Original comment by teichsta on 18 Aug 2013 at 8:09

GoogleCodeExporter commented 8 years ago
The wiki page has been updated and I added configurtion parameters with 
comments to openhab_default.cfg.
So this binding should be ready to go.

Original comment by till.klo...@gmail.com on 21 Aug 2013 at 8:33

GoogleCodeExporter commented 8 years ago
Thanks, Til. Merged your changesets into default (see ac496ec57760, 
043234305ebc and b8ed6ca4dff9)

Original comment by teichsta on 21 Aug 2013 at 1:15

GoogleCodeExporter commented 8 years ago
i am trying to get it to werk however i got an error.

09:49:51.547 ERROR o.o.c.s.ScriptExecutionThread[:70]- Error during the 
execution of rule 'Brievenbus': The name 
'notifyMyAndroid(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)
' cannot be resolved to an item or type.

in my rule file i have the following:
notifyMyAndroid("a3afd113a96b21e5c73b1edf749c13a43243242", "Brievenbus", "er is 
post")

did i something wrong?

Original comment by SJo...@gmail.com on 22 Aug 2013 at 8:07

GoogleCodeExporter commented 8 years ago
are you using the full current snapshot?

Original comment by teichsta on 22 Aug 2013 at 8:15

GoogleCodeExporter commented 8 years ago
Yes i am  updated this morning

Original comment by SJo...@gmail.com on 22 Aug 2013 at 8:19

GoogleCodeExporter commented 8 years ago
whoops!! i feel stuppid. didn`t copied the addons

it works!! 

thanxs

Original comment by SJo...@gmail.com on 22 Aug 2013 at 8:26

GoogleCodeExporter commented 8 years ago
:-) good to know that it works!

Original comment by teichsta on 22 Aug 2013 at 8:34

GoogleCodeExporter commented 8 years ago
Having trouble getting this to work. I have added the following to my 
openhab.cfg;

nma:apiKey=********************************************

But anytime I try to send a message I get;

ERROR o.o.a.n.i.NotifyMyAndroid[:138]- No api key specified

Checking the example config in openhab_default.cfg I see the config entries are 
delimited by '.' instead of ':' which I think is an error? Either way I tried 
both and the action simply won't pick up my api key.

Any idea what I am doing wrong (I am sure it is something obvious!)?!

Original comment by ben.jone...@gmail.com on 23 Aug 2013 at 3:13

GoogleCodeExporter commented 8 years ago
Hi Ben, you're right, the delimiter is inconsistent. I'll change that.

Regarding your problem: to me the code seems to be ok. Did you uncomment the 
config parameters?

Best,

Thomas E.-E.

Original comment by teichsta on 23 Aug 2013 at 7:49

GoogleCodeExporter commented 8 years ago
Yep, the '.' config is copy and paste typ, it should really be ':'. But the 
code should indeed be ok. The service.pid is org.openhab.nma at the moment, so 
parameters starting with "nma:" should be passed to the dictionary.

Original comment by till.klo...@gmail.com on 23 Aug 2013 at 12:51

GoogleCodeExporter commented 8 years ago
Managed to track this down to the fact I wasn't specifying a timeout in my 
openhab.cfg file. Because there is nothing specified the integer parsing on 
line 121 fails and falls out of the method (strange that I didn't see any error 
in my log though?).

There needs to be some better handling of null config options in here I think.

Also noticed the property name being passed to the ConfigurationException for 
this property is wrong.

So now I have the binding initialising, but I am not getting any notifications 
on my phone. The app is installed and I can send test notifications ok from the 
web site. And previously (when the API key was no loading from the config) I 
was getting the 'No api key specified' which tells me my rule is correctly 
attempting to send a notification.

Now I get nothing in the log and no notification. I have checked the API key 
and it is correct. I would expect some sort of error/warning if it was wrong?

Original comment by ben.jone...@gmail.com on 26 Aug 2013 at 3:15

GoogleCodeExporter commented 8 years ago
The bug where the missing timeout caused the configuration to fail, should be 
fixed now. But to track down the other problem I added some debug logging. 
Normally everything leading to an error should be logged, but obviously I 
forgot something. Here is the link to a snapshot build of the addon with 
bugfixes and more debug logging:
http://download.akuz.de/openhab/action/org.openhab.action.nma-1.3.0-SNAPSHOT.jar

Original comment by till.klo...@gmail.com on 26 Aug 2013 at 6:14

GoogleCodeExporter commented 8 years ago
merged Till's fix to default. Changed it slightly since Till changed behaviour 
for param defaultPrio rather than timeout (see 
http://code.google.com/p/openhab/source/detail?r=ee62e987e39b6876b26f4fe2415c0d3
cf64383dd)

Original comment by teichsta on 26 Aug 2013 at 7:27

GoogleCodeExporter commented 8 years ago
I pushed another fix. The application name seems to be mandatory and if it 
wasn't configured no application name was supplied. Instead now a default value 
will be supplied.

Original comment by till.klo...@gmail.com on 26 Aug 2013 at 8:03

GoogleCodeExporter commented 8 years ago
Just had a look at the fixes. So which parameters are mandatory in the config? 
It looks like API key and default priority? Correct?

Original comment by ben.jone...@gmail.com on 26 Aug 2013 at 9:15

GoogleCodeExporter commented 8 years ago
Basically none are mandatory. You need nma:apiKey only if you don't want to 
specify the apiKey in the method call. All the parameters are only there to set 
different default values in case you don't specify them in the method call.

Original comment by till.klo...@gmail.com on 26 Aug 2013 at 9:18

GoogleCodeExporter commented 8 years ago
But looking at the config parsing code won't it fail if you don't have a 
default priority?

Original comment by ben.jone...@gmail.com on 26 Aug 2013 at 9:31

GoogleCodeExporter commented 8 years ago
In the current version (as of this morning) the parsing of the default priority 
will only cause a warning in the logging if it is not set or invalid and not 
throw an Exception any longer. Every parameter should be completely optional.

Original comment by till.klo...@gmail.com on 26 Aug 2013 at 9:33

GoogleCodeExporter commented 8 years ago
sorry, that could my fault!

Till's fix removed the ConfigException at defaultPrio and added a warning but 
with text for timeout parameter. So i thought this line of code has to be moved 
to the parsing of the timeout parameter.

… sorry!

Till could you merge with the current default and add the any necessary path 
into it?

Original comment by teichsta on 26 Aug 2013 at 9:40

GoogleCodeExporter commented 8 years ago
The current revision on my clone should have all necessary fixes. Here is the 
latest snapshot build, which also works without any default configuration:
http://download.akuz.de/openHAB/action/org.openhab.action.nma-1.3.0-SNAPSHOT.jar

Original comment by till.klo...@gmail.com on 26 Aug 2013 at 10:39

GoogleCodeExporter commented 8 years ago
I can't work out what is wrong. I have copied your latest version of the 
binding to my /openhab/addons folder. My openHAB log shows;

2013-08-26 22:44:19 DEBUG o.o.a.n.i.NotifyMyAndroidActionService[:96]- 
NotifyMyAndroid action service deactivated
2013-08-26 22:44:19 DEBUG o.o.a.n.i.NotifyMyAndroidActivator[:62]- 
NotifyMyAndroid action has been stopped.
2013-08-26 22:44:19 DEBUG o.o.a.n.i.NotifyMyAndroidActivator[:54]- 
NotifyMyAndroid action has been started.
2013-08-26 22:44:19 DEBUG o.o.a.n.i.NotifyMyAndroidActionService[:94]- 
NotifyMyAndroid action service activated
2013-08-26 22:44:19 DEBUG o.o.a.n.i.NotifyMyAndroidActionService[:117]- 
Updating config
2013-08-26 22:44:19 DEBUG o.o.a.n.i.NotifyMyAndroidActionService[:119]- 
Received new config
2013-08-26 22:44:19 WARN  o.o.a.n.i.NotifyMyAndroidActionService[:138]- Can't 
parse the default priority value, falling back to default value

So I am pretty happy the latest code is now running. I have a rule that sends 
an XMPP message when the front door opens (which is working). I added a 
notifyMyAndroid call in the same rule but I get nothing. And no errors or 
warnings in the log (I have debug logging enabled).

My rule is;

    notifyMyAndroid("Security", "Front door is open!")

Is there something obvious I am missing here?  

Original comment by ben.jone...@gmail.com on 26 Aug 2013 at 10:52

GoogleCodeExporter commented 8 years ago
If debugging is enabled you should also exactly what is posted to NMA. Also you 
should see the complete body of the response. Both should be available as DEBUG 
messages. Everything else should be available via WARN or ERROR.

Original comment by till.klo...@gmail.com on 26 Aug 2013 at 10:56

GoogleCodeExporter commented 8 years ago
Bingo - had to restart openHAB. Got a message successfully delivered - thanks 
Till!

Original comment by ben.jone...@gmail.com on 26 Aug 2013 at 11:01

GoogleCodeExporter commented 8 years ago
Yes I can confirm I can see the debug messages with the request and response
messages.

Original comment by ben.jone...@gmail.com on 26 Aug 2013 at 8:49

GoogleCodeExporter commented 8 years ago
One final suggestion, I don't think we should be writing WARN log messages when 
there is missing config (which is optional). I.e. if I don't specify a timeout 
or default priority I don't think I should see WARN messages in my openHAB log. 
If there is nothing specified and the default is used it should be a DEBUG 
message (at most). There should only be a WARN if something is specified but 
the parsing fails and thus it falls back to using the default. Just think it 
might confuse/worry some users if they start seeing these WARN messages when in 
actual fact everything is fine!

Original comment by ben.jone...@gmail.com on 26 Aug 2013 at 8:56

GoogleCodeExporter commented 8 years ago
Done, If a value which will be parsed to a number is empty, no warning will be 
shown in the log. Only if it is an unparseable String a warning will appear.

Original comment by till.klo...@gmail.com on 27 Aug 2013 at 5:57

GoogleCodeExporter commented 8 years ago
Guys - I just pushed a change to my clone 
(https://code.google.com/r/benjones12-zwave2/source/detail?r=0496d9e1fcc6ea64bc1
90f691372b520f4ef51d3&name=1.4.0-zwave) to add an extra overload to the 
notifyMyAndroid action.

I want to use the base API key but set the priority easily, so added the 
'notifyMyAndroid(event, description, priority)' overload.

If you are happy to include this can you add to the main branch at some point? 
I will run a local version of the action in the meantime.

Original comment by ben.jone...@gmail.com on 17 Sep 2013 at 12:24

GoogleCodeExporter commented 8 years ago
merged your enhancement into default (see 
https://code.google.com/p/openhab/source/detail?r=3ff5ca37c0fc4ea06ebaa3cd458bdb
6d5a897807&name=1.3.1)

Original comment by teichsta on 18 Sep 2013 at 2:29

GoogleCodeExporter commented 8 years ago
Hi everyone. I have wittnessed some strange behaviour with NMA binding.

When openhab is restarted and execute an NMA Action I receive error an Error 
during the execution of rule 'NMA': The name 
'notifyMyAndroid(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)
' cannot be resolved to an item or type when I execute the the command 
notifyMyAndroid( "APIKEY","Coffee Machine","ON")

If I copy the NMA jar file in to the addons directory with OPENHAB running, the 
notifyMyAndroid( "APIKEY","Coffee Machine","ON") command works everytime.

I have managed to repeat this 5 times in a row. 

My setup:
Openhab snapshot 1.4 build #555 
HABMIN git revision dc6b8c34957b17062ba252336cfb8f156cdbf4d1
HABMIN Zwave binding installed

So i am not sure if this is a bug or not

Original comment by dkw04...@gmail.com on 6 Jan 2014 at 3:06

GoogleCodeExporter commented 8 years ago
When you restart openHAB is the NMA jar in your addons folder? It needs to be 
there always.

Original comment by ben.jone...@gmail.com on 6 Jan 2014 at 3:11

GoogleCodeExporter commented 8 years ago
I think there is a bug in the startup behavior (startlevel for addons). Would 
you mind creating a bug entry at Github for this?

Original comment by kai.openhab on 6 Jan 2014 at 8:14