-
Hi again, After getting the browser_mod popup to work last night, the next thing I'd like to do is use it to show the custom:mini-media-player card for any media_player element, as a hold_action. The popup is working when I hard code the element_id, but I want to pass the entity id of the element clicked on to the popup, to avoid duplicating lots of code. I've tried
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 17 replies
-
Unfortunately, I still haven't been able to find out if this is possible so I had no option but to repeat the code for each media player. To make it a little - but not much - cleaner, I used decluttering cards...
|
Beta Was this translation helpful? Give feedback.
-
So you'd like to pass a value related to the element you're triggering - and parsing that entity to browser_mod, only showing that card, instead of all the media-players? Your description let's me think about the xy-problem. I'm not really sure what you're hoping to do - other than a technical description of it 😄 . I hope it makes a bit of sense. I think there's two routes:
|
Beta Was this translation helpful? Give feedback.
-
☕ Did you find this useful, and would you like to say thanks? Buy me a coffee at: https://www.buymeacoffee.com/coffeetoexetico (Support my ha-floorplan work, say thanks for 1-to-1 help in discussions and whatever else you think about 😺) So @m90att ... More than three hours spend on this, cause I just noticed that many services (if not all?) can actually handle JavaScript as a data-input. That's somehow totally new information to me, which maybe sounds a bit off. But I've never had the needs to dig into the ha-instance like this. Now I've updated all things, and researched a bit. I noticed that browser_mod also supported a data-element, so... It's time to play. ... Here I provide you a fresh 🔥 example on how to really do things with magic. In the
name: Sonos
entities:
- media_player.sonos_kontor
- media_player.sonos_kokken
- media_player.sonos_badevaerelse
- media_player.sonos_stue
tap_action: media_player.media_play_pause
state_action:
- action: call-service
service: floorplan.class_set
service_data: "${entity.state}"
hold_action:
- action: call-service
service: floorplan.class_set
service_data:
class: |
>
try{
browser_mod.service('popup',{title: "Media player",
content:
{
type: "vertical-stack",
cards: [
/* Media player for that specific room */
{
type: "custom:mini-media-player",
entity: entity.entity_id, /* entity.entity_id is the reference from hold_action from ha-floorplan */
artwork: "full-cover",
hide: {
power: true
}
},
/* Auto-entitiy example, showing all from office - auto-entities is a custom lovelace function */
{
type: "custom:auto-entities",
card: {
type: "entities",
show_header_toggle: false
},
filter: {
include: [{group: "group.office"}]
}
}
]
}
})
return `${entity.state}`;
}catch(e){
console.log("Well.. That didn't go as planned");
}
Let me know if you have any questions. Tested with HA 2022.8.5 + browser_mod 2.1.3 @OzGav I'm sure you'll find this very interesting, too. Some Jazz was playing in the background.... OK.... Great? 😄 😆 |
Beta Was this translation helpful? Give feedback.
-
Hi, I second @OzGav's comment about great work! I actually managed to implement the solution using your code before you updated it with the execute function. Here it is...
which gives me this... You'll notice that I worked out the code for the speaker group. I used to know basic javascript but as I haven't used it in anger for a long time I find it difficult writing it now. Another benefit of the execute function is dynamic inclusion of devices for the speaker group, I think, however I don't want to include all devices so I haven't yet updated my code. What's your advice on that? |
Beta Was this translation helpful? Give feedback.
-
@m90att and then you could move the javascript into a custom function to make it useable in multiple places, passing in the relevant items as parameters. |
Beta Was this translation helpful? Give feedback.
Hi, I second @OzGav's comment about great work!
I actually managed to implement the solution using your code before you updated it with the execute function. Here it is...