Release Candidate and Support: Amazon Echo Control Binding

Smart Home Device Control - I need help
I’am preparing a version which can control smart home devices connected to alexa.

  • You have smart home devices connected to alexa, e.g. Philips Hue (not by using the openHAB Smart Home skill, I need other Smart Home Skills)
  • You know how you open the openHAB log files
  • You have 1-2 hours time in the next two days
  • You want help me to finish the implementation of the smart home feature

Current state: It’s implemented for lamps and dimmers, but it seems the the discovering does not work for skills other then the openHAB

Anybody interested?

Hey there and thank you for the fantastic binding !
It works well in my case with amazon.de, except the wha: I had to link the items separately in the PaperUI, then everything works except the volume of the wha. It’s not bad for me, I can do this with a rule.

Another point: I’d like to limit the volume of my echo and with your binding this can be possible. Let me show you my rule:

rule "Scale Factor Wohnzimmer"
when
  Item Echo_Wohnzimmer_Volume_default received command
then
  var Number value = Echo_Wohnzimmer_Volume_default.state as DecimalType
  sendCommand(Echo_Wohnzimmer_Volume, value*0.8)
end

The Item Echo_Wohnzimmer_Volume_default is the dimmer, which is implemented in the sitemap. The dimmer Echo_Wohnzimmer_Volume is not visible for the user. With the factor 0.8 in my example I can limit the maximum of the volume from 10 to 8 ( in Alexa “units”).

This works ! Next, I thought, if I say once: “Alexa, turn the volume to 2”, the speaker gets the new volume data but the default dimmer in the sitemap doesn’t. So I made another rule, which should update the Echo_Wohnzimmer_Volume_default:


rule "Scale Factor Schlafzimmer"
when
  Item Echo_Wohnzimmer_Volume changed
then
  var Number value = Echo_Wohnzimmer_Volume.state as DecimalType
  var Number value_def = Echo_Wohnzimmer_Volume_default.state as DecimalType
  if(value_def!=value/0.8) // compare if the default dimmer has an old value; this should prevent a permanent loop
  {
  sendCommand(Echo_Wohnzimmer_Volume_default, value/0.8); //here I use the inverse operation of the multiplication to get the value for the default item
    Thread::sleep(200)
  }
end

Unfortunately, this does not work as it should: Changing the default item changes the volume as it should, but this repeats 3 times - I can’t understand why. Changing the ‘original’ Echo_Wohnzimmer_Volume works and changes the default item, too. Just changing the default does not work 100 percent right. Do anyone know why ?

Thanks and thank you @michi for the great work !

I solved the problem for myself: The mistake was a forgotten ‘.default’ in the if-clause.
The final code zu scale the volume is:

rule "Scale Factor Wohnzimmer"
when
  Item Echo_Wohnzimmer_Volume_default received command
then
  var Number value = Echo_Wohnzimmer_Volume.state as DecimalType
  var Number value_def = Echo_Wohnzimmer_Volume_default.state as DecimalType
  if(value!=value_def*0.8){
  sendCommand(Echo_Wohnzimmer_Volume, value_def*0.8);
  }
end


rule "Scale Factor Wohnzimmer"
when
  Item Echo_Wohnzimmer_Volume changed
then
  var Number value = Echo_Wohnzimmer_Volume.state as DecimalType
  var Number value_def = Echo_Wohnzimmer_Volume_default.state as DecimalType
  if(value_def!=value/0.8){
  sendCommand(Echo_Wohnzimmer_Volume_default, value/0.8);
  }
end

Trying to duplicate the upper rule, I faced another problem.
Copied the same rule and modified the item names, the method does not work: The dimmer goes to 0 / initialized by updating the browser with basicUI. In the app the dimmer turns to 0 /initialized after 1-2 seconds approx. So, I removed the rules and the failure is still the same. The code is exactly the same, the only difference is that the working one is an echo dot and the bad one is an echo. But I think this can be fixed openhab internally ? I tried to add autoupdate to the item, but this does not help. How is this to fix ?

