from homeassistant import const DOMAIN = 'mute_light_old' HASS = None DEPENDENCIES = [] def setup(hass, config): global HASS HASS = hass hass.states.track_change("switch.living_room_mute", light_with_mute) return True def light_with_mute(entity_id, s_from, s_to): """ toggle a red light when mute is on """ mute_state = s_to.state is_muted = mute_state == const.STATE_ON if is_muted: HASS.services.call('light', 'turn_on', {"entity_id": "light.livingcolors_2", "brightness": 255, "rgb_color": [255, 0, 0]}, True) else: HASS.services.call('light', 'turn_off', {"entity_id": "light.livingcolors_2"}, True)