Hi all,
I’m trying to automate some sliders that control the volume of some Chromecasts and are also updated when the volume is changed by another method. However, when you slide the volume control (in the Home app or Spotify app, for example) it triggers a state change for every level of volume in between the start and final value, which causes some problems with the feedback loop to update the slider.
I have tried to add the duration = t
parameter so that the callback on triggers once the volume has settled on the final value, but it does not seem to make any difference. It could also be something to do with how I’ve built the app, but I was expecting this to solve the problem based on the documentation.
Am I using this right?
Code below:
# Chromecast volume card
#
# Args:
# name: name of chromecast
#
class ChromecastVolume(appapi.AppDaemon):
def initialize(self):
self.name = self.args['name']
self.slider = "input_slider.chromecast_volume_{}".format(self.name)
self.sensor = "sensor.chromecast_volume_{}".format(self.name)
self.media_player = "media_player.{}".format(self.name)
# !!!!
# check duration parameter - slide volume change still fires multiple service calls
# !!!!
self.listen_state(self.update_slider, entity = self.sensor, duration = 1)
self.listen_state(self.update_volume, entity = self.slider)
self.listen_state(self.mute_on, entity = "input_boolean.chromecast_mute", new = "on")
self.listen_state(self.mute_off, entity = "input_boolean.chromecast_mute", new = "off")
def update_volume(self, entity, attribute, old_state, new_state, kwargs):
sensor_value = self.get_state(self.sensor)
set_cc_vol = float(new_state) / 10
if sensor_value != set_cc_vol:
self.log("update volume from {} to {}".format(sensor_value, new_state))
self.call_service("media_player/volume_set", entity_id = self.media_player, volume_level = set_cc_vol)
def update_slider(self, entity, attribute, old_state, new_state, kwargs):
slider_value = self.get_state(self.slider)
set_slider_vol = float(new_state) * 10
if slider_value != set_slider_vol:
self.log("update slider from {} to {}".format(slider_value, new_state))
self.call_service("input_slider/select_value", entity_id = self.slider, value = set_slider_vol)
def mute_on(self, entity, attribute, old_state, new_state, kwargs):
self.call_service("media_player/volume_mute", entity_id = self.media_player, is_volume_muted = "true")
def mute_off(self, entity, attribute, old_state, new_state, kwargs):
self.call_service("media_player/volume_mute", entity_id = self.media_player, is_volume_muted = "false")