Page 4 of 17

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Monday 14 January 2019 20:31
by Westwoodx
rimram31 wrote: Friday 11 January 2019 18:58
Damsee wrote: Friday 11 January 2019 10:23 Viewed your messages this morning and had a quick test => same result "doesn't support that..."
...
Good news, it seems you were right Damsee, I've add timeOfSample and uncertaintyInMilliseconds and it works!

This is updated on github, please update and give your feedback if this is ok for you (for those who make some changes, there is only two lines changed near line 139 of AlexaSmartHome.py source, check last commit git history)

I've first test with home assistant and it's no more working too, thanks Damsee.

I had the same problem with temperature reports too, but the above tweak has worked for me also, so thank you very much!! :D :D

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Wednesday 16 January 2019 17:59
by philchillbill
Damsee wrote: Wednesday 12 December 2018 23:07
mvzut wrote: Wednesday 12 December 2018 11:19 Ok, thanks!
Wouldn't it be nice if Alexa could alert me to movement in and/or around the house at night? (Although the WAF will largely depend on the reliability of the sensor Image)
That's not possible.
Remember that we use Alexa with DZ with the following idea :
> Asking Alexa one action/information > Alexa is asking DZ to do something or get the information > Alexa is giving you the feedback

What you're asking is the following :
> Something's happening with DZ (sensor or switch change) > DZ notifies Alexa > Alexa notifies you
That requires dual channel communication which is not implemented in Alexicz as it would require some configuration in DZ to notify Alexa.
And that would require many configurations steps to setup all devices to be able to notify Alexa for various things.
Actually, you can do this via a 'routine' in the Alexa phone app:

* From the hamburger menu at the top left, select Routines.
* Next, the '+' in the top right corner to add a new routine.
* Then the '+' beside 'when this happens' and select Device
* Choose a device from your devices list (e.g. a motion sensor)
* Choose the state to trigger with (e.g. DETECTED).
* Save it.
* Select a time range for when you want it to work. Save.
* Now hit the '+' for 'Add action' and select 'Alexa says'
* Select 'Custom'. Add your TTS text here and save.

When the DETECTED event is seen for this sensor, Alexa will now announce that motion was seen (or whatever text you entered). You can even select on which of your echos this is announced (I have 5).

Just discovered this myself yesterday :mrgreen:

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Wednesday 16 January 2019 22:11
by Damsee
Hi

Is the state "DETECTED" automatically discovered through Alexa or do you have to ask Alexa the state of your sensor before ?

Good news you find a way to manage Alexa to your needs.

Alexicz - FREE Domoticz to Alexa Integration

Posted: Wednesday 16 January 2019 22:33
by philchillbill
Alexicz reports the DETECTED state - no need to ask. I don’t think it’s ‘pushed’ proactively (looking at the code) so I guess Alexa may poll devices included in routines at regular intervals.

In the CloudWatch log you can see lots of polling happening when the Alexa app is open on the phone to keep status updates. Many rid= calls to Domoticz.


Sent from my iPhone using Tapatalk

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Thursday 17 January 2019 0:03
by Damsee
Could you have more tests with your sensors and with your routine:
- without checking the Alexa app, is Alexa saying detected (or whatever you configured in your routine) when your sensor state is changing to detected ? How long do you have to wait for Alexa applying your routine ?
- same tests while you're checking the Alexa app?

Maybe Amazon sets the sensor to be pulled each xx minutes but I never read that in the documentation.

Thanks for your feedback

Alexicz - FREE Domoticz to Alexa Integration

Posted: Thursday 17 January 2019 8:12
by philchillbill
Just tried it now with the app closed for a while and it failed. The motion lasted only 10 seconds. I see in the docs that “When a motion sensor changes to a DETECTED state, you must wait at least 30 seconds before reporting a change to NOT_DETECTED.” I take this to mean she may poll every 30 sec. I’ll change the minimum duration for my PIR and try again later.

Image

I copied the contact sensor endpoint code and made a specific motion sensor endpoint type and that’s why I have the correct classification in my setup.

Image

Would be best if Domoticz proactively reported state changes to obviate the need for polling. Maybe a plug-in that watches for state changes from the log? It might even be possible to use the 'Custom HTTP/Action' possibility in the Domoticz notifications capability. I'll take a look at it.


Sent from my iPhone using Tapatalk

Alexicz - FREE Domoticz to Alexa Integration

Posted: Thursday 17 January 2019 9:11
by philchillbill
Ok, I just verified that there is no polling from Alexa unless the app is open. Even with the motion sensor staying active for 2 mins. I also discovered that if I modify to proactivelyReported = False in class AlexaInterface in AlexaSmartHome.py, the response when adding a routine triggered by a device is 'we were unable to find any supported devices', so it simply must report proactively for this to work.

Image