Thank you !

I’ve got this awesome binding giving me a 60 and 30 minute reminder of my caldav calendar and it works great however occasionally it does an alarm instead of a reminder anyone else found this? How can I help with troubleshooting this?

Hi Andrew,
maybe you can check the history of reminders in the AlexaApp. If there is a reminder at this time, then it must be a bug in the alexa SW.
Regards,
Michael

Maybe you have an rounding error problem. Try to replay the sendCommand of the second rule with updateState to prevent a loop by calling the first rule, triggered by the second:

rule "Scale Factor Wohnzimmer"
when
  Item Echo_Wohnzimmer_Volume_default received command
then
  var Number value = Echo_Wohnzimmer_Volume.state as DecimalType
  var Number value_def = Echo_Wohnzimmer_Volume_default.state as DecimalType
  if(value!=value_def*0.8){
  sendCommand(Echo_Wohnzimmer_Volume, value_def*0.8);
  }
end


rule "Scale Factor Wohnzimmer"
when
  Item Echo_Wohnzimmer_Volume changed
then
  var Number value = Echo_Wohnzimmer_Volume.state as DecimalType
  var Number value_def = Echo_Wohnzimmer_Volume_default.state as DecimalType
  if(value_def!=value/0.8){
   postUpdate(Echo_Wohnzimmer_Volume_default, value/0.8);
  }
end

All the reminders are there that I can see

Hello,

I would like to ask a few questions.

Is it possible to let Alexa remind me at a specific time on a specific day?

I am asking because I would like to use such a feature to let Alexa remind me at for example at 22:00 - 1 day before I need to put the trash cans/bins outside.

Yes, but you must do this with a rule which starts the remind function at the target time.

Does anyone has actual problems with the binding? Especially with the radio stations? (Getting an error within the log that the notification element couldnt been validated, posting it later, at work at the moment)

How can I use a calendar in rules? Sorry kinda new to the whole programming stuff

If you really want to use a calendar, look into Google Calendar Scheduler, CalDAV Personal, or CalDAV Command.

But the easier route would be to use a cron trigger. I still had this around from before I setup CalDAV…

rule "Cron: Time to take the trash out"
when
    Time cron "0 0 15 ? * MON"// every Monday at 3pm
then
    val String message = "Time to take the trash out"
    SMS_Notification.sendCommand(message)
    if (Presence.state.toString == "Home") {
        Audio_Notification.sendCommand(message)
    }
    logInfo("Rules", "Cron: {}",message)
end
1 Like

So here are the mentioned log entries, that are shown red and the beginning of the change of the tuneinradiostation:

2018-03-07 19:27:54.202 [vent.ItemStateChangedEvent] - EchoImSchlafzimmer_TuneInRadioStationsID changed from to 0

==> /var/log/openhab2/openhab.log <==

2018-03-07 19:27:59.511 [WARN ] [mazonechocontrol.internal.Connection] - Parsing json failed {}

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 5 column 1 path $

at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224) ~[?:?]

at com.google.gson.Gson.fromJson(Gson.java:887) ~[?:?]

at com.google.gson.Gson.fromJson(Gson.java:852) ~[?:?]

at com.google.gson.Gson.fromJson(Gson.java:801) ~[?:?]

at com.google.gson.Gson.fromJson(Gson.java:773) ~[?:?]

at org.openhab.binding.amazonechocontrol.internal.Connection.parseJson(Connection.java:472) ~[?:?]

at org.openhab.binding.amazonechocontrol.internal.Connection.getPlayer(Connection.java:491) ~[?:?]

at org.openhab.binding.amazonechocontrol.handler.EchoHandler.updateState(EchoHandler.java:396) ~[?:?]

at org.openhab.binding.amazonechocontrol.handler.EchoHandler.lambda$0(EchoHandler.java:356) ~[?:?]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

at java.lang.Thread.run(Thread.java:748) [?:?]

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 5 column 1 path $

at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385) ~[?:?]

at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213) ~[?:?]

… 15 more

2018-03-07 19:27:59.540 [WARN ] [mazonechocontrol.internal.Connection] -

(function(d,e){function h(f,b){if(!(a.ec>a.mxe)&&f){a.ter.push(f);b=b||{};var c=f.logLevel||b.logLevel;c&&c!==k&&c!==m&&c!==n&&c!==p||a.ec++;c&&c!=k||a.ecf++;b.pageURL=“”+(e.location?e.location.href:“”);b.logLevel=c;b.attribution=f.attribution||b.attribution;a.erl.push({ex:f,info:b})}}function l(a,b,c,e,g){d.ueLogError({m:a,f:b,l:c,c:“”+e,err:g,fromOnError:1,args:arguments},g?{attribution:g.attribution,logLevel:g.logLevel}:void 0);return!1}var k=“FATAL”,m=“ERROR”,n=“WARN”,p=“DOWNGRADED”,a={ec:0,ecf:0, pec:0,ts:0,erl:,ter:,mxe:50,startTimer:function(){a.ts++;setInterval(function(){d.ue&&a.pec<a.ec&&d.uex(“at”);a.pec=a.ec},1E4)}};l.skipTrace=1;h.skipTrace=1;h.isStub=1;d.ueLogError=h;d.ue_err=a;e.onerror=l})(ue_csm,window);

and

q(“:”,g.attribution||d.attribution,d.name);g.logLevel=d.logLevel;g.attribution&&console&&console.log&&console.log([g.logLevel||“ERROR”,a,“thrown by”,g.attribution].join(" “));C=;fa&&(d=.slice.call(arguments),d[4]=g,fa.apply(f,d))};D.prototype={logError:function(a,b,c,e){b={message:b,logLevel:c||“ERROR”,attribution:q(”:“,this.attribution,e)};if(f.ueLogError)return f.ueLogError(a||b,a?b:null),!0;console&&console.error&&(console.log(b),console.error(a));return!1},error:function(a,b,c,e){a=Error(q(”:",

it seems somewhere above the posted sourceparts of the error there is a warning

[WARN ] [mazonechocontrol.handler.EchoHandler] - Get notification sounds failed: {} …

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 5 column 1 path $

at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385) ~[?:?]

at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213) ~[?:?]

... 80 more

nervermind it works again :open_mouth:

I’ve been waiting for this, now Alexa tells me when someone presses the doorbell (amazon dash button). Good work.

I am now using the binding but the reminder always triggers twice could that be a bug ?

See #189: Release Candidate and Support: Amazon Echo Control Binding - #189 by Oggerschummer

1 Like

Apparently the binding has issues loggig in. The credentials are correct, an the state is
“OFFLINE - COMMUNICATION_ERROR Login fails.”

openhab.log shows

2018-03-09 23:21:49.394 [INFO ] [mazonechocontrol.internal.Connection] - Response maybe not valid
2018-03-09 23:21:49.632 [INFO ] [mazonechocontrol.internal.Connection] - Login failed:{}
org.openhab.binding.amazonechocontrol.internal.ConnectionException: Login fails.
        at org.openhab.binding.amazonechocontrol.internal.Connection.makeLogin(Connection.java:420) ~[?:?]
        at org.openhab.binding.amazonechocontrol.handler.AccountHandler.checkLogin(AccountHandler.java:248) ~[?:?]
        at org.openhab.binding.amazonechocontrol.handler.AccountHandler.lambda$0(AccountHandler.java:197) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.j
ava:180) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294
) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
~

I’m using amazon.de. Could it be they changed the login procedure so the binding fails?

No, normally this happens some time if you restart openHAB very often (should be fixed with beta 10), because the login requires an captcha. Normally this is gone automatically after 8-12 hours.