Add categories to cookbook

This commit is contained in:
Paulus Schoutsen 2016-02-07 14:21:44 -08:00
parent f5a7217b3f
commit a06217bbee
17 changed files with 273 additions and 20 deletions

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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
---

View file

@ -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
---

View file

@ -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!

View file

@ -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 `<config dir>/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".

View file

@ -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 `<config dir>/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
```

View file

@ -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
---
<p class='note'>
This example requires you to have the [MQTT component](/components/mqtt/) up and running.
</p>
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 `<config dir>/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"
}
```

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}