diff --git a/plugins/linkable_title.rb b/plugins/linkable_title.rb index da677b296be..784ca99bcd1 100644 --- a/plugins/linkable_title.rb +++ b/plugins/linkable_title.rb @@ -6,9 +6,9 @@ module Jekyll end def render(context) - slug = @title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') - - " #{@title}" + title = Liquid::Template.parse(@markup).render context + slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') + " #{title}" end end end diff --git a/source/_cookbook/automation_for_rainy_days.markdown b/source/_cookbook/automation_for_rainy_days.markdown index 63d78ce3d4c..52baa7a70b4 100644 --- a/source/_cookbook/automation_for_rainy_days.markdown +++ b/source/_cookbook/automation_for_rainy_days.markdown @@ -3,10 +3,11 @@ layout: page title: "Automation for rainy days" description: "Basic example how to use weather conditions to set states" date: 2015-10-08 19:05 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- ### {% linkable_title Rainy Day Light %} diff --git a/source/_cookbook/automation_sun.markdown b/source/_cookbook/automation_sun.markdown index 54b986a9dec..3e9e058b22d 100644 --- a/source/_cookbook/automation_sun.markdown +++ b/source/_cookbook/automation_sun.markdown @@ -3,10 +3,11 @@ layout: page title: "Automation examples using the sun" description: "Automation examples that use the sun." date: 2015-10-08 19:05 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- #### {% linkable_title Turn on the living room lights 45 minutes before sunset if anyone home %} diff --git a/source/_cookbook/basic_example_use_trigger_values.markdown b/source/_cookbook/basic_example_use_trigger_values.markdown index cbff5a43b62..149177b85c3 100644 --- a/source/_cookbook/basic_example_use_trigger_values.markdown +++ b/source/_cookbook/basic_example_use_trigger_values.markdown @@ -3,10 +3,11 @@ layout: page title: "Automation: use_trigger_values" description: "Basic example how to use use_trigger_values in automation" date: 2015-10-08 19:05 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- ### {% linkable_title Basic example for use_trigger_values %} diff --git a/source/_cookbook/configuration_yaml_by_carlo_costanzo.markdown b/source/_cookbook/configuration_yaml_by_carlo_costanzo.markdown new file mode 100644 index 00000000000..e20885eb7f3 --- /dev/null +++ b/source/_cookbook/configuration_yaml_by_carlo_costanzo.markdown @@ -0,0 +1,13 @@ +--- +layout: page +title: "Configuration.yaml by Carlo Costanzo" +description: "" +date: 2016-02-07 11:45 +sidebar: true +comments: false +sharing: true +footer: true +ha_category: Full configuration.yaml Examples +ha_external_link: https://gist.github.com/CCOSTAN/9934de973a293b809868 +--- + diff --git a/source/_cookbook/configuration_yaml_by_happyleavesaoc.markdown b/source/_cookbook/configuration_yaml_by_happyleavesaoc.markdown new file mode 100644 index 00000000000..774b2c093c9 --- /dev/null +++ b/source/_cookbook/configuration_yaml_by_happyleavesaoc.markdown @@ -0,0 +1,13 @@ +--- +layout: page +title: "Configuration.yaml by happyleavesaoc" +description: "" +date: 2016-02-07 11:45 +sidebar: true +comments: false +sharing: true +footer: true +ha_category: Full configuration.yaml Examples +ha_external_link: https://github.com/happyleavesaoc/my-home-automation/tree/master/homeassistant +--- + diff --git a/source/_cookbook/dim_lights_when_playing_media.markdown b/source/_cookbook/dim_lights_when_playing_media.markdown index 488d5752b96..92bea514ca4 100644 --- a/source/_cookbook/dim_lights_when_playing_media.markdown +++ b/source/_cookbook/dim_lights_when_playing_media.markdown @@ -3,10 +3,11 @@ layout: page title: "Dim lights when playing media" description: "Dim lights up or down when playing media" date: 2015-10-15 19:05 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- Like it how the lights dim up/down at the movies? Do it at home as well! diff --git a/source/_cookbook/python_component_basic_service.markdown b/source/_cookbook/python_component_basic_service.markdown new file mode 100644 index 00000000000..56e95cbcf02 --- /dev/null +++ b/source/_cookbook/python_component_basic_service.markdown @@ -0,0 +1,56 @@ +--- +layout: page +title: "Basic Service Example" +description: "" +date: 2016-02-07 12:13 +sidebar: true +comments: false +sharing: true +footer: true +ha_category: Custom Python Component Examples +--- + +This is a simple hello world example to show the basics of registering a service. To use this example, create the file `/custom_components/hello_service.py` and copy the below example code. + +Services can be called from automation and from the service developer tools in the frontend. + +```python +# The domain of your component. Should be equal to the name of your component +DOMAIN = "hello_service" + +ATTR_NAME = 'name' +DEFAULT_NAME = 'World' + + +def setup(hass, config): + """ Setup is called when Home Assistant is loading our component. """ + + def handle_hello(call): + name = call.data.get(ATTR_NAME, DEFAULT_NAME) + + hass.states.set('hello.service.hello', name) + + hass.services.register(DOMAIN, 'hello', handle_hello) + + # return boolean to indicate that initialization was successful + return True +``` + +Load the component by adding the following to your `configuration.yaml`. When your component is loaded, a new service should be available to call. + +```yaml +# configuration.yaml entry +hello_service: +``` + +Open the frontend and in the sidebar, click the first icon in the developer tool section. This will open the Call Service developer tool. On the right, find your service and click on it. This will automatically fill in the correct values. + +Pressing "Call Service" will now call your service without any parameters. This will cause your service to create a state with the default name 'World'. If you want to specify the name, you have to specify parameters. Add the following JSON as Service Data and press "Call Service again". + +```json +{ + "name": "Planet" +} +``` + +The service will now overwrite the previous state with "Planet". diff --git a/source/_cookbook/python_component_basic_state.markdown b/source/_cookbook/python_component_basic_state.markdown new file mode 100644 index 00000000000..1b5171ec127 --- /dev/null +++ b/source/_cookbook/python_component_basic_state.markdown @@ -0,0 +1,43 @@ +--- +layout: page +title: "Basic State Setting Example" +description: "" +date: 2016-02-07 12:13 +sidebar: true +comments: false +sharing: true +footer: true +ha_category: Custom Python Component Examples +--- + +This is a simple hello world example to show the basics for setting a state. To use this example, create the file `/custom_components/hello_state.py` and copy the below example code. + +```python +# The domain of your component. Should be equal to the name of your component +DOMAIN = "hello_state" + +CONF_NAME = 'name' +DEFAULT_NAME = 'World' + + +def setup(hass, config): + """ Setup is called when Home Assistant is loading our component. """ + + # Get the name from the configuration. Use DEFAULT_NAME if no name provided. + name = config[DOMAIN].get(CONF_NAME, DEFAULT_NAME) + + # States are in the format DOMAIN.OBJECT_ID + hass.states.set('hello_state.hello', name) + + # return boolean to indicate that initialization was successful + return True +``` + +Load the component by adding the following to your `configuration.yaml`: + +```yaml +# configuration.yaml entry +hello_state: + # optional + name: Paulus +``` diff --git a/source/_cookbook/python_component_mqtt_basic.markdown b/source/_cookbook/python_component_mqtt_basic.markdown new file mode 100644 index 00000000000..801ba13e4d8 --- /dev/null +++ b/source/_cookbook/python_component_mqtt_basic.markdown @@ -0,0 +1,78 @@ +--- +layout: page +title: "Basic MQTT Example" +description: "" +date: 2016-02-07 12:13 +sidebar: true +comments: false +sharing: true +footer: true +ha_category: Custom Python Component Examples +--- + +

+This example requires you to have the [MQTT component](/components/mqtt/) up and running. +

+ +This is a simple hello world example to show the basics of using MQTT in a custom component. To use this example, create the file `/custom_components/hello_mqtt.py` and copy the below example code. + +This example follows a topic on MQTT and updates the state of an entity to the last message received on that topic. It will also register a service 'set_state' that will publish a message to the MQTT topic that we're listening to. + +```python +import homeassistant.loader as loader + +# The domain of your component. Should be equal to the name of your component +DOMAIN = "hello_mqtt" + +# List of component names (string) your component depends upon +DEPENDENCIES = ['mqtt'] + + +CONF_TOPIC = 'topic' +DEFAULT_TOPIC = 'home-assistant/hello_mqtt' + + +def setup(hass, config): + """ Setup our hello_mqtt component. """ + mqtt = loader.get_component('mqtt') + topic = config[DOMAIN].get('topic', DEFAULT_TOPIC) + entity_id = 'hello_mqtt.last_message' + + # Listener to be called when we receive a message + def message_received(topic, payload, qos): + """ A new MQTT message has been received. """ + hass.states.set(entity_id, payload) + + # Subscribe our listener to a topic + mqtt.subscribe(hass, topic, message_received) + + # Set the intial state + hass.states.set(entity_id, 'No messages') + + # Service to publish a message on MQTT + def set_state_service(call): + """ Service to send a message. """ + mqtt.publish(hass, topic, call.data.get('new_state')) + + # Register our service with Home Assistant + hass.services.register(DOMAIN, 'set_state', set_state_service) + + # return boolean to indicate that initialization was successful + return True +``` + +Load the component by adding the following to your `configuration.yaml`. When your component is loaded, a new entity should popup and there should be a new service available to call. + +```yaml +# configuration.yaml entry +hello_mqtt: + topic: some_mqtt/topic/here +``` + +You can call the service with example payload: + +```json +{ + "new_state": "some new state" +} +``` diff --git a/source/_cookbook/restart_ha_if_wemo_switch_is_not_detected.markdown b/source/_cookbook/restart_ha_if_wemo_switch_is_not_detected.markdown index 41a6b1b1643..5c7accebee2 100644 --- a/source/_cookbook/restart_ha_if_wemo_switch_is_not_detected.markdown +++ b/source/_cookbook/restart_ha_if_wemo_switch_is_not_detected.markdown @@ -3,10 +3,11 @@ layout: page title: "Restart Home Assistant if Wemo Switch is not detected" description: "Restart Home Assistant if Wemo Switch is not detected." date: 2016-01-29 08:00 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- ### {% linkable_title Restart Home Assistant %} diff --git a/source/_cookbook/send_a_reminder.markdown b/source/_cookbook/send_a_reminder.markdown index bb0296f04aa..6207af196ab 100644 --- a/source/_cookbook/send_a_reminder.markdown +++ b/source/_cookbook/send_a_reminder.markdown @@ -3,10 +3,11 @@ layout: page title: "Send a reminder" description: "Send a reminder" date: 2015-12-16 08:00 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- #### {% linkable_title Send a reminder %} diff --git a/source/_cookbook/track_battery_level.markdown b/source/_cookbook/track_battery_level.markdown index e60d54c5980..1ea9b0d65ca 100644 --- a/source/_cookbook/track_battery_level.markdown +++ b/source/_cookbook/track_battery_level.markdown @@ -3,10 +3,11 @@ layout: page title: "Track your battery level" description: "Basic example how to track the battery level of your mobile devices." date: 2016-01-29 09:00 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- ### {% linkable_title Battery level %} diff --git a/source/_cookbook/turn_on_light_for_10_minutes_when_motion_detected.markdown b/source/_cookbook/turn_on_light_for_10_minutes_when_motion_detected.markdown index ff04a27bfa9..4cb2e40c971 100644 --- a/source/_cookbook/turn_on_light_for_10_minutes_when_motion_detected.markdown +++ b/source/_cookbook/turn_on_light_for_10_minutes_when_motion_detected.markdown @@ -3,10 +3,11 @@ layout: page title: "Motion detected light" description: "Turn on lights for 10 minutes when motion detected." date: 2015-10-08 19:05 -sidebar: false +sidebar: true comments: false sharing: true footer: true +ha_category: Automation Examples --- #### {% linkable_title Turn on lights with a resettable off timer %} diff --git a/source/_includes/asides/cookbook_navigation.html b/source/_includes/asides/cookbook_navigation.html new file mode 100644 index 00000000000..def8baf9f1f --- /dev/null +++ b/source/_includes/asides/cookbook_navigation.html @@ -0,0 +1,25 @@ +
+ {% include edit_github.html %} + {% assign cookbook = site.cookbook | sort: 'title' %} + + + +
+

{{page.ha_category}}

+
    + {% for recipe in cookbook %} + {% if recipe.ha_category == page.ha_category %} +
  • + {% if recipe.url == page.url %} + {{recipe.title}} + {% else %} + {{recipe.title}} + {% endif %} +
  • + {% endif %} + {% endfor %} +
+
+
diff --git a/source/_includes/site/sidebar.html b/source/_includes/site/sidebar.html index 862c78ffe8a..e7b0e2dbaaa 100644 --- a/source/_includes/site/sidebar.html +++ b/source/_includes/site/sidebar.html @@ -2,6 +2,8 @@ {% assign url_parts = page.url | split: '/' %} {% if url_parts[1] == 'components' %} {% include asides/component_navigation.html | compact_newlines %} + {% elsif url_parts[1] == 'cookbook' %} + {% include asides/cookbook_navigation.html | compact_newlines %} {% else %} {% include asides/about.html %} diff --git a/source/cookbook/index.markdown b/source/cookbook/index.markdown index 458f8cac657..2170e6127c1 100644 --- a/source/cookbook/index.markdown +++ b/source/cookbook/index.markdown @@ -1,24 +1,39 @@ --- layout: page -title: "Configuration Cookbook" -description: "Community maintained list of configuration exmaples." +title: "Cookbook" +description: "Community maintained list of different ways to use Home Assistant." date: 2015-10-08 19:05 sidebar: false comments: false sharing: true footer: true regenerate: true +hide_github_edit: true --- -This is a community currated list of `configuration.yaml` examples. New recipes can be added via the [home-assistant.io repository](https://github.com/balloob/home-assistant.io/tree/master/source/_cookbook). +This is a community currated list of different ways to use Home Assistant. New recipes can be added via the [home-assistant.io repository](https://github.com/balloob/home-assistant.io/tree/master/source/_cookbook). -{% for recipe in site.cookbook %} - * [{{recipe.title}}]({{recipe.url}}) -{% endfor %} +{% assign cookbook = site.cookbook | sort: 'title' %} +{% assign categories = cookbook | sort: 'ha_category' | map: 'ha_category' | uniq %} -### {% linkable_title Configuration.yaml Gists %} +{% for category in categories %} +### {% linkable_title {{ category }} %} + {% if category == 'Automation Examples' %} + + {% elsif category == 'Full configuration.yaml examples' %} Some users keep a public scrubbed copy of their `configuration.yaml` to learn from. + {% elsif category == '' %} -- [Configuration.yaml by Carlo Costanzo](https://gist.github.com/CCOSTAN/9934de973a293b809868) -- [Configuration.yaml by happyleavesaoc](https://github.com/happyleavesaoc/my-home-automation/tree/master/homeassistant) + {% endif %} + + {% for recipe in site.cookbook %} + {% if recipe.ha_category == category %} + {% if recipe.ha_external_link %} + * [{{recipe.title}}]({{recipe.ha_external_link}}) + {% else %} + * [{{recipe.title}}]({{recipe.url}}) + {% endif %} + {% endif %} + {% endfor %} +{% endfor %}