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¶m=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¶m=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, next track on squeezebox
- Alexa, skip track on squeezebox
- Alexa, previous track on 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
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).