Last active
January 24, 2016 23:14
-
-
Save rmkraus/654fe4728cad7d125c9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment