Release MQTT Adapter - Now forked (2022)
#16
This thing is already making my house smarter. When my doorbell rings, video that is being played is paused. Big Grin

Now, I'm using mqttwarn (https://github.com/jpmens/mqttwarn) to write MQTT message to a MySQL database for analysis (I'm a Data Warehouse engineer Angel) and to smarten my domotica system (homebrewn ESP8266 stuff).

mqttwarn supports JSON format, only not a nested JSON, like is being created by this addon. For example, the status/title produces a "kodi_details" element which contains title, file, etc. I don't think there is a need for this nesting (not more than 1 thing plays at a time, right?). Can we make the output so that it writes all elements without any nesting?

Doing so will instantly enable everyone to use the much recommended mqttwarn out-of-the-box. This enables direct integration of about 50 interfaces, such as MySQL, PushBullet, http, notifiers, etc.
Reply
#17
I've just uploaded v0.13 of the addon as

https://github.com/owagner/kodi2mqtt/rel..._addon.zip

Code:
v0.13 - 2016-05-01 - owagner
  - change logic for command/playbackstate:
     - resume/play/1 will now properly resume when pausing, and attempt to
       start play when playback has endeded. Fixes #17
     - pause/2 will now only pause if the player is actually playing.
       It can no longer be used to toggle pause mode.
     - toggle (new) will now toggle pause mode, similarily to how "pause"
       did before
Reply
#18
Great addon! This solved all the problems I had! Big Grin

I had problems with the kodi binding for openhab, but with this addon I dont even need the binding, PERFECT!
Reply
#19
I have a suggestion for inclusion on the listen to command/notify topic, add the fields "image/icon" and "displaytime/duration" to the JSON encoded object.

Much appreciated Smile
Reply
#20
First of all Great addon! Thanks a lot for that!

I don't know if you still have time to work on it but if those could be implement it would cover pretty much everything i want to get from or control on my kodi:

-artist and album status
-Volume control/status
-repeat control (one/all/off)
-random on/off control/status

I struggle half a day to get it work on my openhab. The addon was not the problem but i missed one argument in my item creation. I wish to share it here for those who want to implement this on openhab as well:

Here what you need to code for your items. This configuration works with my openhab 1.8.3 + addon bundle 1.8.3 :

Code:
/* Kodi via MQTT */

/* topic kodi/connected */
Number kodiConnected "Kodi Connected: [%d]" (gKodi) {mqtt="<[broker:kodi/connected:state:default]"}

/* topic kodi/status/playbackstate */
Number kodiPlaybackState "Playback state: [MAP(kodiPlaybackState.map):%s]" (gKodi) {mqtt="<[broker:kodi/status/playbackstate:state:JSONPATH($.val)]"}
Number kodiPlaybackSpeed "Playback speed: [%d]" (gKodi) {mqtt="<[broker:kodi/status/playbackstate:state:JSONPATH($..speed)]"}
String kodiPlaybackRepeatState "Repeat: [%s]" (gKodi) {mqtt="<[broker:kodi/status/playbackstate:state:JSONPATH($..repeat)]"}
String kodiState "Kodi state: [%s]" (gKodi) {mqtt="<[broker:kodi/status/playbackstate:state:JSONPATH($.kodi_state)]"}
String kodiPlayerType "Media type: [%s]" (gKodi) {mqtt="<[broker:kodi/status/playbackstate:state:JSONPATH($.kodi_playertype)]"}

/*topic kodi/status/progress */
Number kodiProgress "Progress: [%.1f %%]" (gKodi) {mqtt="<[broker:kodi/status/progress:state:JSONPATH($.val)]"}
String kodiPlaybackPosition "Playback position: [%s]" (gKodi) {mqtt="<[broker:kodi/status/progress:state:JSONPATH($.kodi_time)]"}
String kodiTotalTime "Media Lenght: [%s]" (gKodi) {mqtt="<[broker:kodi/status/progress:state:JSONPATH($.kodi_totaltime)]"}

/*topic kodi/status/title */
String kodiTitle "Titre: [%s]" (gKodi) {mqtt="<[broker:kodi/status/title:state:JSONPATH($.val)]"}
String kodiTitleType "type (title topic): [%s]" (gKodi) {mqtt="<[broker:kodi/status/title:state:JSONPATH($..type)]"}

/*topic kodi/command/playbackstate */
Switch KodiToggle "Play/Pause" (gKodi) {mqtt=">[broker:kodi/command/playbackstate:command:*:toggle]"}
Switch KodiStop "Stop" (gKodi) {mqtt=">[broker:kodi/command/playbackstate:command:*:stop]"}
Switch KodiResume "Resume" (gKodi) {mqtt=">[broker:kodi/command/playbackstate:command:*:resume]"}
Switch KodiPause "Pause" (gKodi) {mqtt=">[broker:kodi/command/playbackstate:command:*:pause]"}
Switch KodiNext "Next" (gKodi) {mqtt=">[broker:kodi/command/playbackstate:command:*:next]"}
Switch KodiPrevious "Previous" (gKodi) {mqtt=">[broker:kodi/command/playbackstate:command:*:previous]"}

Here's the content of kodiPlaybackState.map:

Code:
0=stopped
1=playing
2=pause
-=unknow


Some reference to understand the code better:

https://github.com/openhab/openhab/wiki/MQTT-Binding
https://github.com/jayway/JsonPath
Reply
#21
Thanks for this great plugin!

Is it possible to run a specific playlist?
Reply
#22
(2016-05-01, 13:03)owagner Wrote: I've just uploaded v0.13 of the addon as

