Chromecast: Get current URL

Hi There,

Im using a Chromecast as audio sink for TTS. Works very good.
But when i am streaming any media the Chromecast does not resume the stream after the “say” command.

I want to do this manually in a rule but it seems that the “playurl” channel is just a receiver and has no url when startet externally.

How can i resume the chromecast playback after a TTS command?

best regards

Dominik

Has nobody an idea to resume the Chromecast?

Hi

I had forgotten that I’d programmed a doorbell sound to trigger on one of my Chomecast units.

This has worked well, until I was listening to the radio recently, when the doorbell was pressed (have these people no respect???)

So it got me wondering how I could get the Chromecast to resume.

With NodeRed it turned out to be quite easy.
I assume I could translate this to DSL if I needed to.

For anyone that is interested, here is the flow I used.

[
    {
        "id": "6e725766.ab4968",
        "type": "function",
        "z": "4747cc78.4ab0f4",
        "name": "Doorbell",
        "func": "var event = msg.payload.event;\nvar channel = msg.payload.channel;\nvar newMsg = { payload: msg.payload.event };\nvar button = \"velbus:vmb7in:d212bf44:0A:input#CH7\"\n\nif  (channel === button )  {\n\tif (event === \"PRESSED\") {\n\t\treturn [newMsg, null, null];\n\t}\n\tif (event === \"LONG_PRESSED\") {\n\t\treturn [null, newMsg, null];\n\t}\n\tif (event === \"RELEASED\") {\n\t\treturn [null, null, newMsg];\n\t}\n}\nreturn null;\n",
        "outputs": 3,
        "noerr": 0,
        "x": 180,
        "y": 540,
        "wires": [
            [
                "481e9802.be1b78"
            ],
            [],
            []
        ]
    },
    {
        "id": "4496d800.d07ea8",
        "type": "inject",
        "z": "4747cc78.4ab0f4",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 210,
        "y": 600,
        "wires": [
            [
                "481e9802.be1b78"
            ]
        ]
    },
    {
        "id": "481e9802.be1b78",
        "type": "openhab2-get",
        "z": "4747cc78.4ab0f4",
        "name": "Bathroom ChromeCast Status?",
        "controller": "deaa963.282a968",
        "itemname": "Bathroom_Control_Chromecast",
        "x": 477,
        "y": 528,
        "wires": [
            [
                "e2abadf2.30004",
                "d2b90b8d.111c48"
            ]
        ]
    },
    {
        "id": "d2b90b8d.111c48",
        "type": "switch",
        "z": "4747cc78.4ab0f4",
        "name": "Is Playing?",
        "property": "payload.state",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "PLAY",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "PLAY",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 490,
        "y": 600,
        "wires": [
            [
                "2a5d3dfa.1d0b42"
            ],
            [
                "cd67cdc5.72d6a"
            ]
        ]
    },
    {
        "id": "e2abadf2.30004",
        "type": "debug",
        "z": "4747cc78.4ab0f4",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload.state",
        "targetType": "msg",
        "x": 770,
        "y": 500,
        "wires": []
    },
    {
        "id": "2a5d3dfa.1d0b42",
        "type": "openhab2-get",
        "z": "4747cc78.4ab0f4",
        "name": "Bathroom Current URL",
        "controller": "deaa963.282a968",
        "itemname": "Bathroom_PlayURI",
        "x": 760,
        "y": 600,
        "wires": [
            [
                "45c12f4a.4d65d",
                "704a3997.03f108",
                "cd67cdc5.72d6a"
            ]
        ]
    },
    {
        "id": "cd67cdc5.72d6a",
        "type": "openhab2-out",
        "z": "4747cc78.4ab0f4",
        "name": "Bathroom Play URl - Doorbell",
        "controller": "deaa963.282a968",
        "itemname": "Bathroom_PlayURI",
        "topic": "ItemCommand",
        "payload": "http://192.168.178.42:8080/static/sounds/doorbell.mp3",
        "x": 510,
        "y": 700,
        "wires": [
            []
        ]
    },
    {
        "id": "704a3997.03f108",
        "type": "change",
        "z": "4747cc78.4ab0f4",
        "name": "Move .state to payload",
        "rules": [
            {
                "t": "move",
                "p": "payload.state",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 840,
        "y": 720,
        "wires": [
            [
                "46632c0.1fe92d4"
            ]
        ]
    },
    {
        "id": "45c12f4a.4d65d",
        "type": "debug",
        "z": "4747cc78.4ab0f4",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload.state",
        "targetType": "msg",
        "x": 1050,
        "y": 600,
        "wires": []
    },
    {
        "id": "46632c0.1fe92d4",
        "type": "delay",
        "z": "4747cc78.4ab0f4",
        "name": "",
        "pauseType": "delay",
        "timeout": "4",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 1060,
        "y": 720,
        "wires": [
            [
                "fbf6842a.089448"
            ]
        ]
    },
    {
        "id": "fbf6842a.089448",
        "type": "openhab2-out",
        "z": "4747cc78.4ab0f4",
        "name": "Bathroom Play  Previous URL",
        "controller": "deaa963.282a968",
        "itemname": "Bathroom_PlayURI",
        "topic": "ItemCommand",
        "payload": "",
        "x": 920,
        "y": 800,
        "wires": [
            []
        ]
    }
]

Here’s the logic that I applied :

  • Something is the doorbell trigger - In my case a Velbus button event, which has to be filtered from the openHAB2 events, rather than an openHAB2 Item change

  • Is the ChromeCast playing or paused?

  • If Paused / Stopped, - Just play the doorbell sound

  • If Playing -

  • Capture currently playing URL

  • – Then play the doorbell (so that the doorbell URL isn’t the information captured)

  • Move the Previous URL from msg.payload.state to msp.payload

  • Delay the message (I choose 4 seconds)

  • Restore the Previous URL to the Chromecast

3 Likes

You could have made a rule to send a TTS back to the doorbell (which ofcouse has intercom), telling these people to get lost, while you´re listning to the radio
:smiley:

Hit it!

I could, but it might be our friendly postman, and as they do a difficult job anyway, I wouldn’t want to upset him.

Yeah, because I’ve got nothing else taking up my time…

Thats exactly what I thought :slight_smile:

items
String        LivingRoomSpeaker_Playuri_backup    "Play uri backup"

rule 
when
    Item received command 
then
    if (LivingRoomSpeaker_AppId.state == "CC1AD845" && LivingRoomSpeaker_Control.state == PLAY) {
    LivingRoomSpeaker_Playuri_backup.postUpdate(LivingRoomSpeaker_Playuri.state)
    playSound("doorbell.mp3")
    Thread::sleep(3000)
    LivingRoomSpeaker_Playuri.sendCommand(LivingRoomSpeaker_Playuri_backup.state.toString)
    LivingRoomSpeaker_Control.sendCommand(PLAY) }
    else {playSound("barking.mp3")}
end
1 Like

Unfortunately this trick doesn’t work when currently playing something from youtube

1 Like

Only
AppId: CC1AD845
App: Default Media Receiver

So there is still no solution for all types of media? (e.g. GPM, YT, YTM)