Sonos Plugin elapsed time

Posted on
Mon Jun 18, 2018 6:45 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Sonos Plugin elapsed time

Hi,
I need some python help. Im trying to calculate percent elapsed time for a song in the songs plugin.

The current attribute REMAINING actually counts up from 0:00 to the DURATION of the song.
I'd like to move the REMAINING time into a variable called ElapsedTime and then calculate remaining time.
I got started with the following but I'm already getting errors.

varMusicElapsedTime = indigo.variables[1086500855]
varMusicRemainingTime = indigo.variables[1086500892]
varSonos = indigo.devices[1475651238]
varMusicElapsedTime.value = varSonos.Remaining

Indigo is complaining about the attribute REMAINING not existing.

Thanks

Posted on
Mon Jun 18, 2018 8:16 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Sonos Plugin elapsed time

philipbasile wrote:
Hi,
I need some python help. Im trying to calculate percent elapsed time for a song in the songs plugin.

The current attribute REMAINING actually counts up from 0:00 to the DURATION of the song.
I'd like to move the REMAINING time into a variable called ElapsedTime and then calculate remaining time.
I got started with the following but I'm already getting errors.

varMusicElapsedTime = indigo.variables[1086500855]
varMusicRemainingTime = indigo.variables[1086500892]
varSonos = indigo.devices[1475651238]
varMusicElapsedTime.value = varSonos.Remaining

Indigo is complaining about the attribute REMAINING not existing.

Thanks

Firstly, Indigo variables are stored as strings so you need to convert them to numbers (I assume they're integers here):
Code: Select all
varMusicElapsedTime = int(indigo.variables[1086500855])
varMusicRemainingTime = int(indigo.variables[1086500892])
varSonos = indigo.devices[1475651238]
varMusicElapsedTime.value = varSonos.Remaining

Secondly, I believe that you're looking for a device state (not a device property), which is referenced like this (note that I also removed the dot from your last variable name):
Code: Select all
varMusicElapsedTime = int(indigo.variables[1086500855])
varMusicRemainingTime = int(indigo.variables[1086500892])
varSonos = indigo.devices[1475651238]
varMusicElapsedTimeValue = varSonos.states['Remaining']

If you post the dict of your device (be sure to mask any sensitive data) it would help to diagnose your issue.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jun 26, 2018 7:39 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Re: Sonos Plugin elapsed time

Thank You !
How do I post the dict (dictionary ?)

Posted on
Tue Jun 26, 2018 8:08 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Re: Sonos Plugin elapsed time

I could do this in VB is a few minutes, I hate not knowing python syntax !
Here is what I have...
I get an error on the last line "key remaining not found in dict"

varMusicElapsedTime =indigo.variables[1086500855] # "MusicElapsedTime"
varMusicRemainingTime = indigo.variables[1552641211] # "MusicRemainingTime"
varSonos = indigo.devices[1475651238] # "Sonos"

varMusicElapsedTime = varSonos.states['remaining']


Here is what I'm trying to do
I'd like to first put the Remaining time (which is really the elapsed time) into a correctly named variable, varElapsedTime, in secs.
Then I need to put the song Duration into a variable varDuration in secs
Then I need to convert the now correctly named varElapsedTime to a percentage of a 360 degree circle where 360 degrees is the duration of the song.
Then I need the varElapsedDegrees to be on 15 degree boundries since my elapsed graphics for my control page are on 15 degree increments

Here is the math

varDegrees = (360 * varElapsedTime) / varDuration
varDegrees = Int(varDegrees / 15) * 15

I there a time function to convert to secs ?

Thanks for the help

Philip

Posted on
Wed Jun 27, 2018 1:39 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Sonos Plugin elapsed time

to get the variable as a number:
Code: Select all
varMusicElapsedTime =indigo.variables[1086500855] # "MusicElapsedTime"
valueAsString = varMusicElapsedTime.value
valueAsNumber = int(valueAsString)
in one line:
Code: Select all
valueAsNumber = int(indigo.variables[1086500855] .value)
then normal math
eg
Code: Select all
newValue = valueAsNumber / 60
to update a variable:
Code: Select all
indigo.variable.updateValue(1086500855, value= str(newValue))
check out this page:https://wiki.indigodomo.com/doku.php?id=indigo_7_documentation:plugin_scripting_tutorial

hope that helps

Karl

Posted on
Wed Jun 27, 2018 7:46 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Re: Sonos Plugin elapsed time

Thank You Dave and KW for all the help getting me on the right track!

Here is what I ended up with...
I snuck some code off a python site for converting H:M:S to secs and it all works now.

import datetime

varSonos = indigo.devices[1475651238]
varMusicDuration = varSonos.states['ZP_DURATION']
varMusicElapsedTime = varSonos.states['ZP_RELATIVE']

varMusicElapsedSecs = sum(x * int(t) for x, t in zip([3600, 60, 1], varMusicElapsedTime.split(":")))
varMusicDurationSecs = sum(x * int(t) for x, t in zip([3600, 60, 1], varMusicDuration.split(":")))
varMusicRemainingSecs = varMusicDurationSecs - varMusicElapsedSecs

varMusicDegrees = (360*varMusicElapsedSecs)/varMusicDurationSecs
varMusicDegrees = int(varMusicDegrees/15)*15

indigo.variable.updateValue(1086500855, str(varMusicElapsedTime))
indigo.variable.updateValue(790247935, str(varMusicDuration))
indigo.variable.updateValue(419456527, str(varMusicDegrees))

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests