No need to convert it since it doesn't target the Indigo Server - it's perfectly fine to keep it running just like that.
However, if you're using the iTunes plugin, you can also do it in Python (with lots of comments to explain):
- Code: Select all
import time
tick = 1
thismany = 20
# We need to get the plugin instance in order to call plugin actions
itunesPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.itunes")
# Get the iTunes Server Indigo instance so that we can get the volume.
itunesDevice = indigo.devices[1234567890] # ID of your iTunes server device in Indigo
while True:
# Save the current sound level as an integer
snd = int(itunesDevice.states['volume'])
# Compare to tick
if snd <= tick:
# Set the volume to 0 and break out of the while loop
itunesPlugin.executeAction("setVolume", deviceId=1234567890, props={'volume':0})
break
# Decrement the sound by tick
itunesPlugin.executeAction("setVolume", deviceId=1234567890, props={'volume': snd-tick})
# sleep thismany seconds
time.sleep(thismany)
# Refresh the iTunes device since we have a local copy and it could have changed while
# we were sleeping
itunesDevice.refreshFromServer()
# Pause iTunes
itunesPlugin.executeAction("pause", deviceId=135305663)
# Unclear why the next line is in there since you don't seem to be using snd anymore
# and you know that when you get here the volume is 0, but for completeness
snd = 0
# Set the volume back to full
itunesPlugin.executeAction("setVolume", deviceId=1234567890, props={'volume': 100})
Untested, but it's pretty close. You'll obviously want to run this as an external script since it has sleep statements in it so it is by nature a long-running script.