For a while i have wanted to control itunes from domoticz.
The methods do do this are not new - but i haven't seen it laid out on here, so thought i would share incase it's useful for anyone.
I should also note that this is not full control, but you can start itunes, play, pause, next, back, play track, and select and play playlists ( on shuffle if you want ). The only thing i wish we could achieve now is toggling airplay speakers on/off. if anyone has any ideas let me know

we have an itunes server running on a sumvision cyclone - windows 10. This runs very well .
This serves a number of apple tv's through airplay.
We have just been using the ios "itunes remote" app to control itunes, and this works ok - but since getting the amazon echo, thought it would be nice to control itunes by voice through that.
There are lots of "apple scripts" to control itunes very well on mac. and i there are also many more features. But for those like me with no mac, we can use visual basic ( filename.vbs ), and also powershell ( filename.ps1).
play, pause and skip commands
to create the play, pause and skip commands; i created a vbs for each. ( i will come to playlists later on - dont use the one on here if you want random play )
a full list of vb scripts i found here: https://github.com/ralesi/modal.ahk/tre ... and/iTunes
I wont copy out all the scripts here, but you can just copy and paste the while file into notepad, then save as your_file_name.vbs
i used itunes_play.vbs etc.. I would recommend creating a folder for them all.
I run my main domoticz on a Pi. I couldnt find a straightforward way of firing the vbs files on the windows box from my pi. I think there is a way, and some people have used eventghost. Event ghost looks like it could be good for future use, but i couldn't get my head around it quickly and lost patience, so just installed a 2nd domoticz on the windows box, alongside itunes.
on the windows domoticz, i now created push on buttons for each vbs file i wanted to trigger ( play, pause, next etc.. ).
THen on the on action: script://C:\Users\sion\Documents\scripts\next.vbs
Now when i click on the play switch in domoticz, itunes opens up ( if its not already open ) and starts playing

Playlists
Currently i cannot get it to play applemusic playlists. Although as im typing this, i wonder if its because i haven't downloaded them to the local machine? i will test this later. But all other playlists work,
I could not get the vbs playlist method to work correctly on shuffle, so i found a poweshell method.
create this .ps1 file:
Code: Select all
<#
.SYNOPSIS
Plays an iTunes playlist.
.DESCRIPTION
Opens the Apple iTunes application and starts playing the given iTunes playlist.
.PARAMETER Source
Identifies the name of the source.
.PARAMETER Playlist
Identifies the name of the playlist
.PARAMETER Shuffle
Turns shuffle on (else don't care).
.EXAMPLE
.\Start-PlayList.ps1 -Source 'Library' -Playlist 'Party'
.INPUTS
None
.OUTPUTS
None
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
$Source
,
[Parameter(Mandatory=$true)]
$Playlist
,
[Switch]
$Shuffle
)
try {
$iTunes = New-Object -ComObject iTunes.Application
}
catch {
Write-Error 'Download and install Apple iTunes'
return
}
$src = $iTunes.Sources | Where-Object {$_.Name -eq $Source}
if (!$src) {
Write-Error "Unknown source - $Source"
return
}
$ply = $src.Playlists | Where-Object {$_.Name -eq $Playlist}
if (!$ply) {
Write-Error "Unknown playlist - $Playlist"
return
}
if ($Shuffle) {
if (!$ply.Shuffle) {
$ply.Shuffle = $true
}
}
$ply.PlayFirstTrack()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$iTunes) > $null
[GC]::Collect()
This file is like the back end code. you don't need to edit it.
you may however need to enable running powershell on the pc. For windows 10 see here:https://www.tenforums.com/tutorials/545 ... -10-a.html - you may need to google for other windows versions.
to run selected playlists, we need to now create a .bat file for each one we want to use.
Inside the .bat file is the command that runs the powershell script, and inputs the variables for the playlist name etc..
The .bat file should look like this:
Code: Select all
@ECHO OFF
PowerShell.exe -Command "& '\Users\sion\Documents\scripts\Start-PlayList.ps1'" -Source "library" -Playlist "playlist_name" -Shuffle
Swat out playlist_name for the name of your playlist. If you playlist is more than one word, you need to double quote it, as it doesnt seem to deal with spaces well.
Code: Select all
-Source "library" -Playlist "'playlist name'"
now, point a domoticz button to the .bat file. when pressed, it fires up itunes, and starts shuffling the playlist.
Repeat this for any other playlists you want.
So now we have domoticz controlling itunes on windows. From here, having alexa / echo controlling itunes is as simple as running HA Bridge on either machine, and then add the domotics buttons to it. ( see wiki http://www.domoticz.com/wiki/Alexa )
You may need to be creative with your button names, as "alexa, turn on play" and even "alexa, turn on itunes play" confused it.
i used Resume, Halt, and skip. playlist names weren't an issue.