diff --git a/atom.xml b/atom.xml index 80c7083e4a..9d332d6325 100644 --- a/atom.xml +++ b/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ @@ -13,6 +13,317 @@ Octopress + + <![CDATA[Using MQTT with Home Assistant]]> + + 2015-09-11T02:19:38-07:00 + https://home-assistant.io/blog/2015/09/11/different-ways-to-use-mqtt-with-home-assistant + +The MQTT support was added to Home Assistant recently. The MQTT component will enable you to do all sort of things. Most likely you will use it to communicate with your devices. But Home Assistant doesn’t care where the data is coming from or is limited to real hardware as long as there is MQTT support. This means that it doesn’t matter if the data is coming from a human, a web service, or a device.

+ +

A great example is shown in a Laundry Automation post in this blog.

+ +

This post will give you a small overview of some other possibilities on how to use MQTT with Home Assistant.

+ + + + +

Manual usage

+ +

The simplest but not the coolest way as a human to interact with a Home Assistant sensor is launching a command manually. Let’s create a “Mood” sensor. For simplicity Home Assistant and the MQTT broker are both running on the same host. The needed configuration snipplets to add to the configuration.yaml file consists of two parts: one for the broker and one for the sensor.

+ +
1
+2
+3
+4
+5
+6
+7
+8
+
mqtt:
+  broker: 127.0.0.1
+
+sensor:
+  - platform: mqtt
+    name: "Fabian's Mood"
+    state_topic: "home-assistant/fabian/mood"
+    unit_of_measurement: " "
+
+ + +

After a restart of Home Assistant the “Mood” sensor will show up in the frontend. For more details about the configuration of MQTT itself and the sensor, please refer to the MQTT component or the MQTT sensor documentation.

+ +

Now we can set the mood. The commandline tool (mosquitto_pub) which is shipped with mosquitto is used to send an MQTT message.

+ +
1
+
mosquitto_pub  -h 127.0.0.1 -t "home-assistant/fabian/mood" -m "bad"
+
+ + + + +

+ + The Mood sensor +

+ + +

Python MQTT bindings

+ +

The last section was pretty boring, I know. Nobody wants to send MQTT messages by hand if there is a computer on the desk. If you are playing the lottery this section is for you. If not, read it anyway because the lottery is just an example :-).

+ +

This example is using the Paho MQTT Python binding because those binding should be available on the host where Home Assistant is running. If you want to use this example on another machine, please make sure that the bindings are installed (pip3 install paho-mqtt).

+ +

The first step is to add an additional MQTT sensor to the configuration.yaml file. The sensor will be called “Lottery”.

+ +
1
+2
+3
+4
+
  - platform: mqtt
+    name: "Lottery"
+    state_topic: "home-assistant/lottery/number"
+    unit_of_measurement: " "
+
+ + +

Don’t forget to restart Home Assistant to make the configuration active.

+ +

To play, we need numbers from 1 to 49 which can be marked on the ticket. Those numbers should be random and displayed in the Home Assistant frontend. The Python script below is another simple example on how to send MQTT messages from the commandline; this time in a loop. For further information and examples please check the Paho MQTT documentation.

+ +
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+
#!/usr/bin/python3
+#
+import time
+import random
+import paho.mqtt.client as mqtt
+import paho.mqtt.publish as publish
+
+broker = '127.0.0.1'
+state_topic = 'home-assistant/lottery/number'
+delay = 5
+
+# Send a single message to set the mood
+publish.single('home-assistant/fabian/mood', 'good', hostname=broker)
+
+# Send messages in a loop
+client = mqtt.Client("ha-client")
+client.connect(broker)
+client.loop_start()
+
+while True:
+    client.publish(state_topic, random.randrange(0, 50, 1))
+    time.sleep(delay)
+
+ + +

Every 5 seconds a message with a new number is sent to the broker and picked up by Home Assistant. By the way, my mood is much better now.

+ +

+ + The Lottery sensor +

+ + +

With only a few lines of Python and an MQTT broker you can create your own “smartdevice” or send information to Home Assistant which you haven’t think of. Of course this is not limited to Python. If there is an MQTT library available, the device can be used with Home Assistant now.

+ +

Arduino

+ +

To get started with real hardware that is capable to send MQTT messages, the Arduino platform is an inexpensive way to do it. In this section an Arduino UNO with an Ethernet shield and a photo resistor is used. The photo resistor is connected to analog pin 0 (A0) and has an output from 0 to 1024.

+ +

+ + The Arduino UNO with Ethernet shield and photo resistor +

+ + +

The MQTT client for the Arduino needs to be available in your Arduino IDE. Below you will find a sketch which could act as a starting point. Please modify the IP addresses, the MAC address, and the pin as needed and upload the sketch to your Arduino.

