diff --git a/README.md b/README.md index 96bdcd1f23010fad40b84c47cec736190270fd52..33cd4d862ea2f586879fa08108bb1a475be0f7e0 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The system is built modular so support for other devices or actions can be imple ## Installation instructions / Quick-start guide -Running Home Assistant requires that python3 is installed. +Running Home Assistant requires that python3 and the packages pyephem and requests are installed. Run the following code to get up and running with the minimum setup: @@ -40,7 +40,7 @@ pip3 install -r requirements.txt python3 start.py ``` -This will start the Home Assistant server and its web interface on [http://127.0.0.1:8123](http://127.0.0.1:8123). The default password is 'password'. +This will start the Home Assistant server and create an initial configuration file in `config/home-assistant.conf` that is setup for demo mode. It will launch its web interface on [http://127.0.0.1:8123](http://127.0.0.1:8123). The default password is 'password'. If you're using Docker, you can use @@ -48,7 +48,7 @@ If you're using Docker, you can use docker run -d --name="home-assistant" -v /path/to/homeassistant/config:/config -v /etc/localtime:/etc/localtime:ro -p 8123:8123 balloob/home-assistant ``` -After you got the bare minimum running it is time to enable some components and get started. An example configuration file has been provided in [/config/home-assistant.conf.example](https://github.com/balloob/home-assistant/blob/master/config/home-assistant.conf.example). +After you got the demo mode running it is time to enable some real components and get started. An example configuration file has been provided in [/config/home-assistant.conf.example](https://github.com/balloob/home-assistant/blob/master/config/home-assistant.conf.example). ### Philips Hue To get Philips Hue working you will have to connect Home Assistant to the Hue bridge. diff --git a/homeassistant/components/demo.py b/homeassistant/components/demo.py new file mode 100644 index 0000000000000000000000000000000000000000..9d212e88d058091d1a58b13d8d4f3fadb6374a1b --- /dev/null +++ b/homeassistant/components/demo.py @@ -0,0 +1,110 @@ +""" +homeassistant.components.demo +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sets up a demo environment that mimics interaction with devices +""" +import random + +import homeassistant as ha +import homeassistant.components.group as group +from homeassistant.components import (SERVICE_TURN_ON, SERVICE_TURN_OFF, + STATE_ON, STATE_OFF, get_component, + extract_entity_ids) +from homeassistant.components.light import (ATTR_XY_COLOR, ATTR_BRIGHTNESS, + GROUP_NAME_ALL_LIGHTS) +from homeassistant.util import split_entity_id + +DOMAIN = "demo" + +DEPENDENCIES = [] + + +def setup(hass, config): + """ Setup a demo environment. """ + + if config[DOMAIN].get('hide_demo_state') != '1': + hass.states.set('a.Demo_Mode', 'Enabled') + + light_colors = [ + [0.861, 0.3259], + [0.6389, 0.3028], + [0.1684, 0.0416] + ] + + def mock_turn_on(service): + """ Will fake the component has been turned on. """ + for entity_id in extract_entity_ids(hass, service): + domain, _ = split_entity_id(entity_id) + + if domain == "light": + data = {ATTR_BRIGHTNESS: 200, + ATTR_XY_COLOR: random.choice(light_colors)} + else: + data = None + + hass.states.set(entity_id, STATE_ON, data) + + def mock_turn_off(service): + """ Will fake the component has been turned off. """ + for entity_id in extract_entity_ids(hass, service): + hass.states.set(entity_id, STATE_OFF) + + # Setup sun + if ha.CONF_LATITUDE not in config[ha.DOMAIN]: + config[ha.DOMAIN][ha.CONF_LATITUDE] = '32.87336' + + if ha.CONF_LONGITUDE not in config[ha.DOMAIN]: + config[ha.DOMAIN][ha.CONF_LONGITUDE] = '-117.22743' + + get_component('sun').setup(hass, config) + + # Setup fake lights + lights = ['light.Bowl', 'light.Ceiling', 'light.TV_Back_light', + 'light.Bed_light'] + + hass.services.register('light', SERVICE_TURN_ON, mock_turn_on) + hass.services.register('light', SERVICE_TURN_OFF, mock_turn_off) + + mock_turn_on(ha.ServiceCall('light', SERVICE_TURN_ON, + {'entity_id': lights[0:2]})) + mock_turn_off(ha.ServiceCall('light', SERVICE_TURN_OFF, + {'entity_id': lights[2:]})) + + group.setup_group(hass, GROUP_NAME_ALL_LIGHTS, lights, False) + + # Setup Wemo + wemos = ['wemo.AC', 'wemo.Christmas_Lights'] + + hass.services.register('wemo', SERVICE_TURN_ON, mock_turn_on) + hass.services.register('wemo', SERVICE_TURN_OFF, mock_turn_off) + + mock_turn_on(ha.ServiceCall('wemo', SERVICE_TURN_ON, + {'entity_id': wemos[0:1]})) + mock_turn_off(ha.ServiceCall('wemo', SERVICE_TURN_OFF, + {'entity_id': wemos[1:]})) + + # Setup room groups + group.setup_group(hass, 'living_room', lights[0:3] + wemos[0:1]) + group.setup_group(hass, 'bedroom', [lights[3]] + wemos[1:]) + + # Setup process + hass.states.set("process.XBMC", STATE_ON) + + # Setup device tracker + hass.states.set("device_tracker.Paulus", "home") + hass.states.set("device_tracker.Anne_Therese", "not_home") + hass.states.set("group.all_devices", "home", + { + "auto": True, + "entity_id": [ + "device_tracker.Paulus", + "device_tracker.Anne_Therese" + ] + }) + + # Setup chromecast + hass.states.set("chromecast.Living_Rm", "Netflix", + {'friendly_name': 'Living Room'}) + + return True diff --git a/start.py b/start.py index 246e83ab38917beb818255001c7471b93bf71e59..9ac8cce457dfb5991adad83bb5ba9f9c4449eede 100644 --- a/start.py +++ b/start.py @@ -16,7 +16,8 @@ else: if not os.path.isfile(config_path): with open(config_path, 'w') as conf: conf.write("[http]\n") - conf.write("api_password=password\n") + conf.write("api_password=password\n\n") + conf.write("[demo]\n") hass = homeassistant.bootstrap.from_config_file(config_path) hass.start()