I was fooled yesterday by the app being open and triggering polling. The docs do state that this happens: 'For example, a customer might check the Alexa app, which prompts Alexa to query the state of one of your endpoints.'

Alexicz is 'cheating' by claiming to proactively report even though it doesn't :o

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Thursday 17 January 2019 10:42
by rimram31
philchillbill wrote: Thursday 17 January 2019 9:11 ...
Alexicz is 'cheating' by claiming to proactively report even though it doesn't :o
You're perfectly right :D this is a "work in progress" (but no much time to full implement this), the reason why Damsee explain this is not working. This is a new Alexa feature, a few weeks ago, the french version was not working at all, one of the reason I was unable to continue.

The solution is here: https://developer.amazon.com/fr/docs/sm ... skill.html and more precisely here: https://developer.amazon.com/fr/docs/sm ... ort-events. See also "Asynchronous Response" in the schema here: https://developer.amazon.com/fr/docs/sm ... l-api.html

Technically speaking, for now, Alexicz has no asynchronous response, it only answer Alexa (cloud -> lambda -> domoticz) questions. A ChangeReport event require the skill/domoticz to call "alexa gateway" => https://developer.amazon.com/fr/docs/sm ... teway.html

For us, Alexicz has no online server (and stateful state), so I think a solution will be for each domoticz instance to make itself the call in a domoticz event script. But this script need some knowledge of Alexicz (the way Alexicz name endpointId for example) to build properly the rest post part and it need also an authentication token which is known by the skill. This is an oauth2 token, I don't know if it change or not frequently and I've no idea how Alexciz will be able to send/refresh this token to the target domoticz instance, perhaps a variable ? don't know.

Your ideas (and contributions :-) ) are welcome ...

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Thursday 17 January 2019 22:09
by philchillbill
Yes, I have been reading all this stuff already and am thinking hard how it might be implementable.

Lua might be a nice option as it has access to the devicechanged[] array directly within Domoticz and it can easily post to an external URL like the Amazon asynchronous change notification portal. The difficult bit will indeed be the authentication.

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Monday 21 January 2019 9:54
by rimram31
philchillbill wrote: Thursday 17 January 2019 22:09 Yes, I have been reading all this stuff already and am thinking hard how it might be implementable...
I've work on this this week end, I've not yet commit anything.

Finally, the simple way I've find was to reuse the python code to be able to write a python shell script which will make the change report call with a device id as a parameter for example. The existing python code used in the lambda has all the logic to easily build an api call object having a domoticz device id.

Technically speaking, this is not ideal as this script will be called or from lua or as a domoticz "action script" and it will itself call again domoticz http api, but from the existing code, this is the simpler solution.

For my first tests, I will use the token code as a simple configuration variable (adding it in lambda logs). I hope I will be able to commit some stuff very soon, I don't want to break the master branch. I will create some dev branch.

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Monday 21 January 2019 10:04
by philchillbill
Fantastic ! If it's python code anyway, could it be deployed as a plugin for Domoticz so it doesn't have to run in the shell?

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Monday 21 January 2019 12:46
by rimram31
philchillbill wrote: Monday 21 January 2019 10:04 Fantastic ! If it's python code anyway, could it be deployed as a plugin for Domoticz so it doesn't have to run in the shell?
I don't know how python plugins work ... for now it's to be used as a script triggered on "Action On/Off" as you can call any other script and to be add manually for each device. But this is first to test how and if this work, integration can be perhaps improved later.

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Monday 21 January 2019 16:41
by philchillbill
I've been busy modifying my copy of the code to support both Logitech Media Server and KODI endpoints and both now work. The Alexa.StepSpeaker (for sound control) and Alexa.PlaybackController (for transport) interfaces are used for this. I'm not a Github guy so I'll PM my files to rimram31 and Damsee to see what they want to reuse from my code in the main branch.

I looked at the Domoticz sources for both LMS and KODI and saw that there are undocumented API calls to json endpoints of the type

Code: Select all

/json.htm?type=command&param=lmsmediacommand&idx=nnn&action=ACTION
where values of ACTION that map to the Alexa Smart Home interfaces are Play, Stop, Pause, Forward, Rewind, VolumeUp, VolumeDown, and Mute

For Kodi, we have

Code: Select all

/json.htm?type=command&param=kodimediacommand&idx=nnn&action=ACTION
with commands such as PlayPause, Stop, FastForward, BigStepForward, Rewind, BigStepBack, VolumeUp, VolumeDown, Mute

(I've now just updated the wiki on json/API to reflect these findings).

For both mediacommand variations, a command such as e.g. 'set volume to 80' cannot be used because the LMS source in Domoticz cannot implement that (pity, because Alexa can via Alexa.Speaker). Instead we can do VolumeUp and VolumeDown in multiple steps of 2 increments - my code loops these commands steps/2 times to achieve bigger steps if requested. For Kodi, mute/unmute makes sense but volume up/down probably does not because most people use Kodi with a fixed output volume and change the volume on their amplifier instead. The FastForward and Rewind commands work for Kodi and so are implemented.

Here are some example voice commands that work (in addition to turn on/off):
  • Alexa, pause squeezebox
  • Alexa, next track on squeezebox
  • Alexa, skip track on squeezebox
  • Alexa, previous track on squeezebox
  • Alexa, resume squeezebox
  • Alexa, play squeezebox
  • Alexa, stop squeezebox
  • Alexa, mute squeezebox
  • Alexa, unmute squeezebox
  • Alexa, lower the volume on squeezebox
  • Alexa, decrease the volume on squeezebox by 20
  • Alexa, raise the volume on squeezebox
  • Alexa, increase the volume on squeezebox by 40
  • Alexa, pause kodi
  • Alexa, fastforward kodi
  • Alexa, rewind kodi
  • Alexa, mute kodi
  • etc.
Here are a few more mods I implemented - steal whatever ideas you want from this:
  • I added code to address some corner cases of discovery and the subsequent mapping to the correct type of endpoint.
  • I mapped Domoticz contact and door contact switch types to endpoints of type CONTACT_SENSOR and motion detectors to MOTION_SENSOR.
  • Added a Description option of 'no_alexa' to have a Domoticz device skipped entirely at discovery.
  • Added a Description option to create two Alexa names for the same endpoint - e.g. for 'Dining Light' I have "Alexa_Alternate: Diningroom Light". Alexa often misinterprets/extends Dining to Diningroom by herself and then can't find a device. This mod clones an endpoint and then '-2' is added to the endpointId but that gets stripped anyway by the split on '-' operation before being sent back from Amazon to Domoticz to implement switching.
  • In method getProperty, I changed to "maxLevel = device['MaxDimLevel'] or 100" as otherwise the division by float(maxLevel) was a div by zero if MaxDimLevel is undefined, which it is for many of my devices.
Again, these changes are in my private copy of this and are not yet on Github ! This skill is rimram31/Damsee's baby and they can decide what to reuse from this (if anything).

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Tuesday 22 January 2019 9:47
by philchillbill
I've just noticed there seems to be friendlyName-persistence for the LMS music players. If I initiate a command to a certain squeezebox e.g. 'Alexa, turn on office player' then in subsequent commands I can leave out the player name and can just say 'Alexa, pause', 'Alexa, resume' etc. Note that Follow-Up mode is set to OFF on all my echos so it's not because of that (for sure, because I do have to repeat 'Alexa'). Even if I use a switch command for a lamp in between the music commands or there's a big gap in issuing commands, they still point to the last-used player. The player in question is linked to the echo used, so if the last player targeted from e.g. my bedroon spot was the bedroom player and I start the office player from my office dot, the bedroom spot still tries to control the bedroom player even if the office player was switched later. Undocumented feature? Hope it rolls further - it's cool !

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Sunday 03 February 2019 13:33
by mozo78
I cannot wait to use this modification. :) Looks very great! Hope the guys implement it soon.

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Sunday 03 February 2019 19:40
by philchillbill
It's already implemented in the release code on Github (not in the master branch) so if you copy the 2 python files from that download you should be good to go. It's here:

https://github.com/rimram31/dz_smarthom ... g/dev-phil

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Tuesday 05 February 2019 21:41
by j0eyv
Do i rly need a creditcard to create a account for console.aws.amazon.com? I don't have one which means i cannot use Alexicz?

Thank you for creating an Amazon Web Services account. For the next 12 months, you'll have free access to core AWS compute, storage, database, and application services within the limits of the Free Tier.

What happens after 12 months? Is my Alexa skill still working or do i have to pay for it after 12 months?

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Tuesday 05 February 2019 21:53
by philchillbill
It stays free if you stay under one million calls to your skill a month. The credit card requirement is just a formality for private skills like this.


Sent from my iPhone using Tapatalk

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Wednesday 06 February 2019 7:17
by j0eyv
Ok. But can i complete the process without filling in creditcard information? Looks like i'm not able to because i do not have a creditcard:

1. Make sure you provided all necessary information during signup. Complete your AWS registration.
2. Check your email to see if you have received any requests for additional information. If you have, please respond to those emails with the information requested.
3. Verify your credit card information is correct. Also, check your credit card activity to see if there’s a $1 authorization (this is not a charge). You may need to contact your card issuer to approve the authorization.

Re: Alexicz - FREE Domoticz to Alexa Integration

Posted: Wednesday 06 February 2019 7:31
by philchillbill
Nope, you do need a credit card. May seem strange for a free service but (1) it establishes identity, and (2) it provides for automatic billing if your skill consumes big AWS resources. It’s like a red light camera. Not needed if you just stop when it’s red like most people do...


Sent from my iPhone using Tapatalk