ioBroker.lovelace icon indicating copy to clipboard operation
ioBroker.lovelace copied to clipboard

Kodi as a Media Player

Open agross opened this issue 3 years ago • 22 comments

Describe the bug

I'd like to use my Kodi instance as a Lovelace Media Player. Some features of the media player card do not work.

I created an alias device with all the states required to detect a media player. Most things work, except:

  • Mute: It seems the state needs to be set with ack = false, but LL sets it with ack = true
  • Pause button:
    lovelace.0 (29155) Unknown service: media_pause ({"type":"call_service","domain":"media_player","service":"media_pause","service_data":{},"id":69})
    
  • Progress bar: only updated sometimes (didn't find a pattern yet), sometimes just greyed out: 2021-11-27_12-12-03

Versions:

  • Adapter version: Latest
  • JS-Controller version: Latest
  • Node version: 12
  • Operating system: docker

agross avatar Nov 27 '21 11:11 agross

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. Dieses Problem wurde automatisch als veraltet markiert, da es in letzter Zeit keine Aktivitäten gab. Es wird geschlossen, wenn nicht innerhalb der nächsten 7 Tage weitere Aktivitäten stattfinden. Bitte überprüft, ob das Problem auch in der aktuellsten Version des Adapters noch relevant ist, und teilt uns dies mit. Überprüft auch, ob alle relevanten Details, Logs und Reproduktionsschritte enthalten sind bzw. aktualisiert diese. Vielen Dank für Eure Unterstützung.

stale[bot] avatar Apr 17 '22 06:04 stale[bot]

Unstale

agross avatar Apr 17 '22 06:04 agross

Sorry, had no time to look into this, yet...

For me to reproduce, can you supply me with an object export of your alias device? (admin UI -> objects tab, select the whole device folder and press export, somewhere at the top).

Also, just out of interest, could you do the same for the kodi objects? I'd like to see if they can be detected by type-detector.

Garfonso avatar Jun 05 '22 09:06 Garfonso

Sure, see attached files:

kodi.0.json.zip alias.0.kodi.json.zip

The alias was created based on what I understood from the type-detector. Not the easiest code to understand!

agross avatar Jun 07 '22 14:06 agross

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. Dieses Problem wurde automatisch als veraltet markiert, da es in letzter Zeit keine Aktivitäten gab. Es wird geschlossen, wenn nicht innerhalb der nächsten 7 Tage weitere Aktivitäten stattfinden. Bitte überprüft, ob das Problem auch in der aktuellsten Version des Adapters noch relevant ist, und teilt uns dies mit. Überprüft auch, ob alle relevanten Details, Logs und Reproduktionsschritte enthalten sind bzw. aktualisiert diese. Vielen Dank für Eure Unterstützung.

stale[bot] avatar Sep 21 '22 05:09 stale[bot]

Unstale

agross avatar Sep 21 '22 06:09 agross

The LL builtin media player card only sends media_play or media_pause. Both commands are not registered by ioBroker.lovelace, only media_play_pause, which might a legacy way of handling play/pause.

I also use the mini-media-player card which sends media_play_pause, but also media_play and media_pause.

agross avatar Nov 25 '22 13:11 agross

After some more research:

    • Progress bar: only updated sometimes

    Doesn't work because if media_position is updated, media_position_updated_at also needs to change (e.g. by assigning state.lc or a Date).

  • Seeking does not work because it's never checked whether the media player object has a SEEK state.

  • REPEAT is also not checked, hence no support for repeating songs.

  • Mute and shuffle buttons do not work because the Media Player cards expect booleans, but iobState2EntityState maps state values to on and off which is not understood by either Media Player card (builtin and mini).

agross avatar Nov 25 '22 17:11 agross

I've got a dirty hack in https://github.com/agross/ioBroker.lovelace if you are interested. Fixes the problems mentioned above (except repeat).

agross avatar Nov 25 '22 17:11 agross

I've got a dirty hack in https://github.com/agross/ioBroker.lovelace if you are interested. Fixes the problems mentioned above (except repeat).

Can you share how you fixed it? i have a similar problem with Sonos speakers. The media_play does not work

Dalmapalma avatar Jan 04 '23 21:01 Dalmapalma

@Dalmapalma The relevant parts are in the "Testing" commit by me here: https://github.com/agross/ioBroker.lovelace/blame/master/lib/converters/media_player.js#L124

The ioBroker state responsible for play and pause needs to be detectable by ioBroker's type-detector, see here: https://github.com/ioBroker/ioBroker.type-detector/blob/master/index.js#L121

It's all rather complicated to explain and I do not know how deep your knowledge regarding this is. I too needed to read a lot of code because most of it is undocumented. But the basic idea is that

  1. ioBroker states are inspected by the aforementioned type-detector
  2. ioBroker.lovelace by default only inspects states that have a function and room assigned
  3. For such states the type-detector needs to have determined that it is a media player as per the definition in the link above which contains must-have features (e.g. play) and optional features (e.g. seek)
  4. For devices that are detected as a media player, ioBroker.lovelace will make entities available for you to place on the UI
  5. A click on the e.g. play button sets the corresponding ioBroker state to a certain value
  6. Sometimes the value set needs to be remapped to another value, but not in the case of play and pause

Did that help?

agross avatar Jan 04 '23 21:01 agross

@Dalmapalma The relevant parts are in the "Testing" commit by me here: https://github.com/agross/ioBroker.lovelace/blame/master/lib/converters/media_player.js#L124

The ioBroker state responsible for play and pause needs to be detectable by ioBroker's type-detector, see here: https://github.com/ioBroker/ioBroker.type-detector/blob/master/index.js#L121

It's all rather complicated to explain and I do not know how deep your knowledge regarding this is. I too needed to read a lot of code because most of it is undocumented. But the basic idea is that

  1. ioBroker states are inspected by the aforementioned type-detector
  2. ioBroker.lovelace by default only inspects states that have a function and room assigned
  3. For such states the type-detector needs to have determined that it is a media player as per the definition in the link above which contains must-have features (e.g. play) and optional features (e.g. seek)
  4. For devices that are detected as a media player, ioBroker.lovelace will make entities available for you to place on the UI
  5. A click on the e.g. play button sets the corresponding ioBroker state to a certain value
  6. Sometimes the value set needs to be remapped to another value, but not in the case of play and pause

Did that help?

Puuhhh I tried to follow your steps. I think steps 1-5 are ok. My device/entity is configured properly. It has the required features, as well as for the play Bildschirm­foto 2023-01-04 um 21 18 00

regarding step 6, i was thinking as well if something needs to be remapped. Currently the play-State is configured as button.play. Maybe I need something different? a boolean?

Dalmapalma avatar Jan 05 '23 00:01 Dalmapalma

This is my media.state role: https://github.com/agross/iobroker-scripts/blob/master/home/Automation/Media_Player.ts#L135-L148

As you can see there is a mapping for the read side from kodi.0.state to the alias where what Kodi calls play is translated to 1, stop to 2, otherwise 0. Whatever value is written to the alias will cause kodi.0.pause to be set with true.

agross avatar Jan 05 '23 11:01 agross

For your reference, these are the attributes ioBroker.lovelace assigned for my alias:

entity_picture: alias.0.kodi.0.cover-big
friendly_name: Kodi
icon: mdi:play-network
is_volume_muted: alias.0.kodi.0.mute
media_artist: alias.0.kodi.0.artist
media_content_type: unknown
media_duration: alias.0.kodi.0.duration
media_position: alias.0.kodi.0.elapsed
media_position_updated_at:
media_title: alias.0.kodi.0.title
repeat: alias.0.kodi.0.repeat
shuffle: alias.0.kodi.0.shuffle
supported_features: 316479
volume_level: alias.0.kodi.0.volume

agross avatar Jan 05 '23 12:01 agross

@agross thanks for your research. I am currently implementing the things you mentioned.

The master branch should reflect your findings. Can you test with it?

I don't really see what should not work with the repeat functionality (give an alias with the right conversion is set up). From my examples, it seems that 1 means "repeat all" and 2 "repeat one"... but I'm not sure about that.

@Dalmapalma from what I see, a Sonos device should be detected as media_player by default. If you supply the device itself (i.e. sonos.0.root.192_168_10_254 in your case) with room & function, do you see a media device pop up in the devices tab of iobroker?

Garfonso avatar Jan 05 '23 14:01 Garfonso

I don't really see what should not work with the repeat functionality

My fork added the check for a REPEAT state, as does your latest commit in master. Previously REPEAT was unchecked as far as I can tell.

From my examples, it seems that 1 means "repeat all" and 2 "repeat one"... but I'm not sure about that.

As for the different repeat states, the mini media player uses this enum and uses indexOf to cycle to the next repeat state. I think your mapping is off in this regard. Or maybe mine.

agross avatar Jan 05 '23 15:01 agross

Fixes the problems mentioned above (except repeat).

My comment about repeat was directed at this statement, you wrote earlier.

What mini media player does internally is of no concern for the adapter. The HomeAssistant side expects values of 'off', 'all' or 'one'. mini media player handles them and decides what to send if the user does something with the enum and indexOf you linked. It will send out one of 'off', 'all' or 'one' which the adapter has to process and translate into an ioBroker value. So the adapter code will never see the enum or the index, mini media player reads from it.

On the iobroker side type-detector expects a number. But many media players only have a boolean, as it seems. Also, it is not specified which numbers mean what (or at least not documented). The only media player I found that has a number for repeat is the Sonos and there 1 means "all" and 2 means "one". So I took that translation. All others will either require changes in type-detector or aliases.

Garfonso avatar Jan 05 '23 18:01 Garfonso

@Garfonso This is what I hoped to see...under "Native Devices" my Sonos devices are listed, but they do not show up in Lovelace as a Media Player. Bildschirm­foto 2023-01-06 um 10 11 25

This is why I started to create Aliase-Devices.

EDIT:

I changed the functions for the native devices and now they are showing up 😊 But still the play function does not work. I tried to install a custom-card "Mini media player" and there it's working

Dalmapalma avatar Jan 06 '23 09:01 Dalmapalma

If a device is in native devices but not in lovelace, then one possibility is, that you configured lovelace to create automatic entities only from alias.0.* Also the devices will always need room & function set (I'm not 100% sure if that is the case in native devices).

A third possibility is, that support in the adapter is still lacking, but that is not the case for media devices. 😁

Garfonso avatar Jan 14 '23 15:01 Garfonso

Play function is repaired in latest github version. If you feel lucky, you can install that (use admin, in expert view there is a github button where you can install an adapter from github directly). If something breaks, you can just switch back to the latest version in admin.

Garfonso avatar Jan 14 '23 15:01 Garfonso

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. Dieses Problem wurde automatisch als veraltet markiert, da es in letzter Zeit keine Aktivitäten gab. Es wird geschlossen, wenn nicht innerhalb der nächsten 7 Tage weitere Aktivitäten stattfinden. Bitte überprüft, ob das Problem auch in der aktuellsten Version des Adapters noch relevant ist, und teilt uns dies mit. Überprüft auch, ob alle relevanten Details, Logs und Reproduktionsschritte enthalten sind bzw. aktualisiert diese. Vielen Dank für Eure Unterstützung.

stale[bot] avatar May 09 '23 01:05 stale[bot]

unstale

agross avatar May 09 '23 08:05 agross

@Garfonso I was finally able to test this with ioBroker.lovelace 4.1.10, ioBroker.kodi 3.1.0, Kodi 21 and my Kodi alias that provides cover images. Everything seems to be working fine. I didn't check whether kodi.<instance>.* states alone would work.

agross avatar Jun 16 '24 15:06 agross