from homeassistant.helpers.event_decorators import HASS, track_state_change from homeassistant import const DOMAIN = 'mute_light' DEPENDENCIES = [] def setup(hass, config): return True @track_state_change(['switch.living_room_mute']) def light_with_mute(entity_id, from_state, to_state): """ Toggle red light when volume is muted """ is_muted = to_state.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)