meingraham
(Michael Ingraham)
November 28, 2018, 3:47pm
21
I wonder if the Title channel of the Chromecast Thing is equivalent? One could link a String Item to the channel and use that in the Rules logic that would implement the same delay logic presented in the Python script you posted. I’ll bookmark this for a future enhancement to my Chromecast notifications logic.
Thanks.
Mike
1 Like
yfaway
(YF)
November 28, 2018, 10:39pm
22
Yes it is the title channel. You can do the same thing with xtend as well.
String FF_GreatRoom_ChromeCastTitle "Title [%s]"
{ channel="chromecast:audio:greatRoom:title" }
meingraham
(Michael Ingraham)
December 18, 2018, 8:31pm
23
Here is the Title check implemented as openHAB Rules code:
Group gChromecastsTitle
Player myAudioPlayer
"Google Home"
String myAudioPlayer_title
"Google Home: Title" (gChromecastsTitle)
val Functions.Function1<String,String> getChromecastSink = [ String itemName |
try
{
val allLinks = sendHttpGetRequest("http://localhost:8080/rest/links")
var String filter = "$..[?(@.itemName=='"+itemName+"')].channelUID"
var output = transform("JSONPATH", filter, allLinks)
var chromecastSink = output.split(":").get(0)+":"+output.split(":").get(1)+":"+output.split(":").get(2)
return chromecastSink
}
catch(Exception e)
{
logError("myLog", "Failure in getChromecastSink: {}", e.toString)
return null
}
]
var String itemName = null
var String broadcastMessage = null
var Timer tBroadcastWait = null
rule "Broadcast Notification"
when
Item VT_messageBroadcast received update
then
try
{
// If it's between 8am and 10pm, broadcast to a message
if ((now.getHourOfDay > 07) && (now.getHourOfDay < 22))
{
itemName = VT_messageBroadcast.state.toString
broadcastMessage = null
if (itemName.contains(";"))
{
broadcastMessage = itemName.split(";").get(1)
itemName = itemName.split(";").get(0)
}
val audioSink = getChromecastSink.apply(itemName)
playSound(audioSink, "dingding.mp3")
if (broadcastMessage !== null)
{
tBroadcastWait = createTimer(now.plusSeconds(1), [ |
if (gChromecastsTitle.members.filter [titleItem | titleItem.name == (itemName + "_title")].head.state == "Notification")
{
tBroadcastWait.reschedule(now.plusSeconds(1))
}
else
{
tBroadcastWait = null
say(broadcastMessage, "voicerss:enUS", audioSink)
}
])
}
}
}
catch(Exception e)
{
logError("myLog", "Failure in Broadcast Notification: {}", e.toString)
}
end
2 Likes