https://github.com/owagner/kodi2mqtt/rel..._addon.zip

Code:
v0.13 - 2016-05-01 - owagner
  - change logic for command/playbackstate:
     - resume/play/1 will now properly resume when pausing, and attempt to
       start play when playback has endeded. Fixes #17
     - pause/2 will now only pause if the player is actually playing.
       It can no longer be used to toggle pause mode.
     - toggle (new) will now toggle pause mode, similarily to how "pause"
       did before



Beautiful!

I combined this with the EventGhost mqtt plugin and they work well together!
My question though is, what commands would use if you have more than one instance of KODI running? Huh
And it would also be nice to expand this abit more say, if you have the kodi IP Cam plugin and you want to activate it for a given time when the door bell rings ====>
Let me not ask too much but that would be great! Cool

There is a JSON option for doing this but the whole concept is so resource hogging (on the server side ===> running HomeSeer with the KODI plugin for HomeSeer) in that if you have all types of protocols connecting to kodi. I found that mqtt is the best.

Thank you so much! Your feedback is appreciated.



Eman457
Reply
#23
Wutu:

For most command I'm sending json to my kodi from my openhab server. You can do this command to play a specific playlist. Verify that your playlist is in the path specified. If not, change to the appropriate one. (change playlistname.m3u by your playlist name). You can send that json by telnet at port 9090 (default port) of your kodi server.

Code:
{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"/$HOME/.kodi/userdata/playlists/music/playlistname.m3u"},"options":{"repeat":"all","shuffled":true}}}

You can aslo send it by web. That's how my openhab send it. So use your ip address, your port (8080 is the default) and login pass might be needed but sometimes it's not needed.

Code:
http://login:[email protected]:8080/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"/$HOME/.kodi/userdata/playlists/music/playlistname.m3u"},"options":{"repeat":"all","shuffled":true}}}
Reply
#24
Hi,

This looks a very very interesting addon.

I have searched for quite some time but it is not clear to me how I can install this MQTT Adapter.

FYI I am running KODI on rapsberry pi version 3 with jessie OS.

many thanks for any valuable response.
Jan.
Reply
#25
(2016-12-11, 11:01)jvda Wrote: Hi,

This looks a very very interesting addon.

I have searched for quite some time but it is not clear to me how I can install this MQTT Adapter.

FYI I am running KODI on rapsberry pi version 3 with jessie OS.

many thanks for any valuable response.
Jan.

I managed to get it installed based on following steps:

1. I installed the mqtt python client on my raspberry pi using following commands also specified at http://www.eclipse.org/paho/clients/python/
Code:
git clone https://github.com/eclipse/paho.mqtt.python.git
cd paho.mqtt.python/
sudo python setup.py install
2. I downloaded mqtt_addon.zip from following URL : https://github.com/owagner/kodi2mqtt/releases
3. I copied (using scp) the zip file to my raspberry pi
4. Within kodi : goto system settings > addons > install from zip then select root folder and then select file /home/pi/mqtt_addon.zip
5. To configure this add-on goto system settings > addons > my addons, then select all and then select "mqtt adapter".
FYI: I only changed the IP address of MQTT server.
6. I had to reboot kodi to makes the changes in step 5 become effective.

kr
Jan
Reply
#26
This is a great add-on; many thanks.
As part of a wider home-automation project, I'd find it very useful to be able to set the volume via MQTT - any plans to implement that?

Thanks

Luke.
Reply
#27
If you can send json with your home automation system here are the sentence. Check my last entry for more info like sending it via web.

Code:
{"jsonrpc":"2.0","method":"Application.SetVolume","params":{"volume":10},"id": 1}   //set to 10, or change for level you want
{"jsonrpc":"2.0","method":"Application.SetVolume","params":{"volume":"increment"},"id":1}  //increment 1 db, i suggested to triple that command !
{"jsonrpc":"2.0","method":"Application.SetVolume","params":{"volume":"decrement"},"id":1}  //decrement 1db, i suggested to triple that command !
{"jsonrpc":"2.0","method":"Application.SetMute","params":{"mute":"toggle"}}
Reply
#28
Thanks - I've got json commands working from the command line using curl - will experiment with how to trigger through MQTT.

Thank-you.
Reply
#29
This is an awesome plugin! Is it possible to add an MQTT message when the plugin starts and one when it stops? I presume that would happen when the system itself starts or stops and I need it to cut the power my rPi on shutdown. I'll try to do this on my own, but have no experience with plugins on Kodi.
Reply
#30
Hello

I've been reading about this at work and have come straight home to try it out but unfortunately I'm struggling to get it to work.

I have a raspberry pi 3 running openelec krypton.
I have installed and setup the addon and configured it but I cannot get any messages to come up on my server. I'm using cloudmqtt (and have got this up and running with other services like owntracks which are receiving messages)
I've had a look at the server log file it seems to be getting a message from my external ip address (below) but no messages from kodi.
I'm using the ssl port listed on the server info page but I've also tried the websocket port tls
Do I need to install anything else other than the addon?
I've noticed that others are using with openelec but perhaps I've missed something.


1494954394: New connection from ***.**.**.*** on port 28404.
1494954396: OpenSSL Error: error:140780E5:SSL routines:SSL23_READConfusedsl handshake failure

Any help would be very appreciated.

Thanks in advance

Tim
Reply

Logout Mark Read Team Forum Stats Members Help
MQTT Adapter - Now forked (2022)0