+ +
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+
/*
+  This sketch is based on the basic MQTT example by
+  http://knolleary.github.io/pubsubclient/
+*/
+
+#include <SPI.h>
+#include <Ethernet.h>
+#include <PubSubClient.h>
+
+#define DEBUG 1 // Debug output to serial console
+
+// Device settings
+IPAddress deviceIp(192, 168, 0, 43);
+byte deviceMac[] = { 0xAB, 0xCD, 0xFE, 0xFE, 0xFE, 0xFE };
+char* deviceId  = "sensor01"; // Name of the sensor
+char* stateTopic = "home-assistant/sensor01/brightness"; // MQTT topic where values are published
+int sensorPin = A0; // Pin to which the sensor is connected to
+char buf[4]; // Buffer to store the sensor value
+int updateInterval = 1000; // Interval in miliseconds
+
+// MQTT server settings
+IPAddress mqttServer(192, 168, 0, 12);
+int mqttPort = 1883;
+
+EthernetClient ethClient;
+PubSubClient client(ethClient);
+
+void reconnect() {
+  while (!client.connected()) {
+#if DEBUG
+    Serial.print("Attempting MQTT connection...");
+#endif
+    if (client.connect(deviceId)) {
+#if DEBUG
+      Serial.println("connected");
+#endif
+    } else {
+#if DEBUG
+      Serial.print("failed, rc=");
+      Serial.print(client.state());
+      Serial.println(" try again in 5 seconds");
+#endif
+      delay(5000);
+    }
+  }
+}
+
+void setup() {
+  Serial.begin(57600);
+  client.setServer(mqttServer, mqttPort);
+  Ethernet.begin(deviceMac, deviceIp);
+  delay(1500);
+}
+
+void loop() {
+  if (!client.connected()) {
+    reconnect();
+  }
+  client.loop();
+
+  int sensorValue = analogRead(sensorPin);
+#if DEBUG
+  Serial.print("Sensor value: ");
+  Serial.println(sensorValue);
+#endif
+  client.publish(stateTopic, itoa(sensorValue, buf, 10));
+  delay(updateInterval);
+}
+
+ + +

The Arduino will send the value of the sensor every second. To use the data in Home Assistant, add an additional MQTT sensor to the configuration.yaml file.

+ +
1
+2
+3
+4
+
  - platform: mqtt
+    name: "Brightness"
+    state_topic: "home-assistant/sensor01/brightness"
+    unit_of_measurement: " "
+
+ + +

After a restart of Home Assistant the values of your Arduino will be available.

+ +

+ + The Brightness sensor +

+ + +

I hope that this post could give you some ideas about the usage Home Assistant and MQTT. If you are working on a cool project that includes Home Assistant, please let us now.

+]]>
+
+ <![CDATA[0.7: Better UI and improved distribution]]> @@ -1888,77 +2199,6 @@ Home Assistant now supports --open-ui and --demo-mode notify.send_message(hass, "Hello from my component!") -]]> - - - - <![CDATA[Home Control, Automation & the Smart Home]]> - - 2014-12-26T10:23:13-08:00 - https://home-assistant.io/blog/2014/12/26/home-control-home-automation-and-the-smart-home - The internet has been buzzing over the last year about home automation. A lot of different terms fly around like the internet of things, home automation and the smart home. -This article will try to explain how they all relate.

- -

The first thing to introduce is the Internet of Things (IoT). This refers to a new generation of devices that cannot only be controlled by humans via buttons or remotes but also provide an interface to communicate with other devices and applications. For example, an IoT-capable coffee machine could receive commands to create different types of coffee and be able to broadcast the amount of water left in its resevoir.

- -

There is no widely adopted open standard for smart device communication. This prevents a lot of devices to communicate with one another. And even if they could, most devices are not designed to manage other devices. To solve this we need a device to be able to communicate with and manage all these connected devices. This device is called a hub.

- -

As a bare minimum a hub has to keep track of the state of each device and should be able to control them if possible. For example, it has to know which lights are on or off and offer a way to control the lights. For a sensor it only has to know the value. A hub with these capabilities offers home control.

- -

- - Hub dashboard example - - Example of a hub’s dashboard. Showing the state of 2 persons, 4 lights and the sun. -

- - - - - -

A step up from home control is to have the user setup triggers to send commands based on information in the home control layer. For example, to turn on the lights when a person arrives home. A hub with these capabilities is capable of home automation.

- -

Most hubs on the market today offer this in various degrees of functionality and usability. Some IoT-capable devices offer this too, but only control themselves and are usually limited to location and time-based events.

- -

The last category, and this is still very much in the future, is the smart home. A self-learning and adopting system that will decide which events should impact other devices.

- -

An example of a smart home in action is that it observes that when person A comes home, the lights in the living room and the kitchen switch on. While if person B comes home, the lights in the living room and the study room are switched on. The next time person A or B comes home, the smart home will turn on its preferred lights without any configuration being set by the user.

- -

A glimpse today at how the future can look is the Nest thermostat. A thermostat smart enough to learn your schedule and adjust its own temperature accordingly.

- -

All this results in the following overview of Home Automation.

- -

- - Home Automation landscape - - Overview of the home automation landscape. -

- - -

Challenges

- -

You are probably wondering, this all seems relatively simple, why don’t I have my very own smart home yet? There are a couple of challenges today that keep us from stepping into the future.

- -

More Internet of Things-capable devices

- -

The majority of the IoT products out there are either lights, switches or presence detection. That’s not enough for your home to be very smart about. We need televisions, fridges, ovens and more to join the party to increase the number of devices that we can control.

- -

More data

- -

Most first generation IoT devices are only exposing information that is needed for controlling it. We need to be able to track all interactions with each device for our smart home to learn how interaction with devices influence other things. For example, we need to be able to track how many cups of coffee were made or how often the fridge was open. This will increase the information flow and open up a whole bunch of new possibilities. For example, the smart home can order new coffee when you’re running low.

- -

Easy to use, open software that we can trust

- -

To increase adoption we will need people to trust their smart home system. It will be very tough to convince people to upgrade all their devices and upload all interactions with each of them to the cloud. This data could reveal their whole life including all bad habits. That’s why such a system should be simple and open-source so people can validate that their data generated at home stays home.

- -

Anoter important booster for adoption is that the software should be easy to set up and use by the average user. A lot of people are not burning their hands yet on Home Automation because they are scared of configurating it.

- -

Home Assistant is trying to be this software. It is not there yet but trying hard. Device discovery and a user interface for configuring home automation are problems we hope to tackle in 2015 while not sacrificing any modularity or usability.

- -

Happy new year!

]]>
diff --git a/blog/2014/12/18/website-launched/index.html b/blog/2014/12/18/website-launched/index.html index c463dd8e68..6f629b86d1 100644 --- a/blog/2014/12/18/website-launched/index.html +++ b/blog/2014/12/18/website-launched/index.html @@ -212,6 +212,12 @@ diff --git a/blog/2014/12/26/home-control-home-automation-and-the-smart-home/index.html b/blog/2014/12/26/home-control-home-automation-and-the-smart-home/index.html index ec0942fc62..7ab0262fb4 100644 --- a/blog/2014/12/26/home-control-home-automation-and-the-smart-home/index.html +++ b/blog/2014/12/26/home-control-home-automation-and-the-smart-home/index.html @@ -274,6 +274,12 @@ This article will try to explain how they all relate.

diff --git a/blog/2015/01/04/hey-pushbullet-nice-talking-to-you/index.html b/blog/2015/01/04/hey-pushbullet-nice-talking-to-you/index.html index 658bb93c28..7cc9bbe2c1 100644 --- a/blog/2015/01/04/hey-pushbullet-nice-talking-to-you/index.html +++ b/blog/2015/01/04/hey-pushbullet-nice-talking-to-you/index.html @@ -256,6 +256,12 @@ diff --git a/blog/2015/01/11/bootstrapping-your-setup-with-discovery/index.html b/blog/2015/01/11/bootstrapping-your-setup-with-discovery/index.html index 3bd3ed517b..89481b908a 100644 --- a/blog/2015/01/11/bootstrapping-your-setup-with-discovery/index.html +++ b/blog/2015/01/11/bootstrapping-your-setup-with-discovery/index.html @@ -224,6 +224,12 @@ diff --git a/blog/2015/01/13/nest-in-da-house/index.html b/blog/2015/01/13/nest-in-da-house/index.html index 514d96e2a4..28b28f5ae4 100644 --- a/blog/2015/01/13/nest-in-da-house/index.html +++ b/blog/2015/01/13/nest-in-da-house/index.html @@ -231,6 +231,12 @@ diff --git a/blog/2015/01/24/release-notes/index.html b/blog/2015/01/24/release-notes/index.html index 8a9ea12fc4..00b4e734e8 100644 --- a/blog/2015/01/24/release-notes/index.html +++ b/blog/2015/01/24/release-notes/index.html @@ -236,6 +236,12 @@ Home Assistant now supports --open-ui and --demo-mode diff --git a/blog/2015/02/08/looking-at-the-past/index.html b/blog/2015/02/08/looking-at-the-past/index.html index c813c73dcc..4088ed3a3c 100644 --- a/blog/2015/02/08/looking-at-the-past/index.html +++ b/blog/2015/02/08/looking-at-the-past/index.html @@ -254,6 +254,12 @@ Events are saved in a local database. Google Graphs is used to draw the graph. D diff --git a/blog/2015/02/24/streaming-updates/index.html b/blog/2015/02/24/streaming-updates/index.html index 84464025da..049acdfe45 100644 --- a/blog/2015/02/24/streaming-updates/index.html +++ b/blog/2015/02/24/streaming-updates/index.html @@ -232,6 +232,12 @@ diff --git a/blog/2015/03/01/home-assistant-migrating-to-yaml/index.html b/blog/2015/03/01/home-assistant-migrating-to-yaml/index.html index 695a11c023..798f4869ce 100644 --- a/blog/2015/03/01/home-assistant-migrating-to-yaml/index.html +++ b/blog/2015/03/01/home-assistant-migrating-to-yaml/index.html @@ -219,6 +219,12 @@ YAML allows the use of lists, which should make the configuration file a bit mor diff --git a/blog/2015/03/08/new-logo/index.html b/blog/2015/03/08/new-logo/index.html index 2895069d51..5444af1885 100644 --- a/blog/2015/03/08/new-logo/index.html +++ b/blog/2015/03/08/new-logo/index.html @@ -220,6 +220,12 @@ The old logo, the new detailed logo and the new simple logo. diff --git a/blog/2015/03/11/release-notes/index.html b/blog/2015/03/11/release-notes/index.html index a2b5ee6deb..e98a47883a 100644 --- a/blog/2015/03/11/release-notes/index.html +++ b/blog/2015/03/11/release-notes/index.html @@ -266,6 +266,12 @@ An initial version of voice control for Home Assistant has landed. The current i diff --git a/blog/2015/03/22/release-notes/index.html b/blog/2015/03/22/release-notes/index.html index 5aa65e0584..23aa6051f8 100644 --- a/blog/2015/03/22/release-notes/index.html +++ b/blog/2015/03/22/release-notes/index.html @@ -339,6 +339,12 @@ James Cole has also contributed support for the diff --git a/blog/2015/04/25/release-notes/index.html b/blog/2015/04/25/release-notes/index.html index 67018db8b6..bc90f2545f 100644 --- a/blog/2015/04/25/release-notes/index.html +++ b/blog/2015/04/25/release-notes/index.html @@ -355,6 +355,12 @@ James has also contributed support for integrating Transmission into Home Assist diff --git a/blog/2015/05/09/utc-time-zone-awareness/index.html b/blog/2015/05/09/utc-time-zone-awareness/index.html index c4888699d4..cf6eccb197 100644 --- a/blog/2015/05/09/utc-time-zone-awareness/index.html +++ b/blog/2015/05/09/utc-time-zone-awareness/index.html @@ -244,6 +244,12 @@ diff --git a/blog/2015/05/14/release-notes/index.html b/blog/2015/05/14/release-notes/index.html index f601989676..4f276c0db9 100644 --- a/blog/2015/05/14/release-notes/index.html +++ b/blog/2015/05/14/release-notes/index.html @@ -381,6 +381,12 @@ Before diving into the newly supported devices and services, I want to highlight diff --git a/blog/2015/06/10/release-notes/index.html b/blog/2015/06/10/release-notes/index.html index 5212f987dd..7378782437 100644 --- a/blog/2015/06/10/release-notes/index.html +++ b/blog/2015/06/10/release-notes/index.html @@ -460,6 +460,12 @@ This switch platform allows you to control your motion detection setting on your diff --git a/blog/2015/07/11/ip-cameras-arduino-kodi-efergy-support/index.html b/blog/2015/07/11/ip-cameras-arduino-kodi-efergy-support/index.html index b3e107ecef..3b4d7308c1 100644 --- a/blog/2015/07/11/ip-cameras-arduino-kodi-efergy-support/index.html +++ b/blog/2015/07/11/ip-cameras-arduino-kodi-efergy-support/index.html @@ -404,6 +404,12 @@ Fabian has added support for Forecast.io to g diff --git a/blog/2015/08/09/mqtt-raspberry-pi-squeezebox-asuswrt-support/index.html b/blog/2015/08/09/mqtt-raspberry-pi-squeezebox-asuswrt-support/index.html index a57d2f4ce4..7ba217733a 100644 --- a/blog/2015/08/09/mqtt-raspberry-pi-squeezebox-asuswrt-support/index.html +++ b/blog/2015/08/09/mqtt-raspberry-pi-squeezebox-asuswrt-support/index.html @@ -367,6 +367,12 @@ Support for Temper temperature sensors has been contributed by +
  • + Using MQTT with Home Assistant +
  • + + +
  • 0.7: Better UI and improved distribution
  • @@ -386,12 +392,6 @@ Support for Temper temperature sensors has been contributed by - IP Cameras, Arduinos, Kodi and Efergy Energy Monitors now supported - - - diff --git a/blog/2015/08/17/verisure-and-modern-tp-link-router-support/index.html b/blog/2015/08/17/verisure-and-modern-tp-link-router-support/index.html index 9be50fc7b8..c35d9f859a 100644 --- a/blog/2015/08/17/verisure-and-modern-tp-link-router-support/index.html +++ b/blog/2015/08/17/verisure-and-modern-tp-link-router-support/index.html @@ -245,6 +245,12 @@ Home Assistant support to integrate your Ver diff --git a/blog/2015/08/26/laundry-automation-with-moteino-mqtt-and-home-assistant/index.html b/blog/2015/08/26/laundry-automation-with-moteino-mqtt-and-home-assistant/index.html index ad97c1636f..b3c9ee9be0 100644 --- a/blog/2015/08/26/laundry-automation-with-moteino-mqtt-and-home-assistant/index.html +++ b/blog/2015/08/26/laundry-automation-with-moteino-mqtt-and-home-assistant/index.html @@ -429,6 +429,12 @@ diff --git a/blog/2015/08/31/version-7-revamped-ui-and-improved-distribution/index.html b/blog/2015/08/31/version-7-revamped-ui-and-improved-distribution/index.html index e3baa78fac..b24c2857f7 100644 --- a/blog/2015/08/31/version-7-revamped-ui-and-improved-distribution/index.html +++ b/blog/2015/08/31/version-7-revamped-ui-and-improved-distribution/index.html @@ -375,6 +375,12 @@ or AM2302 device.

    diff --git a/blog/2015/09/11/different-ways-to-use-mqtt-with-home-assistant/index.html b/blog/2015/09/11/different-ways-to-use-mqtt-with-home-assistant/index.html new file mode 100644 index 0000000000..f6d17b033d --- /dev/null +++ b/blog/2015/09/11/different-ways-to-use-mqtt-with-home-assistant/index.html @@ -0,0 +1,609 @@ + + + + + + + + + + + + Using MQTT with Home Assistant - Home Assistant + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    + +
    + + +
    +
    + +

    Using MQTT with Home Assistant

    + + + +
    + + + + + + + + + + + + + + + + + + + 10 minutes reading time + + + + + + + + + Comments + +
    + +
    + + + + +

    +The MQTT support was added to Home Assistant recently. The MQTT component will enable you to do all sort of things. Most likely you will use it to communicate with your devices. But Home Assistant doesn’t care where the data is coming from or is limited to real hardware as long as there is MQTT support. This means that it doesn’t matter if the data is coming from a human, a web service, or a device.

    + +

    A great example is shown in a Laundry Automation post in this blog.

    + +

    This post will give you a small overview of some other possibilities on how to use MQTT with Home Assistant.

    + + + + +

    Manual usage

    + +

    The simplest but not the coolest way as a human to interact with a Home Assistant sensor is launching a command manually. Let’s create a “Mood” sensor. For simplicity Home Assistant and the MQTT broker are both running on the same host. The needed configuration snipplets to add to the configuration.yaml file consists of two parts: one for the broker and one for the sensor.

    + +
    1
    +2
    +3
    +4
    +5
    +6
    +7
    +8
    +
    mqtt:
    +  broker: 127.0.0.1
    +
    +sensor:
    +  - platform: mqtt
    +    name: "Fabian's Mood"
    +    state_topic: "home-assistant/fabian/mood"
    +    unit_of_measurement: " "
    +
    + + +

    After a restart of Home Assistant the “Mood” sensor will show up in the frontend. For more details about the configuration of MQTT itself and the sensor, please refer to the MQTT component or the MQTT sensor documentation.

    + +

    Now we can set the mood. The commandline tool (mosquitto_pub) which is shipped with mosquitto is used to send an MQTT message.

    + +
    1
    +
    mosquitto_pub  -h 127.0.0.1 -t "home-assistant/fabian/mood" -m "bad"
    +
    + + + + +

    + + The Mood sensor +

    + + +

    Python MQTT bindings

    + +

    The last section was pretty boring, I know. Nobody wants to send MQTT messages by hand if there is a computer on the desk. If you are playing the lottery this section is for you. If not, read it anyway because the lottery is just an example :-).

    + +

    This example is using the Paho MQTT Python binding because those binding should be available on the host where Home Assistant is running. If you want to use this example on another machine, please make sure that the bindings are installed (pip3 install paho-mqtt).

    + +

    The first step is to add an additional MQTT sensor to the configuration.yaml file. The sensor will be called “Lottery”.

    + +
    1
    +2
    +3
    +4
    +
      - platform: mqtt
    +    name: "Lottery"
    +    state_topic: "home-assistant/lottery/number"
    +    unit_of_measurement: " "
    +
    + + +

    Don’t forget to restart Home Assistant to make the configuration active.

    + +

    To play, we need numbers from 1 to 49 which can be marked on the ticket. Those numbers should be random and displayed in the Home Assistant frontend. The Python script below is another simple example on how to send MQTT messages from the commandline; this time in a loop. For further information and examples please check the Paho MQTT documentation.

    + +
    1
    +2
    +3
    +4
    +5
    +6
    +7
    +8
    +9
    +10
    +11
    +12
    +13
    +14
    +15
    +16
    +17
    +18
    +19
    +20
    +21
    +22
    +
    #!/usr/bin/python3
    +#
    +import time
    +import random
    +import paho.mqtt.client as mqtt
    +import paho.mqtt.publish as publish
    +
    +broker = '127.0.0.1'
    +state_topic = 'home-assistant/lottery/number'
    +delay = 5
    +
    +# Send a single message to set the mood
    +publish.single('home-assistant/fabian/mood', 'good', hostname=broker)
    +
    +# Send messages in a loop
    +client = mqtt.Client("ha-client")
    +client.connect(broker)
    +client.loop_start()
    +
    +while True:
    +    client.publish(state_topic, random.randrange(0, 50, 1))
    +    time.sleep(delay)
    +
    + + +

    Every 5 seconds a message with a new number is sent to the broker and picked up by Home Assistant. By the way, my mood is much better now.

    + +

    + + The Lottery sensor +

    + + +

    With only a few lines of Python and an MQTT broker you can create your own “smartdevice” or send information to Home Assistant which you haven’t think of. Of course this is not limited to Python. If there is an MQTT library available, the device can be used with Home Assistant now.

    + +

    Arduino

    + +

    To get started with real hardware that is capable to send MQTT messages, the Arduino platform is an inexpensive way to do it. In this section an Arduino UNO with an Ethernet shield and a photo resistor is used. The photo resistor is connected to analog pin 0 (A0) and has an output from 0 to 1024.

    + +

    + + The Arduino UNO with Ethernet shield and photo resistor +

    + + +

    The MQTT client for the Arduino needs to be available in your Arduino IDE. Below you will find a sketch which could act as a starting point. Please modify the IP addresses, the MAC address, and the pin as needed and upload the sketch to your Arduino.

    + +
    1
    +2
    +3
    +4
    +5
    +6
    +7
    +8
    +9
    +10
    +11
    +12
    +13
    +14
    +15
    +16
    +17
    +18
    +19
    +20
    +21
    +22
    +23
    +24
    +25
    +26
    +27
    +28
    +29
    +30
    +31
    +32
    +33
    +34
    +35
    +36
    +37
    +38
    +39
    +40
    +41
    +42
    +43
    +44
    +45
    +46
    +47
    +48
    +49
    +50
    +51
    +52
    +53
    +54
    +55
    +56
    +57
    +58
    +59
    +60
    +61
    +62
    +63
    +64
    +65
    +66
    +67
    +68
    +
    /*
    +  This sketch is based on the basic MQTT example by
    +  http://knolleary.github.io/pubsubclient/
    +*/
    +
    +#include <SPI.h>
    +#include <Ethernet.h>
    +#include <PubSubClient.h>
    +
    +#define DEBUG 1 // Debug output to serial console
    +
    +// Device settings
    +IPAddress deviceIp(192, 168, 0, 43);
    +byte deviceMac[] = { 0xAB, 0xCD, 0xFE, 0xFE, 0xFE, 0xFE };
    +char* deviceId  = "sensor01"; // Name of the sensor
    +char* stateTopic = "home-assistant/sensor01/brightness"; // MQTT topic where values are published
    +int sensorPin = A0; // Pin to which the sensor is connected to
    +char buf[4]; // Buffer to store the sensor value
    +int updateInterval = 1000; // Interval in miliseconds
    +
    +// MQTT server settings
    +IPAddress mqttServer(192, 168, 0, 12);
    +int mqttPort = 1883;
    +
    +EthernetClient ethClient;
    +PubSubClient client(ethClient);
    +
    +void reconnect() {
    +  while (!client.connected()) {
    +#if DEBUG
    +    Serial.print("Attempting MQTT connection...");
    +#endif
    +    if (client.connect(deviceId)) {
    +#if DEBUG
    +      Serial.println("connected");
    +#endif
    +    } else {
    +#if DEBUG
    +      Serial.print("failed, rc=");
    +      Serial.print(client.state());
    +      Serial.println(" try again in 5 seconds");
    +#endif
    +      delay(5000);
    +    }
    +  }
    +}
    +
    +void setup() {
    +  Serial.begin(57600);
    +  client.setServer(mqttServer, mqttPort);
    +  Ethernet.begin(deviceMac, deviceIp);
    +  delay(1500);
    +}
    +
    +void loop() {
    +  if (!client.connected()) {
    +    reconnect();
    +  }
    +  client.loop();
    +
    +  int sensorValue = analogRead(sensorPin);
    +#if DEBUG
    +  Serial.print("Sensor value: ");
    +  Serial.println(sensorValue);
    +#endif
    +  client.publish(stateTopic, itoa(sensorValue, buf, 10));
    +  delay(updateInterval);
    +}
    +
    + + +

    The Arduino will send the value of the sensor every second. To use the data in Home Assistant, add an additional MQTT sensor to the configuration.yaml file.

    + +
    1
    +2
    +3
    +4
    +
      - platform: mqtt
    +    name: "Brightness"
    +    state_topic: "home-assistant/sensor01/brightness"
    +    unit_of_measurement: " "
    +
    + + +

    After a restart of Home Assistant the values of your Arduino will be available.

    + +

    + + The Brightness sensor +

    + + +

    I hope that this post could give you some ideas about the usage Home Assistant and MQTT. If you are working on a cool project that includes Home Assistant, please let us now.

    + + +
    + + +
    +

    Comments

    +
    +
    +
    + + +
    + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/blog/archives/index.html b/blog/archives/index.html index 390a29e2de..4f39e32a43 100644 --- a/blog/archives/index.html +++ b/blog/archives/index.html @@ -22,7 +22,7 @@ - + @@ -114,6 +114,43 @@
    +
    + +
    + +
    +
    +

    Using MQTT with Home Assistant

    + +
    + + + + + + + +
    + +
    +
    + +
    +
    + + + +
    + +
    @@ -951,6 +988,12 @@ diff --git a/blog/categories/architecture/atom.xml b/blog/categories/architecture/atom.xml index 3a2b490735..823d2877c7 100644 --- a/blog/categories/architecture/atom.xml +++ b/blog/categories/architecture/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: architecture | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/architecture/index.html b/blog/categories/architecture/index.html index 95dcab8ac5..3df53cd11d 100644 --- a/blog/categories/architecture/index.html +++ b/blog/categories/architecture/index.html @@ -206,6 +206,12 @@ diff --git a/blog/categories/branding/atom.xml b/blog/categories/branding/atom.xml index 9d587f10d0..e92f72e123 100644 --- a/blog/categories/branding/atom.xml +++ b/blog/categories/branding/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: branding | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/branding/index.html b/blog/categories/branding/index.html index 6613750abd..0e928f5603 100644 --- a/blog/categories/branding/index.html +++ b/blog/categories/branding/index.html @@ -206,6 +206,12 @@ diff --git a/blog/categories/component/atom.xml b/blog/categories/component/atom.xml index 4fc8cf24a0..29cc1b590e 100644 --- a/blog/categories/component/atom.xml +++ b/blog/categories/component/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: component | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/component/index.html b/blog/categories/component/index.html index ef8687a1e7..f4bec72c58 100644 --- a/blog/categories/component/index.html +++ b/blog/categories/component/index.html @@ -319,6 +319,12 @@ diff --git a/blog/categories/core/atom.xml b/blog/categories/core/atom.xml index 4ac6d9c348..fc51db0080 100644 --- a/blog/categories/core/atom.xml +++ b/blog/categories/core/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: core | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/core/index.html b/blog/categories/core/index.html index ab48f9a05d..b005ee6614 100644 --- a/blog/categories/core/index.html +++ b/blog/categories/core/index.html @@ -243,6 +243,12 @@ diff --git a/blog/categories/frontend/atom.xml b/blog/categories/frontend/atom.xml index 67d448d45f..8962717e5f 100644 --- a/blog/categories/frontend/atom.xml +++ b/blog/categories/frontend/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: frontend | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/frontend/index.html b/blog/categories/frontend/index.html index a0aae00690..af9d5d6237 100644 --- a/blog/categories/frontend/index.html +++ b/blog/categories/frontend/index.html @@ -245,6 +245,12 @@ diff --git a/blog/categories/how-to/atom.xml b/blog/categories/how-to/atom.xml new file mode 100644 index 0000000000..26d0bbbc98 --- /dev/null +++ b/blog/categories/how-to/atom.xml @@ -0,0 +1,212 @@ + + + + <![CDATA[Category: how-to | Home Assistant]]> + + + 2015-09-11T09:24:25-07:00 + https://home-assistant.io/ + + + + + Octopress + + + + <![CDATA[Using MQTT with Home Assistant]]> + + 2015-09-11T02:19:38-07:00 + https://home-assistant.io/blog/2015/09/11/different-ways-to-use-mqtt-with-home-assistant + +The MQTT support was added to Home Assistant recently. The MQTT component will enable you to do all sort of things. Most likely you will use it to communicate with your devices. But Home Assistant doesn’t care where the data is coming from or is limited to real hardware as long as there is MQTT support. This means that it doesn’t matter if the data is coming from a human, a web service, or a device.

    + +

    A great example is shown in a Laundry Automation post in this blog.

    + +

    This post will give you a small overview of some other possibilities on how to use MQTT with Home Assistant.

    + + + + +

    Manual usage

    + +

    The simplest but not the coolest way as a human to interact with a Home Assistant sensor is launching a command manually. Let’s create a “Mood” sensor. For simplicity Home Assistant and the MQTT broker are both running on the same host. The needed configuration snipplets to add to the configuration.yaml file consists of two parts: one for the broker and one for the sensor.

    + +
    mqtt:
    +  broker: 127.0.0.1
    +
    +sensor:
    +  - platform: mqtt
    +    name: "Fabian's Mood"
    +    state_topic: "home-assistant/fabian/mood"
    +    unit_of_measurement: " "
    +
    + +

    After a restart of Home Assistant the “Mood” sensor will show up in the frontend. For more details about the configuration of MQTT itself and the sensor, please refer to the MQTT component or the MQTT sensor documentation.

    + +

    Now we can set the mood. The commandline tool (mosquitto_pub) which is shipped with mosquitto is used to send an MQTT message.

    + +
    mosquitto_pub  -h 127.0.0.1 -t "home-assistant/fabian/mood" -m "bad"
    +
    + +

    + + The Mood sensor +

    + + +

    Python MQTT bindings

    + +

    The last section was pretty boring, I know. Nobody wants to send MQTT messages by hand if there is a computer on the desk. If you are playing the lottery this section is for you. If not, read it anyway because the lottery is just an example :-).

    + +

    This example is using the Paho MQTT Python binding because those binding should be available on the host where Home Assistant is running. If you want to use this example on another machine, please make sure that the bindings are installed (pip3 install paho-mqtt).

    + +

    The first step is to add an additional MQTT sensor to the configuration.yaml file. The sensor will be called “Lottery”.

    + +
      - platform: mqtt
    +    name: "Lottery"
    +    state_topic: "home-assistant/lottery/number"
    +    unit_of_measurement: " "
    +
    + +

    Don’t forget to restart Home Assistant to make the configuration active.

    + +

    To play, we need numbers from 1 to 49 which can be marked on the ticket. Those numbers should be random and displayed in the Home Assistant frontend. The Python script below is another simple example on how to send MQTT messages from the commandline; this time in a loop. For further information and examples please check the Paho MQTT documentation.

    + +
    #!/usr/bin/python3
    +#
    +import time
    +import random
    +import paho.mqtt.client as mqtt
    +import paho.mqtt.publish as publish
    +
    +broker = '127.0.0.1'
    +state_topic = 'home-assistant/lottery/number'
    +delay = 5
    +
    +# Send a single message to set the mood
    +publish.single('home-assistant/fabian/mood', 'good', hostname=broker)
    +
    +# Send messages in a loop
    +client = mqtt.Client("ha-client")
    +client.connect(broker)
    +client.loop_start()
    +
    +while True:
    +    client.publish(state_topic, random.randrange(0, 50, 1))
    +    time.sleep(delay)
    +
    + +

    Every 5 seconds a message with a new number is sent to the broker and picked up by Home Assistant. By the way, my mood is much better now.

    + +

    + + The Lottery sensor +

    + + +

    With only a few lines of Python and an MQTT broker you can create your own “smartdevice” or send information to Home Assistant which you haven’t think of. Of course this is not limited to Python. If there is an MQTT library available, the device can be used with Home Assistant now.

    + +

    Arduino

    + +

    To get started with real hardware that is capable to send MQTT messages, the Arduino platform is an inexpensive way to do it. In this section an Arduino UNO with an Ethernet shield and a photo resistor is used. The photo resistor is connected to analog pin 0 (A0) and has an output from 0 to 1024.

    + +

    + + The Arduino UNO with Ethernet shield and photo resistor +

    + + +

    The MQTT client for the Arduino needs to be available in your Arduino IDE. Below you will find a sketch which could act as a starting point. Please modify the IP addresses, the MAC address, and the pin as needed and upload the sketch to your Arduino.

    + +
    /*
    +  This sketch is based on the basic MQTT example by
    +  http://knolleary.github.io/pubsubclient/
    +*/
    +
    +#include <SPI.h>
    +#include <Ethernet.h>
    +#include <PubSubClient.h>
    +
    +#define DEBUG 1 // Debug output to serial console
    +
    +// Device settings
    +IPAddress deviceIp(192, 168, 0, 43);
    +byte deviceMac[] = { 0xAB, 0xCD, 0xFE, 0xFE, 0xFE, 0xFE };
    +char* deviceId  = "sensor01"; // Name of the sensor
    +char* stateTopic = "home-assistant/sensor01/brightness"; // MQTT topic where values are published
    +int sensorPin = A0; // Pin to which the sensor is connected to
    +char buf[4]; // Buffer to store the sensor value
    +int updateInterval = 1000; // Interval in miliseconds
    +
    +// MQTT server settings
    +IPAddress mqttServer(192, 168, 0, 12);
    +int mqttPort = 1883;
    +
    +EthernetClient ethClient;
    +PubSubClient client(ethClient);
    +
    +void reconnect() {
    +  while (!client.connected()) {
    +#if DEBUG
    +    Serial.print("Attempting MQTT connection...");
    +#endif
    +    if (client.connect(deviceId)) {
    +#if DEBUG
    +      Serial.println("connected");
    +#endif
    +    } else {
    +#if DEBUG
    +      Serial.print("failed, rc=");
    +      Serial.print(client.state());
    +      Serial.println(" try again in 5 seconds");
    +#endif
    +      delay(5000);
    +    }
    +  }
    +}
    +
    +void setup() {
    +  Serial.begin(57600);
    +  client.setServer(mqttServer, mqttPort);
    +  Ethernet.begin(deviceMac, deviceIp);
    +  delay(1500);
    +}
    +
    +void loop() {
    +  if (!client.connected()) {
    +    reconnect();
    +  }
    +  client.loop();
    +
    +  int sensorValue = analogRead(sensorPin);
    +#if DEBUG
    +  Serial.print("Sensor value: ");
    +  Serial.println(sensorValue);
    +#endif
    +  client.publish(stateTopic, itoa(sensorValue, buf, 10));
    +  delay(updateInterval);
    +}
    +
    + +

    The Arduino will send the value of the sensor every second. To use the data in Home Assistant, add an additional MQTT sensor to the configuration.yaml file.

    + +
      - platform: mqtt
    +    name: "Brightness"
    +    state_topic: "home-assistant/sensor01/brightness"
    +    unit_of_measurement: " "
    +
    + +

    After a restart of Home Assistant the values of your Arduino will be available.

    + +

    + + The Brightness sensor +

    + + +

    I hope that this post could give you some ideas about the usage Home Assistant and MQTT. If you are working on a cool project that includes Home Assistant, please let us now.

    +]]>
    +
    + +
    diff --git a/blog/categories/how-to/index.html b/blog/categories/how-to/index.html new file mode 100644 index 0000000000..86d96c9345 --- /dev/null +++ b/blog/categories/how-to/index.html @@ -0,0 +1,302 @@ + + + + + + + + + + + + Category: how-to - Home Assistant + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    + +
    + + + + + +
    + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/blog/categories/release-notes/atom.xml b/blog/categories/release-notes/atom.xml index 5a6978ad5f..3f259bda64 100644 --- a/blog/categories/release-notes/atom.xml +++ b/blog/categories/release-notes/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: release-notes | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/release-notes/index.html b/blog/categories/release-notes/index.html index 6c525c8d25..61a44e4c89 100644 --- a/blog/categories/release-notes/index.html +++ b/blog/categories/release-notes/index.html @@ -502,6 +502,12 @@ diff --git a/blog/categories/user-stories/atom.xml b/blog/categories/user-stories/atom.xml index 1afedbe207..fdc1147e03 100644 --- a/blog/categories/user-stories/atom.xml +++ b/blog/categories/user-stories/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: user-stories | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/user-stories/index.html b/blog/categories/user-stories/index.html index ee0c6fe77f..203746e895 100644 --- a/blog/categories/user-stories/index.html +++ b/blog/categories/user-stories/index.html @@ -243,6 +243,12 @@ diff --git a/blog/categories/website/atom.xml b/blog/categories/website/atom.xml index 25b28e3b2d..cecb178d97 100644 --- a/blog/categories/website/atom.xml +++ b/blog/categories/website/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: website | Home Assistant]]> - 2015-09-10T12:38:32-07:00 + 2015-09-11T09:24:25-07:00 https://home-assistant.io/ diff --git a/blog/categories/website/index.html b/blog/categories/website/index.html index bad5a7733a..2990f199bf 100644 --- a/blog/categories/website/index.html +++ b/blog/categories/website/index.html @@ -206,6 +206,12 @@ diff --git a/blog/index.html b/blog/index.html index c655337225..7fcf1b11a4 100644 --- a/blog/index.html +++ b/blog/index.html @@ -22,7 +22,7 @@ - + @@ -96,6 +96,76 @@ +
    +
    + +

    + Using MQTT with Home Assistant +

    + + + +
    + + + + + + + + + + + + + + + + + + + 10 minutes reading time + + + + + + + + + Comments + +
    + +
    + + + + +
    +

    +The MQTT support was added to Home Assistant recently. The MQTT component will enable you to do all sort of things. Most likely you will use it to communicate with your devices. But Home Assistant doesn’t care where the data is coming from or is limited to real hardware as long as there is MQTT support. This means that it doesn’t matter if the data is coming from a human, a web service, or a device.

    + +

    A great example is shown in a Laundry Automation post in this blog.

    + +

    This post will give you a small overview of some other possibilities on how to use MQTT with Home Assistant.

    + + + Read on → +
    + +
    +
    + +
    @@ -913,113 +983,6 @@ I (Paulus) have added a logbook component. The logbook component provides a diff

    - -
    -
    - -

    - Release notes for March 22, 2015 -

    - - - -
    - - - - - - - - - - - - - - - - - - - three minutes reading time - - - - - - - - - Comments - -
    - -
    - - - - -
    -

    A new version of Home Assistant has just been pushed out. It contains bugfixes contributed by jamespcole, andythigpen, trainman419 and me. It also adds a bunch of great new features:

    - -

    Script
    -Andythigpen has contributed a script component. This allows users to create a sequence of service calls and delays. Scripts can be started using the service script/turn_on and interrupted using the service script/turn_off. A separate page has been added to the frontend to see the status of your scripts.

    - -
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    -9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -
    # Example configuration.yaml entry
    -script:
    -  # Turns on the bedroom lights and then the living room lights 1 minute later
    -  wakeup:
    -    alias: Wake Up
    -    sequence:
    -      - alias: Bedroom lights on
    -        execute_service: light.turn_on
    -        service_data:
    -          entity_id: group.bedroom
    -      - delay:
    -          # supports seconds, milliseconds, minutes, hours, etc.
    -          minutes: 1
    -      - alias: Living room lights on
    -        execute_service: light.turn_on
    -        service_data:
    -          entity_id: group.living_room
    -
    - - - - - - Read on → -
    - -
    -
    -