Jay, Dave and Joe, thank you all for your interest in helping me through this. So far, the two scripts work correctly independently of one another when put in separate triggers. However since both triggers fire with the string variable change, while one will work correctly for the zone/volume and the other will work correctly with bass/treble, the other trigger will log an error.
I combined the two adapted scripts in the hopes that the selector text that Jay put in would allow the script to run the appropriate code:
- Code: Select all
vaux_response_string = indigo.variables[1925362107].value #VauxResponse variable
junk, command, details = vaux_response_string.split(',', 2)
# details now has the string after the second comma in it, for instance "2,5,4"
# Determine what to do next
if command == "1":
# Log the zone and it's settings
vaux_zone_number, fourth_value, vaux_source_setting, vaux_volume_number1, vaux_volume_number2, vaux_bass_setting, vaux_treble_setting = details.split(",")
indigo.server.log("{} {} {}".format(vaux_zone_number, vaux_source_setting, vaux_volume_number1))
# This is a more Pythonic way of doing your zone number map
zone_map = {
"0": "Off",
"1": "Kitchen",
"2": "FamRm",
"3": "Study",
"4": "LivDnRm",
"5": "GameRm",
"6": "Patio",
"7": "Pool",
"8": "MBR",
}
source_map = {
"0": "Off",
"1": "Tuner",
"2": "iTunes",
"3": "AirPlay",
"4": "Cable",
}
# Save off the current zone name for use later in case it doesn't change for some reason
vaux_zone_variable = indigo.variables[519871620] #VauxZoneName
temp_zone_name = vaux_zone_variable.value
# If the zone number from the list is in the map's keys, save off the new name and set the Indigo variable
if vaux_zone_number in zone_map.keys():
temp_zone_name = zone_map[vaux_zone_number]
indigo.variable.updateValue(vaux_zone_variable, value=temp_zone_name)
vaux_source_variable = indigo.variables[1890620001] #VauxSourceName
temp_source_name = vaux_source_variable.value
if vaux_source_setting in source_map.keys():
temp_source_name = source_map[vaux_source_setting]
indigo.variable.updateValue(vaux_source_variable, value=temp_source_name)
vaux_volume_variable = vaux_volume_number1 #vauxZoneVolume
indigo.variable.updateValue(1699344874, vaux_volume_number1)
vaux_source_setting = indigo.variables[1890620001]
# Create the string that's going to be set in the variable and logged
new_string_value = "{} {} {} ".format(temp_zone_name, temp_source_name, vaux_volume_number1)
# Set the Indigo variable
indigo.variable.updateValue(1932988370, value=new_string_value) #vauxResponseOutputShort
# Log the string
indigo.server.log(new_string_value)
vaux_response_string = indigo.variables[1925362107].value #VauxResponse variable
junk, command, details = vaux_response_string.split(',', 2)
# details now has the string after the second comma in it, for instance "2,5,4"
# Determine what to do next
if command == "40":
# Log the zone and it's settings
#indigo.server.log("{} {} {}".format(vaux_zone_number, vaux_bass_setting, vaux_treble_setting))
vaux_zone_number,vaux_bass_setting, vaux_treble_setting = details.split(",")
indigo.server.log("{} {} {}".format(vaux_zone_number, vaux_bass_setting, vaux_treble_setting))
# This is a more Pythonic way of doing your zone number map
zone_map = {
"0": "Off",
"1": "Kitchen",
"2": "FamRm",
"3": "Study",
"4": "LivDnRm",
"5": "GameRm",
"6": "Patio",
"7": "Pool",
"8": "MBR",
}
# Save off the current zone name for use later in case it doesn't change for some reason
vaux_zone_variable = indigo.variables[519871620] #VauxZoneName
temp_zone_name = vaux_zone_variable.value
# If the zone number from the list is in the map's keys, save off the new name and set the Indigo variable
if vaux_zone_number in zone_map.keys():
temp_zone_name = zone_map[vaux_zone_number]
indigo.variable.updateValue(vaux_zone_variable, value=temp_zone_name)
# Create the string that's going to be set in the variable and logged
new_string_value = "{} Bass {} Treble {}".format(temp_zone_name, vaux_bass_setting, vaux_treble_setting)
# Set the Indigo variable
indigo.variable.updateValue(1963098885, value=new_string_value)
# Log the string
indigo.server.log(new_string_value)
Here are the responses when setting source in the Game Room zone. The script runs correctly and both the zone/source/volume and bass/treble scripts run.
However, when trying to change the bass/treble, the script hangs on the zone/source/volume sections. So it looks like it is not passing over the zone/source/volume to execute only the bass/treble.
- Code: Select all
Mar 28, 2020 at 10:56:59 AM
>>>>>>>>>>>>>>>>Turn off Game Room
Simple Serial Plugin Response from serial device (text): !S,1,5,0,0,0,0,6,8
, of length 20 characters
Script 5 0 0
Script GameRm Off 0
Script GameRm Bass 6 Treble 8
Simple Serial Plugin Response from serial device (text): !S,1,5,0,0,0,0,6,8
, of length 20 characters
Simple Serial Plugin Response from serial device (text): , of length 0 characters
>>>>>>>>>>>>>>>>>>>> Change Bass/Treble
Simple Serial Plugin Response from serial device (text): !S,40,5,6,7. <<<<<<<<<< 40 = bass/treble string, 5 = zone Game Room, 6 = bass setting, 7 = treble setting
, of length 13 characters
Script Error Vaux Python Parser 200328.py: local variable 'vaux_zone_number' referenced before assignment
Script Error Exception Traceback (most recent call shown last):
Vaux Python Parser 200328.py, line 40, at top level
UnboundLocalError: local variable 'vaux_zone_number' referenced before assignment
>>>>>>>>>>>>>>>>> Again
Simple Serial Plugin Response from serial device (text): !S,40,5,6,6 <<<<<<<<<<< new string with change showing treble lowered to 6
, of length 13 characters
Script Error Vaux Python Parser 200328.py: local variable 'vaux_zone_number' referenced before assignment
Script Error Exception Traceback (most recent call shown last):
Vaux Python Parser 200328.py, line 40, at top level
UnboundLocalError: local variable 'vaux_zone_number' referenced before assignment
>>>>>>>>>>>>>>>>> Again
Simple Serial Plugin Response from serial device (text): !S,40,5,6,5
, of length 13 characters
Script Error Vaux Python Parser 200328.py: local variable 'vaux_zone_number' referenced before assignment
Script Error Exception Traceback (most recent call shown last):
Vaux Python Parser 200328.py, line 40, at top level
UnboundLocalError: local variable 'vaux_zone_number' referenced before assignment
>>>>>>>>>>>>change the volume once again. Now the script works correctly to process the zone/source/volume as well as bass/treble.
Mar 28, 2020 at 10:58:01 AM
Simple Serial Plugin Response from serial device (text): !S,1,5,1,1,29,29,6,5
, of length 22 characters
Script 5 1 29. <<<<<<<Zone Source Volume
Script GameRm Tuner 29 <<<<<<<<<<<<< Correct
Script GameRm Bass 6 Treble 5 <<<<<<<< Correct
Overall the simplest thing to do is to ignore the problem, because I rarely change the bass/treble, but I'd like to get it to work if possible. Maybe the easiest thing is to just put these two separate scripts into different triggers with a conditional based the selector, but I could not figure out how to get to resolve to "true" to let the trigger execute.