From 1fb5b5b9eac242345aed2bc6a173062f15735317 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Wed, 31 Aug 2016 05:05:07 +0000 Subject: [PATCH] Site updated at 2016-08-31 05:05:07 UTC --- atom.xml | 123 +++++-- blog/2014/12/18/website-launched/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- blog/2015/01/13/nest-in-da-house/index.html | 12 +- blog/2015/01/24/release-notes/index.html | 12 +- .../2015/02/08/looking-at-the-past/index.html | 12 +- blog/2015/02/24/streaming-updates/index.html | 12 +- .../index.html | 12 +- blog/2015/03/08/new-logo/index.html | 12 +- blog/2015/03/11/release-notes/index.html | 12 +- blog/2015/03/22/release-notes/index.html | 12 +- blog/2015/04/25/release-notes/index.html | 12 +- .../05/09/utc-time-zone-awareness/index.html | 12 +- blog/2015/05/14/release-notes/index.html | 12 +- blog/2015/06/10/release-notes/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../13/home-assistant-meets-ifttt/index.html | 12 +- .../index.html | 12 +- .../alarm-sonos-and-itunes-support/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../11/22/survey-november-2015/index.html | 12 +- .../12/05/community-highlights/index.html | 12 +- .../index.html | 12 +- .../12/07/influxdb-and-grafana/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../01/19/perfect-home-automation/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../multi-room-audio-with-snapcast/index.html | 12 +- .../02/20/community-highlights/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- blog/2016/04/07/static-website/index.html | 12 +- .../index.html | 12 +- .../04/17/updated-documentation/index.html | 12 +- .../04/19/to-infinity-and-beyond/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../05/06/open-iot-summit-talk/index.html | 12 +- .../empowering-scripts-and-alexa/index.html | 12 +- .../index.html | 12 +- blog/2016/05/18/why-we-use-polymer/index.html | 12 +- blog/2016/05/21/release-020/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../06/01/community-highlights/index.html | 12 +- .../08/super-fast-web-enocean-lirc/index.html | 12 +- .../home-assistant-at-pycon-2016/index.html | 12 +- .../index.html | 12 +- .../usb-webcams-and-home-assistant/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../sqlalchemy-knx-join-simplisafe/index.html | 12 +- .../19/visualizing-your-iot-data/index.html | 12 +- .../index.html | 12 +- .../esp8266-and-micropython-part1/index.html | 12 +- .../index.html | 12 +- .../03/laundry-automation-update/index.html | 12 +- .../index.html | 8 +- .../index.html | 12 +- blog/2016/08/16/we-have-apps-now/index.html | 12 +- .../index.html | 12 +- .../index.html | 12 +- .../esp8266-and-micropython-part2/index.html | 347 ++++++++++++++++++ blog/archives/index.html | 50 ++- blog/categories/community/atom.xml | 2 +- blog/categories/community/index.html | 12 +- blog/categories/device-tracking/atom.xml | 2 +- blog/categories/device-tracking/index.html | 12 +- blog/categories/esp8266/atom.xml | 104 +++++- blog/categories/esp8266/index.html | 50 ++- blog/categories/how-to/atom.xml | 213 ++++++----- blog/categories/how-to/index.html | 50 ++- blog/categories/ibeacons/atom.xml | 2 +- blog/categories/ibeacons/index.html | 12 +- blog/categories/internet-of-things/atom.xml | 2 +- blog/categories/internet-of-things/index.html | 12 +- blog/categories/iot-data/atom.xml | 2 +- blog/categories/iot-data/index.html | 12 +- blog/categories/micropython/atom.xml | 104 +++++- blog/categories/micropython/index.html | 50 ++- blog/categories/mqtt/atom.xml | 104 +++++- blog/categories/mqtt/index.html | 50 ++- blog/categories/organisation/atom.xml | 2 +- blog/categories/organisation/index.html | 12 +- blog/categories/owntracks/atom.xml | 2 +- blog/categories/owntracks/index.html | 12 +- blog/categories/presence-detection/atom.xml | 2 +- blog/categories/presence-detection/index.html | 12 +- .../public-service-announcement/atom.xml | 2 +- .../public-service-announcement/index.html | 12 +- blog/categories/release-notes/atom.xml | 2 +- blog/categories/release-notes/index.html | 12 +- blog/categories/survey/atom.xml | 2 +- blog/categories/survey/index.html | 12 +- blog/categories/talks/atom.xml | 2 +- blog/categories/talks/index.html | 12 +- blog/categories/technology/atom.xml | 2 +- blog/categories/technology/index.html | 12 +- blog/categories/user-stories/atom.xml | 2 +- blog/categories/user-stories/index.html | 12 +- blog/categories/video/atom.xml | 2 +- blog/categories/video/index.html | 12 +- blog/categories/website/atom.xml | 2 +- blog/categories/website/index.html | 12 +- blog/index.html | 101 ++--- blog/posts/2/index.html | 102 +++-- blog/posts/3/index.html | 117 +++--- blog/posts/4/index.html | 121 +++--- blog/posts/5/index.html | 109 +++--- blog/posts/6/index.html | 104 +++--- blog/posts/7/index.html | 118 +++--- blog/posts/8/index.html | 125 ++++--- blog/posts/9/index.html | 58 +++ index.html | 10 +- sitemap.xml | 34 +- topics/platform_options/index.html | 12 +- 136 files changed, 2212 insertions(+), 1236 deletions(-) create mode 100644 blog/2016/08/31/esp8266-and-micropython-part2/index.html diff --git a/atom.xml b/atom.xml index ec3e47a98b..2c7f7d0635 100644 --- a/atom.xml +++ b/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ @@ -13,6 +13,107 @@ Octopress + + <![CDATA[ESP8266 and MicroPython - Part 2]]> + + 2016-08-31T04:17:25+00:00 + https://home-assistant.io/blog/2016/08/31/esp8266-and-micropython-part2 + +So, part 1 of ESP8266 and MicroPython was pretty lame, right? Instead of getting information out of Home Assistant we are going a step forward and create our own sensor which is sending details about its state to a Home Assistant instance.

+ + + +

Beside HTTP POST requests, MQTT is the quickest way (from the author’s point of view) to publish information with DIY devices.

+ +

You have to make a decision: Do you want to pull or to poll? For slowly changing values like temperature it’s perfectly fine to wait a couple of seconds to retrieve the value. If it’s a motion detector the state change should be available instantly. This means the sensor must take initiative.

+ +

An example for pulling is aREST. This is a great way to work with the ESP8266 based units and the Ardunio IDE.

+ +

MQTT

+ +

You can find a simple examples for publishing and subscribing with MQTT in the MicroPython library overview in the section for umqtt.

+ +

The example below is adopted from the work of @davea as we don’t want to re-invent the wheel. The configuration feature is crafty and simplyfies the code with the usage of a file called /config.json which stores the configuration details. The ESP8266 device will send the value of a pin every 5 seconds.

+ +
import machine
+import time
+import ubinascii
+import webrepl
+
+from umqtt.simple import MQTTClient
+
+# These defaults are overwritten with the contents of /config.json by load_config()
+CONFIG = {
+    "broker": "192.168.1.19",
+    "sensor_pin": 0, 
+    "client_id": b"esp8266_" + ubinascii.hexlify(machine.unique_id()),
+    "topic": b"home",
+}
+
+client = None
+sensor_pin = None
+
+def setup_pins():
+    global sensor_pin
+    sensor_pin = machine.ADC(CONFIG['sensor_pin'])
+
+def load_config():
+    import ujson as json
+    try:
+        with open("/config.json") as f:
+            config = json.loads(f.read())
+    except (OSError, ValueError):
+        print("Couldn't load /config.json")
+        save_config()
+    else:
+        CONFIG.update(config)
+        print("Loaded config from /config.json")
+
+def save_config():
+    import ujson as json
+    try:
+        with open("/config.json", "w") as f:
+            f.write(json.dumps(CONFIG))
+    except OSError:
+        print("Couldn't save /config.json")
+
+def main():
+    client = MQTTClient(CONFIG['client_id'], CONFIG['broker'])
+    client.connect()
+    print("Connected to {}".format(CONFIG['broker']))
+    while True:
+        data = sensor_pin.read()
+        client.publish('{}/{}'.format(CONFIG['topic'],
+                                          CONFIG['client_id']),
+                                          bytes(str(data), 'utf-8'))
+        print('Sensor state: {}'.format(data))
+        time.sleep(5)
+
+if __name__ == '__main__':
+    load_config()
+    setup_pins()
+    main()
+
+
+ +

Subscribe to the topic home/# or create a MQTT sensor to check if the sensor values are published.

+ +
$ mosquitto_sub -h 192.168.1.19 -v -t "home/#"
+
+
+ +
sensor:
+  - platform: mqtt
+    state_topic: "home/esp8266_[last part of the MAC address]"
+    name: "MicroPython"
+
+
+ +

@davea created sonoff-mqtt. This code will work on ESP8622 based devices too and shows how to use a button to control a relay.

+ +]]>
+
+ <![CDATA[0.27 is here to break eggs and take names: notifications, Hue fakery, safety and unification come to Home Assistant]]> @@ -1762,26 +1863,6 @@ target_dir /tmp

Please see the notes at the end of Part 1 for documentation information.

-]]> -
- - - <![CDATA[Raspberry Pi all-in-one installer]]> - - 2016-05-22T16:06:00+00:00 - https://home-assistant.io/blog/2016/05/22/get-started-with-all-in-one-installer - We are always hard at work at the virtual Home Assistant headquarters to make it easier for you to get started with Home Assistant. That’s why @jbags81 recently introduced the all-in-one installer. It allows you to get up and running with a complete Home Assistant setup by entering one line of code into your Raspberry Pi running Raspbian Jessie:

- -
wget -Nnv https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/hass_rpi_installer.sh && bash hass_rpi_installer.sh;
-
-
- -

This feature wouldn’t be complete if it wasn’t accompanied by a new video by Ben from BRUH Automation. The video shows how to install Raspbian Jessie on your Raspberry Pi and use the new installation script to get a full Home Assistant system up and running.

- -
- -
- ]]>
diff --git a/blog/2014/12/18/website-launched/index.html b/blog/2014/12/18/website-launched/index.html index 328e337775..58feac853d 100644 --- a/blog/2014/12/18/website-launched/index.html +++ b/blog/2014/12/18/website-launched/index.html @@ -169,6 +169,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 47cfca2786..5deffc7fb1 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 @@ -224,6 +224,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 d601ec1e69..6bcdb82426 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 @@ -204,6 +204,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 898887f524..4283fbee2a 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 @@ -181,6 +181,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 a5e2a39f4d..783ba878db 100644 --- a/blog/2015/01/13/nest-in-da-house/index.html +++ b/blog/2015/01/13/nest-in-da-house/index.html @@ -184,6 +184,12 @@ diff --git a/blog/2015/01/24/release-notes/index.html b/blog/2015/01/24/release-notes/index.html index 5d1cb0a298..a896dcacb5 100644 --- a/blog/2015/01/24/release-notes/index.html +++ b/blog/2015/01/24/release-notes/index.html @@ -192,6 +192,12 @@ Home Assistant now supports --open-ui and 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 8723d191ce..24aee91ebd 100644 --- a/blog/2015/02/08/looking-at-the-past/index.html +++ b/blog/2015/02/08/looking-at-the-past/index.html @@ -200,6 +200,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 97eb4b8cb3..43eb3229b6 100644 --- a/blog/2015/02/24/streaming-updates/index.html +++ b/blog/2015/02/24/streaming-updates/index.html @@ -185,6 +185,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 bbe867f4f3..0bd01bb619 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 @@ -175,6 +175,12 @@ diff --git a/blog/2015/03/08/new-logo/index.html b/blog/2015/03/08/new-logo/index.html index 1162e0acac..56e6f4f41b 100644 --- a/blog/2015/03/08/new-logo/index.html +++ b/blog/2015/03/08/new-logo/index.html @@ -176,6 +176,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 b2d884f511..1957ff7747 100644 --- a/blog/2015/03/11/release-notes/index.html +++ b/blog/2015/03/11/release-notes/index.html @@ -209,6 +209,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 9ecfb4d87a..23e6dc5f1c 100644 --- a/blog/2015/03/22/release-notes/index.html +++ b/blog/2015/03/22/release-notes/index.html @@ -244,6 +244,12 @@ I (Paulus) have contributed a scene component. A user can create scenes that cap diff --git a/blog/2015/04/25/release-notes/index.html b/blog/2015/04/25/release-notes/index.html index d706c7e56f..88c39ad1e6 100644 --- a/blog/2015/04/25/release-notes/index.html +++ b/blog/2015/04/25/release-notes/index.html @@ -255,6 +255,12 @@ 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 b122eb813c..adef136729 100644 --- a/blog/2015/05/09/utc-time-zone-awareness/index.html +++ b/blog/2015/05/09/utc-time-zone-awareness/index.html @@ -196,6 +196,12 @@ diff --git a/blog/2015/05/14/release-notes/index.html b/blog/2015/05/14/release-notes/index.html index 95327da0b7..a8352390d8 100644 --- a/blog/2015/05/14/release-notes/index.html +++ b/blog/2015/05/14/release-notes/index.html @@ -276,6 +276,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 d90ea2a14b..756b37dc29 100644 --- a/blog/2015/06/10/release-notes/index.html +++ b/blog/2015/06/10/release-notes/index.html @@ -327,6 +327,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 6390af38de..e8a3b796da 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 @@ -283,6 +283,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 a93178b6c8..0420ebaf09 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 @@ -268,6 +268,12 @@ Support for Temper temperature sensors has been contributed by +
  • + ESP8266 and MicroPython - Part 2 +
  • + + +
  • 0.27 is here to break eggs and take names: notifications, Hue fakery, safety and unification come to Home Assistant
  • @@ -291,12 +297,6 @@ Support for Temper temperature sensors has been contributed by - Optimizing the Home Assistant mobile web app - - - 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 d9b3ae54af..d2ab28c2f6 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 @@ -192,6 +192,12 @@ 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 0dc3fe820b..57f8b75f19 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 @@ -305,6 +305,12 @@ The automation and script syntax here is using a deprecated and no longer suppor 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 70d155d777..bbe0577748 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 @@ -269,6 +269,12 @@ 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 index 649df8c203..667880a179 100644 --- 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 @@ -360,6 +360,12 @@ diff --git a/blog/2015/09/13/home-assistant-meets-ifttt/index.html b/blog/2015/09/13/home-assistant-meets-ifttt/index.html index bc8452187a..f400e063b0 100644 --- a/blog/2015/09/13/home-assistant-meets-ifttt/index.html +++ b/blog/2015/09/13/home-assistant-meets-ifttt/index.html @@ -341,6 +341,12 @@ diff --git a/blog/2015/09/18/monitoring-with-glances-and-home-assistant/index.html b/blog/2015/09/18/monitoring-with-glances-and-home-assistant/index.html index 7c5bd0416f..d604b8a83b 100644 --- a/blog/2015/09/18/monitoring-with-glances-and-home-assistant/index.html +++ b/blog/2015/09/18/monitoring-with-glances-and-home-assistant/index.html @@ -234,6 +234,12 @@ Glances web server started on http://0.0.0.0:61208/ diff --git a/blog/2015/09/19/alarm-sonos-and-itunes-support/index.html b/blog/2015/09/19/alarm-sonos-and-itunes-support/index.html index 1a284c0f9a..8dc7be8522 100644 --- a/blog/2015/09/19/alarm-sonos-and-itunes-support/index.html +++ b/blog/2015/09/19/alarm-sonos-and-itunes-support/index.html @@ -219,6 +219,12 @@ Automation has gotten a lot of love. It now supports conditions, multiple trigge diff --git a/blog/2015/10/05/home-assistant-goes-geo-with-owntracks/index.html b/blog/2015/10/05/home-assistant-goes-geo-with-owntracks/index.html index 4136e74282..35a640b11a 100644 --- a/blog/2015/10/05/home-assistant-goes-geo-with-owntracks/index.html +++ b/blog/2015/10/05/home-assistant-goes-geo-with-owntracks/index.html @@ -199,6 +199,12 @@ Map in Home Assistant showing two people and three zones (home, school, work) diff --git a/blog/2015/10/11/measure-temperature-with-esp8266-and-report-to-mqtt/index.html b/blog/2015/10/11/measure-temperature-with-esp8266-and-report-to-mqtt/index.html index a773eb635d..fd5466989f 100644 --- a/blog/2015/10/11/measure-temperature-with-esp8266-and-report-to-mqtt/index.html +++ b/blog/2015/10/11/measure-temperature-with-esp8266-and-report-to-mqtt/index.html @@ -408,6 +408,12 @@ Home Assistant will keep track of historical values and allow you to integrate i diff --git a/blog/2015/10/11/rfxtrx-blinkstick-and-snmp-support/index.html b/blog/2015/10/11/rfxtrx-blinkstick-and-snmp-support/index.html index 12a4221d92..2d69a8c8b3 100644 --- a/blog/2015/10/11/rfxtrx-blinkstick-and-snmp-support/index.html +++ b/blog/2015/10/11/rfxtrx-blinkstick-and-snmp-support/index.html @@ -188,6 +188,12 @@ diff --git a/blog/2015/10/26/firetv-and-radiotherm-now-supported/index.html b/blog/2015/10/26/firetv-and-radiotherm-now-supported/index.html index 42fb393a49..5e2ad9cdea 100644 --- a/blog/2015/10/26/firetv-and-radiotherm-now-supported/index.html +++ b/blog/2015/10/26/firetv-and-radiotherm-now-supported/index.html @@ -210,6 +210,12 @@ This makes more sense as most people run Home Assistant as a daemon

    diff --git a/blog/2015/11/16/zwave-switches-lights-and-honeywell-thermostats-now-supported/index.html b/blog/2015/11/16/zwave-switches-lights-and-honeywell-thermostats-now-supported/index.html index 04e47bde73..95575dd01b 100644 --- a/blog/2015/11/16/zwave-switches-lights-and-honeywell-thermostats-now-supported/index.html +++ b/blog/2015/11/16/zwave-switches-lights-and-honeywell-thermostats-now-supported/index.html @@ -204,6 +204,12 @@ diff --git a/blog/2015/11/22/survey-november-2015/index.html b/blog/2015/11/22/survey-november-2015/index.html index 71e858f0f7..9f0c0316ae 100644 --- a/blog/2015/11/22/survey-november-2015/index.html +++ b/blog/2015/11/22/survey-november-2015/index.html @@ -246,6 +246,12 @@ diff --git a/blog/2015/12/05/community-highlights/index.html b/blog/2015/12/05/community-highlights/index.html index 78c5f21ffc..11230b6d2c 100644 --- a/blog/2015/12/05/community-highlights/index.html +++ b/blog/2015/12/05/community-highlights/index.html @@ -181,6 +181,12 @@ diff --git a/blog/2015/12/06/locks-rollershutters-binary-sensors-and-influxdb-support/index.html b/blog/2015/12/06/locks-rollershutters-binary-sensors-and-influxdb-support/index.html index 831d995b7f..05a63a3dbc 100644 --- a/blog/2015/12/06/locks-rollershutters-binary-sensors-and-influxdb-support/index.html +++ b/blog/2015/12/06/locks-rollershutters-binary-sensors-and-influxdb-support/index.html @@ -188,6 +188,12 @@ diff --git a/blog/2015/12/07/influxdb-and-grafana/index.html b/blog/2015/12/07/influxdb-and-grafana/index.html index 47dc42e4c9..d62493a1ff 100644 --- a/blog/2015/12/07/influxdb-and-grafana/index.html +++ b/blog/2015/12/07/influxdb-and-grafana/index.html @@ -263,6 +263,12 @@ name: binary_sensor diff --git a/blog/2015/12/10/activating-tasker-tasks-from-home-assistant-using-command-line-switches/index.html b/blog/2015/12/10/activating-tasker-tasks-from-home-assistant-using-command-line-switches/index.html index c414429298..727bf3b577 100644 --- a/blog/2015/12/10/activating-tasker-tasks-from-home-assistant-using-command-line-switches/index.html +++ b/blog/2015/12/10/activating-tasker-tasks-from-home-assistant-using-command-line-switches/index.html @@ -225,6 +225,12 @@ This is where we’ll configure our task, so select the plus icon to select an a diff --git a/blog/2015/12/12/philips-hue-blocks-3rd-party-bulbs/index.html b/blog/2015/12/12/philips-hue-blocks-3rd-party-bulbs/index.html index 1d780783ec..b93eec9307 100644 --- a/blog/2015/12/12/philips-hue-blocks-3rd-party-bulbs/index.html +++ b/blog/2015/12/12/philips-hue-blocks-3rd-party-bulbs/index.html @@ -201,6 +201,12 @@ Philips Hue FAQ entries regarding 3rd party light bulbs. diff --git a/blog/2015/12/13/setup-encryption-using-lets-encrypt/index.html b/blog/2015/12/13/setup-encryption-using-lets-encrypt/index.html index 0f2db0adb5..e469ac789f 100644 --- a/blog/2015/12/13/setup-encryption-using-lets-encrypt/index.html +++ b/blog/2015/12/13/setup-encryption-using-lets-encrypt/index.html @@ -260,6 +260,12 @@ sudo docker run -it --rm -p 80:80 --name certbot \ diff --git a/blog/2015/12/22/amazon-echo-icloud-and-templates/index.html b/blog/2015/12/22/amazon-echo-icloud-and-templates/index.html index 02ca7061c2..bd1eea6b59 100644 --- a/blog/2015/12/22/amazon-echo-icloud-and-templates/index.html +++ b/blog/2015/12/22/amazon-echo-icloud-and-templates/index.html @@ -220,6 +220,12 @@ diff --git a/blog/2016/01/17/extended-support-for-diy-solutions/index.html b/blog/2016/01/17/extended-support-for-diy-solutions/index.html index b4ba50f4b5..b3ba78355e 100644 --- a/blog/2016/01/17/extended-support-for-diy-solutions/index.html +++ b/blog/2016/01/17/extended-support-for-diy-solutions/index.html @@ -202,6 +202,12 @@ diff --git a/blog/2016/01/19/perfect-home-automation/index.html b/blog/2016/01/19/perfect-home-automation/index.html index 2049e5d262..7df2a51f60 100644 --- a/blog/2016/01/19/perfect-home-automation/index.html +++ b/blog/2016/01/19/perfect-home-automation/index.html @@ -206,6 +206,12 @@ diff --git a/blog/2016/01/30/insteon-lifx-twitter-and-zigbee/index.html b/blog/2016/01/30/insteon-lifx-twitter-and-zigbee/index.html index 8089b6afc2..119bc85328 100644 --- a/blog/2016/01/30/insteon-lifx-twitter-and-zigbee/index.html +++ b/blog/2016/01/30/insteon-lifx-twitter-and-zigbee/index.html @@ -208,6 +208,12 @@ Example of the new views in the frontend. Learn mor diff --git a/blog/2016/02/09/Smarter-Smart-Things-with-MQTT-and-Home-Assistant/index.html b/blog/2016/02/09/Smarter-Smart-Things-with-MQTT-and-Home-Assistant/index.html index f9b607e7e1..055541b126 100644 --- a/blog/2016/02/09/Smarter-Smart-Things-with-MQTT-and-Home-Assistant/index.html +++ b/blog/2016/02/09/Smarter-Smart-Things-with-MQTT-and-Home-Assistant/index.html @@ -379,6 +379,12 @@ Z-Wave light bulb | diff --git a/blog/2016/02/12/classifying-the-internet-of-things/index.html b/blog/2016/02/12/classifying-the-internet-of-things/index.html index bf933429c2..d49d5a417f 100644 --- a/blog/2016/02/12/classifying-the-internet-of-things/index.html +++ b/blog/2016/02/12/classifying-the-internet-of-things/index.html @@ -345,6 +345,12 @@ diff --git a/blog/2016/02/13/speedtest-bloomsky-splunk-and-garage-doors/index.html b/blog/2016/02/13/speedtest-bloomsky-splunk-and-garage-doors/index.html index aea2188a7b..5535816603 100644 --- a/blog/2016/02/13/speedtest-bloomsky-splunk-and-garage-doors/index.html +++ b/blog/2016/02/13/speedtest-bloomsky-splunk-and-garage-doors/index.html @@ -211,6 +211,12 @@ diff --git a/blog/2016/02/18/multi-room-audio-with-snapcast/index.html b/blog/2016/02/18/multi-room-audio-with-snapcast/index.html index 795c3eef78..50bc0eb8d1 100644 --- a/blog/2016/02/18/multi-room-audio-with-snapcast/index.html +++ b/blog/2016/02/18/multi-room-audio-with-snapcast/index.html @@ -295,6 +295,12 @@ diff --git a/blog/2016/02/20/community-highlights/index.html b/blog/2016/02/20/community-highlights/index.html index c0b5881422..86e4dec581 100644 --- a/blog/2016/02/20/community-highlights/index.html +++ b/blog/2016/02/20/community-highlights/index.html @@ -219,6 +219,12 @@ Hold your NFC tag against the belly of Garfield to unlock the alarm. diff --git a/blog/2016/02/27/steam-d-link-smart-plugs-and-neurio-energy-sensors/index.html b/blog/2016/02/27/steam-d-link-smart-plugs-and-neurio-energy-sensors/index.html index b16e748377..423b85561c 100644 --- a/blog/2016/02/27/steam-d-link-smart-plugs-and-neurio-energy-sensors/index.html +++ b/blog/2016/02/27/steam-d-link-smart-plugs-and-neurio-energy-sensors/index.html @@ -210,6 +210,12 @@ diff --git a/blog/2016/03/12/z-wave-pep257-templated-service-calls/index.html b/blog/2016/03/12/z-wave-pep257-templated-service-calls/index.html index f8f1f2fdd1..1527484c1e 100644 --- a/blog/2016/03/12/z-wave-pep257-templated-service-calls/index.html +++ b/blog/2016/03/12/z-wave-pep257-templated-service-calls/index.html @@ -214,6 +214,12 @@ player state attributes. This change affects automations, scripts and scenes. +
  • + ESP8266 and MicroPython - Part 2 +
  • + + +
  • 0.27 is here to break eggs and take names: notifications, Hue fakery, safety and unification come to Home Assistant
  • @@ -237,12 +243,6 @@ player state attributes. This change affects automations, scripts and scenes. - -
  • - Optimizing the Home Assistant mobile web app -
  • - - diff --git a/blog/2016/03/26/embedded-mqtt-broker-uber-yamaha-growl/index.html b/blog/2016/03/26/embedded-mqtt-broker-uber-yamaha-growl/index.html index 4899be21ff..f30923ec42 100644 --- a/blog/2016/03/26/embedded-mqtt-broker-uber-yamaha-growl/index.html +++ b/blog/2016/03/26/embedded-mqtt-broker-uber-yamaha-growl/index.html @@ -223,6 +223,12 @@ diff --git a/blog/2016/04/05/your-hub-should-be-local-and-open/index.html b/blog/2016/04/05/your-hub-should-be-local-and-open/index.html index 0bfdf46246..8c5eedc323 100644 --- a/blog/2016/04/05/your-hub-should-be-local-and-open/index.html +++ b/blog/2016/04/05/your-hub-should-be-local-and-open/index.html @@ -179,6 +179,12 @@ diff --git a/blog/2016/04/07/static-website/index.html b/blog/2016/04/07/static-website/index.html index f732046779..6e4b56db26 100644 --- a/blog/2016/04/07/static-website/index.html +++ b/blog/2016/04/07/static-website/index.html @@ -185,6 +185,12 @@ diff --git a/blog/2016/04/09/onkyo-panasonic-gtfs-and-config-validation/index.html b/blog/2016/04/09/onkyo-panasonic-gtfs-and-config-validation/index.html index 2e3d7ebd14..bd32cab367 100644 --- a/blog/2016/04/09/onkyo-panasonic-gtfs-and-config-validation/index.html +++ b/blog/2016/04/09/onkyo-panasonic-gtfs-and-config-validation/index.html @@ -193,6 +193,12 @@ diff --git a/blog/2016/04/17/updated-documentation/index.html b/blog/2016/04/17/updated-documentation/index.html index 4c9aba798b..f791711405 100644 --- a/blog/2016/04/17/updated-documentation/index.html +++ b/blog/2016/04/17/updated-documentation/index.html @@ -177,6 +177,12 @@ diff --git a/blog/2016/04/19/to-infinity-and-beyond/index.html b/blog/2016/04/19/to-infinity-and-beyond/index.html index 859eba1c47..974f998566 100644 --- a/blog/2016/04/19/to-infinity-and-beyond/index.html +++ b/blog/2016/04/19/to-infinity-and-beyond/index.html @@ -194,6 +194,12 @@ diff --git a/blog/2016/04/20/bluetooth-lg-webos-tvs-and-roombas/index.html b/blog/2016/04/20/bluetooth-lg-webos-tvs-and-roombas/index.html index e8c585e627..0ff7f5cfdc 100644 --- a/blog/2016/04/20/bluetooth-lg-webos-tvs-and-roombas/index.html +++ b/blog/2016/04/20/bluetooth-lg-webos-tvs-and-roombas/index.html @@ -212,6 +212,12 @@ diff --git a/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better/index.html b/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better/index.html index 1e2a30d683..d91fe3cc0f 100644 --- a/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better/index.html +++ b/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better/index.html @@ -299,6 +299,12 @@ For example, my wife works next door - and I couldn’t detect whether she’s a diff --git a/blog/2016/05/06/open-iot-summit-talk/index.html b/blog/2016/05/06/open-iot-summit-talk/index.html index 95a711cc6c..bf93528a61 100644 --- a/blog/2016/05/06/open-iot-summit-talk/index.html +++ b/blog/2016/05/06/open-iot-summit-talk/index.html @@ -175,6 +175,12 @@ diff --git a/blog/2016/05/07/empowering-scripts-and-alexa/index.html b/blog/2016/05/07/empowering-scripts-and-alexa/index.html index 1fa60164d6..1423647b71 100644 --- a/blog/2016/05/07/empowering-scripts-and-alexa/index.html +++ b/blog/2016/05/07/empowering-scripts-and-alexa/index.html @@ -257,6 +257,12 @@ diff --git a/blog/2016/05/12/video-configuring-home-assistant/index.html b/blog/2016/05/12/video-configuring-home-assistant/index.html index 2faa99b7a6..9398056c1f 100644 --- a/blog/2016/05/12/video-configuring-home-assistant/index.html +++ b/blog/2016/05/12/video-configuring-home-assistant/index.html @@ -175,6 +175,12 @@ diff --git a/blog/2016/05/18/why-we-use-polymer/index.html b/blog/2016/05/18/why-we-use-polymer/index.html index 4a3717efdb..cc4ce3fa55 100644 --- a/blog/2016/05/18/why-we-use-polymer/index.html +++ b/blog/2016/05/18/why-we-use-polymer/index.html @@ -189,6 +189,12 @@ diff --git a/blog/2016/05/21/release-020/index.html b/blog/2016/05/21/release-020/index.html index cfe3dd096a..fa0e28647c 100644 --- a/blog/2016/05/21/release-020/index.html +++ b/blog/2016/05/21/release-020/index.html @@ -208,6 +208,12 @@ diff --git a/blog/2016/05/22/get-started-with-all-in-one-installer/index.html b/blog/2016/05/22/get-started-with-all-in-one-installer/index.html index b2d79a719b..48ef8160f7 100644 --- a/blog/2016/05/22/get-started-with-all-in-one-installer/index.html +++ b/blog/2016/05/22/get-started-with-all-in-one-installer/index.html @@ -179,6 +179,12 @@ diff --git a/blog/2016/05/26/ibeacons-how-to-track-things-that-cant-track-themselves-part-ii/index.html b/blog/2016/05/26/ibeacons-how-to-track-things-that-cant-track-themselves-part-ii/index.html index b55dc07864..842a804c68 100644 --- a/blog/2016/05/26/ibeacons-how-to-track-things-that-cant-track-themselves-part-ii/index.html +++ b/blog/2016/05/26/ibeacons-how-to-track-things-that-cant-track-themselves-part-ii/index.html @@ -315,6 +315,12 @@ diff --git a/blog/2016/06/01/community-highlights/index.html b/blog/2016/06/01/community-highlights/index.html index 7272f35c4b..b47a560f60 100644 --- a/blog/2016/06/01/community-highlights/index.html +++ b/blog/2016/06/01/community-highlights/index.html @@ -195,6 +195,12 @@ diff --git a/blog/2016/06/08/super-fast-web-enocean-lirc/index.html b/blog/2016/06/08/super-fast-web-enocean-lirc/index.html index 56035e5d34..62b64c8537 100644 --- a/blog/2016/06/08/super-fast-web-enocean-lirc/index.html +++ b/blog/2016/06/08/super-fast-web-enocean-lirc/index.html @@ -229,6 +229,12 @@ diff --git a/blog/2016/06/13/home-assistant-at-pycon-2016/index.html b/blog/2016/06/13/home-assistant-at-pycon-2016/index.html index 46ba1cafb1..f1bef2fd59 100644 --- a/blog/2016/06/13/home-assistant-at-pycon-2016/index.html +++ b/blog/2016/06/13/home-assistant-at-pycon-2016/index.html @@ -200,6 +200,12 @@ diff --git a/blog/2016/06/18/pandora-bt-home-hub-5-and-local-file-camera/index.html b/blog/2016/06/18/pandora-bt-home-hub-5-and-local-file-camera/index.html index b338b5d70e..01e8e72afd 100644 --- a/blog/2016/06/18/pandora-bt-home-hub-5-and-local-file-camera/index.html +++ b/blog/2016/06/18/pandora-bt-home-hub-5-and-local-file-camera/index.html @@ -222,6 +222,12 @@ diff --git a/blog/2016/06/23/usb-webcams-and-home-assistant/index.html b/blog/2016/06/23/usb-webcams-and-home-assistant/index.html index 506a3a2596..4e03283624 100644 --- a/blog/2016/06/23/usb-webcams-and-home-assistant/index.html +++ b/blog/2016/06/23/usb-webcams-and-home-assistant/index.html @@ -276,6 +276,12 @@ target_dir /tmp diff --git a/blog/2016/07/01/envisalink-homematic-hdmi-cec-and-sony-bravia-tv/index.html b/blog/2016/07/01/envisalink-homematic-hdmi-cec-and-sony-bravia-tv/index.html index 3253f553e7..feecac5ccb 100644 --- a/blog/2016/07/01/envisalink-homematic-hdmi-cec-and-sony-bravia-tv/index.html +++ b/blog/2016/07/01/envisalink-homematic-hdmi-cec-and-sony-bravia-tv/index.html @@ -223,6 +223,12 @@ diff --git a/blog/2016/07/06/pocketchip-running-home-assistant/index.html b/blog/2016/07/06/pocketchip-running-home-assistant/index.html index dd850a979e..ab4ba3fc61 100644 --- a/blog/2016/07/06/pocketchip-running-home-assistant/index.html +++ b/blog/2016/07/06/pocketchip-running-home-assistant/index.html @@ -218,6 +218,12 @@ Over a year ago I participated in the +
  • + ESP8266 and MicroPython - Part 2 +
  • + + +
  • 0.27 is here to break eggs and take names: notifications, Hue fakery, safety and unification come to Home Assistant
  • @@ -241,12 +247,6 @@ Over a year ago I participated in the - Optimizing the Home Assistant mobile web app - - - diff --git a/blog/2016/07/16/sqlalchemy-knx-join-simplisafe/index.html b/blog/2016/07/16/sqlalchemy-knx-join-simplisafe/index.html index 0dc8814248..daaa56c21b 100644 --- a/blog/2016/07/16/sqlalchemy-knx-join-simplisafe/index.html +++ b/blog/2016/07/16/sqlalchemy-knx-join-simplisafe/index.html @@ -218,6 +218,12 @@ diff --git a/blog/2016/07/19/visualizing-your-iot-data/index.html b/blog/2016/07/19/visualizing-your-iot-data/index.html index 7bec83382a..25007850f5 100644 --- a/blog/2016/07/19/visualizing-your-iot-data/index.html +++ b/blog/2016/07/19/visualizing-your-iot-data/index.html @@ -270,6 +270,12 @@ SQLite version 3.11.0 2016-02-15 17:29:24 diff --git a/blog/2016/07/23/internet-of-things-data-exploration-with-jupyter-notebooks/index.html b/blog/2016/07/23/internet-of-things-data-exploration-with-jupyter-notebooks/index.html index ba3f3bafa0..9a944a8704 100644 --- a/blog/2016/07/23/internet-of-things-data-exploration-with-jupyter-notebooks/index.html +++ b/blog/2016/07/23/internet-of-things-data-exploration-with-jupyter-notebooks/index.html @@ -235,6 +235,12 @@ One of the graphs created with this tutorial. diff --git a/blog/2016/07/28/esp8266-and-micropython-part1/index.html b/blog/2016/07/28/esp8266-and-micropython-part1/index.html index ea76e569c5..4e8000600e 100644 --- a/blog/2016/07/28/esp8266-and-micropython-part1/index.html +++ b/blog/2016/07/28/esp8266-and-micropython-part1/index.html @@ -322,6 +322,12 @@ If a module is missing then you need to download is it from +
  • + ESP8266 and MicroPython - Part 2 +
  • + + +
  • 0.27 is here to break eggs and take names: notifications, Hue fakery, safety and unification come to Home Assistant
  • @@ -345,12 +351,6 @@ If a module is missing then you need to download is it from - Optimizing the Home Assistant mobile web app - - - diff --git a/blog/2016/07/30/custom-frontend-panels-jupyter-notebooks-directv/index.html b/blog/2016/07/30/custom-frontend-panels-jupyter-notebooks-directv/index.html index 7fc2b74726..7a57fc04e0 100644 --- a/blog/2016/07/30/custom-frontend-panels-jupyter-notebooks-directv/index.html +++ b/blog/2016/07/30/custom-frontend-panels-jupyter-notebooks-directv/index.html @@ -237,6 +237,12 @@ diff --git a/blog/2016/08/03/laundry-automation-update/index.html b/blog/2016/08/03/laundry-automation-update/index.html index 1e6438897b..fe9def5758 100644 --- a/blog/2016/08/03/laundry-automation-update/index.html +++ b/blog/2016/08/03/laundry-automation-update/index.html @@ -274,6 +274,12 @@ diff --git a/blog/2016/08/07/optimizing-the-home-assistant-mobile-web-app/index.html b/blog/2016/08/07/optimizing-the-home-assistant-mobile-web-app/index.html index 78e6fc02f2..64eef48be4 100644 --- a/blog/2016/08/07/optimizing-the-home-assistant-mobile-web-app/index.html +++ b/blog/2016/08/07/optimizing-the-home-assistant-mobile-web-app/index.html @@ -310,6 +310,12 @@ diff --git a/blog/2016/08/13/foursquare-fast-com-ffmpeg-gpsd/index.html b/blog/2016/08/13/foursquare-fast-com-ffmpeg-gpsd/index.html index e077e82855..bd10aa0966 100644 --- a/blog/2016/08/13/foursquare-fast-com-ffmpeg-gpsd/index.html +++ b/blog/2016/08/13/foursquare-fast-com-ffmpeg-gpsd/index.html @@ -236,6 +236,12 @@ diff --git a/blog/2016/08/16/we-have-apps-now/index.html b/blog/2016/08/16/we-have-apps-now/index.html index 74d7f6a8af..e6311cea2d 100644 --- a/blog/2016/08/16/we-have-apps-now/index.html +++ b/blog/2016/08/16/we-have-apps-now/index.html @@ -290,6 +290,12 @@ diff --git a/blog/2016/08/19/github-style-calendar-heatmap-of-device-data/index.html b/blog/2016/08/19/github-style-calendar-heatmap-of-device-data/index.html index 3027983b83..c01791f4f5 100644 --- a/blog/2016/08/19/github-style-calendar-heatmap-of-device-data/index.html +++ b/blog/2016/08/19/github-style-calendar-heatmap-of-device-data/index.html @@ -176,6 +176,12 @@ Heatmap diff --git a/blog/2016/08/28/notifications-hue-fake-unification/index.html b/blog/2016/08/28/notifications-hue-fake-unification/index.html index ec1b5a0f74..232b8b34ed 100644 --- a/blog/2016/08/28/notifications-hue-fake-unification/index.html +++ b/blog/2016/08/28/notifications-hue-fake-unification/index.html @@ -345,6 +345,12 @@ diff --git a/blog/2016/08/31/esp8266-and-micropython-part2/index.html b/blog/2016/08/31/esp8266-and-micropython-part2/index.html new file mode 100644 index 0000000000..19ba0e1516 --- /dev/null +++ b/blog/2016/08/31/esp8266-and-micropython-part2/index.html @@ -0,0 +1,347 @@ + + + + + + + + + + ESP8266 and MicroPython - Part 2 - Home Assistant + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    + + + +
    +
    + +
    + + +
    + +
    + +

    ESP8266 and MicroPython - Part 2

    + + + +
    + + + three minutes reading time + + +
      + + +
    • ESP8266
    • + +
    • How-To
    • + +
    • MQTT
    • + +
    • Micropython
    • + + +
    +
    + + Comments + +
    + +
    + + +

    +So, part 1 of ESP8266 and MicroPython was pretty lame, right? Instead of getting information out of Home Assistant we are going a step forward and create our own sensor which is sending details about its state to a Home Assistant instance.

    + + + +

    Beside HTTP POST requests, MQTT is the quickest way (from the author’s point of view) to publish information with DIY devices.

    + +

    You have to make a decision: Do you want to pull or to poll? For slowly changing values like temperature it’s perfectly fine to wait a couple of seconds to retrieve the value. If it’s a motion detector the state change should be available instantly. This means the sensor must take initiative.

    + +

    An example for pulling is aREST. This is a great way to work with the ESP8266 based units and the Ardunio IDE.

    + +

    MQTT

    + +

    You can find a simple examples for publishing and subscribing with MQTT in the MicroPython library overview in the section for umqtt.

    + +

    The example below is adopted from the work of @davea as we don’t want to re-invent the wheel. The configuration feature is crafty and simplyfies the code with the usage of a file called /config.json which stores the configuration details. The ESP8266 device will send the value of a pin every 5 seconds.

    + +
    import machine
    +import time
    +import ubinascii
    +import webrepl
    +
    +from umqtt.simple import MQTTClient
    +
    +# These defaults are overwritten with the contents of /config.json by load_config()
    +CONFIG = {
    +    "broker": "192.168.1.19",
    +    "sensor_pin": 0, 
    +    "client_id": b"esp8266_" + ubinascii.hexlify(machine.unique_id()),
    +    "topic": b"home",
    +}
    +
    +client = None
    +sensor_pin = None
    +
    +def setup_pins():
    +    global sensor_pin
    +    sensor_pin = machine.ADC(CONFIG['sensor_pin'])
    +
    +def load_config():
    +    import ujson as json
    +    try:
    +        with open("/config.json") as f:
    +            config = json.loads(f.read())
    +    except (OSError, ValueError):
    +        print("Couldn't load /config.json")
    +        save_config()
    +    else:
    +        CONFIG.update(config)
    +        print("Loaded config from /config.json")
    +
    +def save_config():
    +    import ujson as json
    +    try:
    +        with open("/config.json", "w") as f:
    +            f.write(json.dumps(CONFIG))
    +    except OSError:
    +        print("Couldn't save /config.json")
    +
    +def main():
    +    client = MQTTClient(CONFIG['client_id'], CONFIG['broker'])
    +    client.connect()
    +    print("Connected to {}".format(CONFIG['broker']))
    +    while True:
    +        data = sensor_pin.read()
    +        client.publish('{}/{}'.format(CONFIG['topic'],
    +                                          CONFIG['client_id']),
    +                                          bytes(str(data), 'utf-8'))
    +        print('Sensor state: {}'.format(data))
    +        time.sleep(5)
    +
    +if __name__ == '__main__':
    +    load_config()
    +    setup_pins()
    +    main()
    +
    +
    + +

    Subscribe to the topic home/# or create a MQTT sensor to check if the sensor values are published.

    + +
    $ mosquitto_sub -h 192.168.1.19 -v -t "home/#"
    +
    +
    + +
    sensor:
    +  - platform: mqtt
    +    state_topic: "home/esp8266_[last part of the MAC address]"
    +    name: "MicroPython"
    +
    +
    + +

    @davea created sonoff-mqtt. This code will work on ESP8622 based devices too and shows how to use a button to control a relay.

    +
    + + +
    +

    Comments

    +
    +
    + + +
    + + + + +
    +
    + + + + + + + \ No newline at end of file diff --git a/blog/archives/index.html b/blog/archives/index.html index b09fefab4e..09e7347ccd 100644 --- a/blog/archives/index.html +++ b/blog/archives/index.html @@ -2731,6 +2731,44 @@ + + + + @@ -2788,6 +2826,12 @@ diff --git a/blog/categories/community/atom.xml b/blog/categories/community/atom.xml index 76e1dd762d..e6eab8a26c 100644 --- a/blog/categories/community/atom.xml +++ b/blog/categories/community/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Community | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/community/index.html b/blog/categories/community/index.html index b993d40d0b..cca173692f 100644 --- a/blog/categories/community/index.html +++ b/blog/categories/community/index.html @@ -258,6 +258,12 @@ diff --git a/blog/categories/device-tracking/atom.xml b/blog/categories/device-tracking/atom.xml index 5c60e6714e..bd6033da60 100644 --- a/blog/categories/device-tracking/atom.xml +++ b/blog/categories/device-tracking/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Device-Tracking | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/device-tracking/index.html b/blog/categories/device-tracking/index.html index c901d502ec..9c2fbe7ec5 100644 --- a/blog/categories/device-tracking/index.html +++ b/blog/categories/device-tracking/index.html @@ -189,6 +189,12 @@ diff --git a/blog/categories/esp8266/atom.xml b/blog/categories/esp8266/atom.xml index bb474357e9..b147c8086b 100644 --- a/blog/categories/esp8266/atom.xml +++ b/blog/categories/esp8266/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: ESP8266 | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ @@ -13,6 +13,108 @@ Octopress + + <![CDATA[ESP8266 and MicroPython - Part 2]]> + + 2016-08-31T04:17:25+00:00 + https://home-assistant.io/blog/2016/08/31/esp8266-and-micropython-part2 + +So, part 1 of [ESP8266 and MicroPython](/blog/2016/07/28/esp8266-and-micropython-part1/) was pretty lame, right? Instead of getting information out of Home Assistant we are going a step forward and create our own sensor which is sending details about its state to a Home Assistant instance. + + + +Beside [HTTP POST](https://en.wikipedia.org/wiki/POST_(HTTP)) requests, MQTT is the quickest way (from the author's point of view) to publish information with DIY devices. + +You have to make a decision: Do you want to pull or to poll? For slowly changing values like temperature it's perfectly fine to wait a couple of seconds to retrieve the value. If it's a motion detector the state change should be available instantly. This means the sensor must take initiative. + +An example for pulling is [aREST](/components/sensor.arest/). This is a great way to work with the ESP8266 based units and the Ardunio IDE. + +### MQTT + +You can find a simple examples for publishing and subscribing with MQTT in the [MicroPython](https://github.com/micropython/micropython-lib) library overview in the section for [umqtt](https://github.com/micropython/micropython-lib/tree/master/umqtt.simple). + +The example below is adopted from the work of [@davea](https://github.com/davea) as we don't want to re-invent the wheel. The configuration feature is crafty and simplyfies the code with the usage of a file called `/config.json` which stores the configuration details. The ESP8266 device will send the value of a pin every 5 seconds. + + +```python +import machine +import time +import ubinascii +import webrepl + +from umqtt.simple import MQTTClient + +# These defaults are overwritten with the contents of /config.json by load_config() +CONFIG = { + "broker": "192.168.1.19", + "sensor_pin": 0, + "client_id": b"esp8266_" + ubinascii.hexlify(machine.unique_id()), + "topic": b"home", +} + +client = None +sensor_pin = None + +def setup_pins(): + global sensor_pin + sensor_pin = machine.ADC(CONFIG['sensor_pin']) + +def load_config(): + import ujson as json + try: + with open("/config.json") as f: + config = json.loads(f.read()) + except (OSError, ValueError): + print("Couldn't load /config.json") + save_config() + else: + CONFIG.update(config) + print("Loaded config from /config.json") + +def save_config(): + import ujson as json + try: + with open("/config.json", "w") as f: + f.write(json.dumps(CONFIG)) + except OSError: + print("Couldn't save /config.json") + +def main(): + client = MQTTClient(CONFIG['client_id'], CONFIG['broker']) + client.connect() + print("Connected to {}".format(CONFIG['broker'])) + while True: + data = sensor_pin.read() + client.publish('{}/{}'.format(CONFIG['topic'], + CONFIG['client_id']), + bytes(str(data), 'utf-8')) + print('Sensor state: {}'.format(data)) + time.sleep(5) + +if __name__ == '__main__': + load_config() + setup_pins() + main() +``` + +Subscribe to the topic `home/#` or create a [MQTT sensor](/components/sensor.mqtt/) to check if the sensor values are published. + +```bash +$ mosquitto_sub -h 192.168.1.19 -v -t "home/#" +``` + +```yaml +sensor: + - platform: mqtt + state_topic: "home/esp8266_[last part of the MAC address]" + name: "MicroPython" +``` + +[@davea](https://github.com/davea) created [sonoff-mqtt](https://github.com/davea/sonoff-mqtt). This code will work on ESP8622 based devices too and shows how to use a button to control a relay. + +]]> + + <![CDATA[ESP8266 and MicroPython - Part 1]]> diff --git a/blog/categories/esp8266/index.html b/blog/categories/esp8266/index.html index 4b20be4b90..b28836d757 100644 --- a/blog/categories/esp8266/index.html +++ b/blog/categories/esp8266/index.html @@ -98,6 +98,44 @@

    2016

    + + + +
    @@ -228,6 +266,12 @@ diff --git a/blog/categories/how-to/atom.xml b/blog/categories/how-to/atom.xml index f32c51ac34..780ab8f6f1 100644 --- a/blog/categories/how-to/atom.xml +++ b/blog/categories/how-to/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: How-To | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ @@ -13,6 +13,108 @@ Octopress + + <![CDATA[ESP8266 and MicroPython - Part 2]]> + + 2016-08-31T04:17:25+00:00 + https://home-assistant.io/blog/2016/08/31/esp8266-and-micropython-part2 + +So, part 1 of [ESP8266 and MicroPython](/blog/2016/07/28/esp8266-and-micropython-part1/) was pretty lame, right? Instead of getting information out of Home Assistant we are going a step forward and create our own sensor which is sending details about its state to a Home Assistant instance. + + + +Beside [HTTP POST](https://en.wikipedia.org/wiki/POST_(HTTP)) requests, MQTT is the quickest way (from the author's point of view) to publish information with DIY devices. + +You have to make a decision: Do you want to pull or to poll? For slowly changing values like temperature it's perfectly fine to wait a couple of seconds to retrieve the value. If it's a motion detector the state change should be available instantly. This means the sensor must take initiative. + +An example for pulling is [aREST](/components/sensor.arest/). This is a great way to work with the ESP8266 based units and the Ardunio IDE. + +### MQTT + +You can find a simple examples for publishing and subscribing with MQTT in the [MicroPython](https://github.com/micropython/micropython-lib) library overview in the section for [umqtt](https://github.com/micropython/micropython-lib/tree/master/umqtt.simple). + +The example below is adopted from the work of [@davea](https://github.com/davea) as we don't want to re-invent the wheel. The configuration feature is crafty and simplyfies the code with the usage of a file called `/config.json` which stores the configuration details. The ESP8266 device will send the value of a pin every 5 seconds. + + +```python +import machine +import time +import ubinascii +import webrepl + +from umqtt.simple import MQTTClient + +# These defaults are overwritten with the contents of /config.json by load_config() +CONFIG = { + "broker": "192.168.1.19", + "sensor_pin": 0, + "client_id": b"esp8266_" + ubinascii.hexlify(machine.unique_id()), + "topic": b"home", +} + +client = None +sensor_pin = None + +def setup_pins(): + global sensor_pin + sensor_pin = machine.ADC(CONFIG['sensor_pin']) + +def load_config(): + import ujson as json + try: + with open("/config.json") as f: + config = json.loads(f.read()) + except (OSError, ValueError): + print("Couldn't load /config.json") + save_config() + else: + CONFIG.update(config) + print("Loaded config from /config.json") + +def save_config(): + import ujson as json + try: + with open("/config.json", "w") as f: + f.write(json.dumps(CONFIG)) + except OSError: + print("Couldn't save /config.json") + +def main(): + client = MQTTClient(CONFIG['client_id'], CONFIG['broker']) + client.connect() + print("Connected to {}".format(CONFIG['broker'])) + while True: + data = sensor_pin.read() + client.publish('{}/{}'.format(CONFIG['topic'], + CONFIG['client_id']), + bytes(str(data), 'utf-8')) + print('Sensor state: {}'.format(data)) + time.sleep(5) + +if __name__ == '__main__': + load_config() + setup_pins() + main() +``` + +Subscribe to the topic `home/#` or create a [MQTT sensor](/components/sensor.mqtt/) to check if the sensor values are published. + +```bash +$ mosquitto_sub -h 192.168.1.19 -v -t "home/#" +``` + +```yaml +sensor: + - platform: mqtt + state_topic: "home/esp8266_[last part of the MAC address]" + name: "MicroPython" +``` + +[@davea](https://github.com/davea) created [sonoff-mqtt](https://github.com/davea/sonoff-mqtt). This code will work on ESP8622 based devices too and shows how to use a button to control a relay. + +]]> + + <![CDATA[Github-style calendar heatmap of device data]]> @@ -390,115 +492,6 @@ One of the graphs created with this tutorial. Thanks to the magic of Jupyter, all of the code is customizable: want to selectively display your data, only covering a specific entity? Sure thing! Want to change the properties of the plots? No problem! While you learn and explore your IoT data, we will be working on providing more ready-to-use Jupyter Notebooks. Feel free to ask questions or provide suggestions. Would you like to see a specific visualization? Is there a particular facet of data you’re interested in? Let’s talk about it, let’s dive into the world of data together! -]]> - - - - <![CDATA[Visualize your IoT data]]> - - 2016-07-19T16:00:00+00:00 - https://home-assistant.io/blog/2016/07/19/visualizing-your-iot-data - - -The [history component](/components/history/) is tracking everything that is going on within Home Assistant. This means that you have access to all stored information about your home. Our history is not a full-fledged graphical processing and visualization component as you may know from systems and network monitoring tools. The current limitation is that you only can select a day for a visual output of your information and not a period. Also, there is no possibility to drill down on a specific entity. - -This blog post will show you ways to export data for reporting, visualization, or further analysis of automation rules. - - - -In this blog post I use the temperature of the [Aare](https://en.wikipedia.org/wiki/Aare) river close to where I live as a show case. The temperatures were recorded with the [Swiss Hydrological Data sensor](/components/sensor.swiss_hydrological_data/) and the name of the sensor is `sensor.aare`. - -The database is stored at `/.homeassistant/home-assistant_v2.db` as [SQLite database](https://www.sqlite.org/). In all examples we are going to use the path: `/home/ha/.homeassistant/home-assistant_v2.db` - -If you are just curious what's stored in your database then you can use the `sqlite3` command-line tool or a graphical one like [DB Browser for SQLite](http://sqlitebrowser.org/). - -The table that is holding the states is called `states`. The `events` tables is responsible for storing the events which occurred. So, we will first check how many entries there are in the `states` table. `sqlite3` needs to know where the databases is located. To work with your database make sure that Home Assistant is not running or create a copy of the existing database. It's recommended to work with a copy. - -```bash -$ sqlite3 /home/ha/.homeassistant/home-assistant_v2.db -SQLite version 3.11.0 2016-02-15 17:29:24 -sqlite> SELECT count(*) FROM states; -24659 -``` - -Let's have a look at a sample [SQL](https://en.wikipedia.org/wiki/SQL) query. This query will show all states in a period for the sensor `sensor.aare`. - -```sql -SELECT state, last_changed FROM states - WHERE - entity_id = 'sensor.aare' - AND - last_changed BETWEEN - '2016-07-05 00:00:00.000000' AND '2016-07-07 00:00:00.000000'; -``` - -The SQL statement can be formed that it fits exactly what you need. This means that you can process the data in any way you want for further use. Often it makes sense to eliminate certain entries like `Unknown` or peaks. - -If the above query is executed in DB Browser for SQLite you would be able to save the sensor's graph as png. - -

    - - Visualization with DB Browser for SQLite -

    - -You may ask: Why not do this with LibreOffice Calc or another spreadsheet application? As most spreadsheet applications are not able to work directly with SQLite database we are going to export the data from the database to [CSV](https://en.wikipedia.org/wiki/Comma-separated_values). - -```bash -$ sqlite3 -header -csv /home/ha/.homeassistant/home-assistant_v2.db "SELECT last_changed, state FROM states WHERE entity_id = 'sensor.aare' AND last_changed BETWEEN '2016-07-05 00:00:00.000000' AND '2016-07-07 00:00:00.000000';" > sensor.csv -``` - -The ordering for the `SELECT` was changed to get the time stamps first and then the state. Now we can import the CSV file into the application of your choice, here it's LibreOffice Calc. - -

    - - Import of the CSV file -

    - -After the import a graph can be created over the existing data. - -

    - - Graph in LibreOffice -

    - -You can also use [matplotlib](http://matplotlib.org/) to generate graphs as an alternative to a spreadsheet application. This is a powerful Python 2D plotting library. With the built-in support for SQLite in Python it will only take a couple lines of code to visualize your data. - -```python -import sqlite3 -from matplotlib import dates -import matplotlib.pyplot as plt - -import homeassistant.util.dt as dt - -values = [] -timestamps = [] - -conn = sqlite3.connect('/home/ha/.homeassistant/home-assistant_v2.db') -data = conn.execute("SELECT state, last_changed FROM states WHERE " - "entity_id = 'sensor.aare' AND last_changed BETWEEN " - "'2016-07-05 00:00:00.000000' AND " - "'2016-07-07 00:00:00.000000'") - -for x in data: - timestamps.append(dates.date2num(dt.parse_datetime(x[1]))) - values.append(float(x[0])) - -plt.plot_date(x=timestamps, y=values, fmt="r-") -plt.ylabel('Temperature') -plt.xlabel('Time line') - -plt.savefig('sensor.png') -``` - -Creating a connection to the database and executing a query is similar to the ways already seen. The return values from the query are splitted into two lists. The time stamps must be converted in an value which is accepted by matplotlib and then the graph is generated and saved as image. - -

    - - Sensor graph generated by matplotlib -

    - -Most of the graphs are pretty ugly. So, further beautification will be needed. If you have created a nice report including some amazing graphs then the Home Assistant community would be grateful for sharing them in our [forum](https://community.home-assistant.io/). - ]]>
    diff --git a/blog/categories/how-to/index.html b/blog/categories/how-to/index.html index eada54d459..3b13bf61ee 100644 --- a/blog/categories/how-to/index.html +++ b/blog/categories/how-to/index.html @@ -98,6 +98,44 @@

    2016

    + + + +
    @@ -720,6 +758,12 @@ diff --git a/blog/categories/ibeacons/atom.xml b/blog/categories/ibeacons/atom.xml index 6b6d981c77..19e5fcf7f6 100644 --- a/blog/categories/ibeacons/atom.xml +++ b/blog/categories/ibeacons/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: iBeacons | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/ibeacons/index.html b/blog/categories/ibeacons/index.html index d8d82142a0..0628249922 100644 --- a/blog/categories/ibeacons/index.html +++ b/blog/categories/ibeacons/index.html @@ -225,6 +225,12 @@ diff --git a/blog/categories/internet-of-things/atom.xml b/blog/categories/internet-of-things/atom.xml index 3ae763d40c..be4b5b0651 100644 --- a/blog/categories/internet-of-things/atom.xml +++ b/blog/categories/internet-of-things/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Internet-of-Things | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/internet-of-things/index.html b/blog/categories/internet-of-things/index.html index f66148d5f9..74a2229634 100644 --- a/blog/categories/internet-of-things/index.html +++ b/blog/categories/internet-of-things/index.html @@ -284,6 +284,12 @@ diff --git a/blog/categories/iot-data/atom.xml b/blog/categories/iot-data/atom.xml index 8704694548..6a8f17b6e3 100644 --- a/blog/categories/iot-data/atom.xml +++ b/blog/categories/iot-data/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: IoT-Data | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/iot-data/index.html b/blog/categories/iot-data/index.html index cdd786563d..254262b830 100644 --- a/blog/categories/iot-data/index.html +++ b/blog/categories/iot-data/index.html @@ -255,6 +255,12 @@ diff --git a/blog/categories/micropython/atom.xml b/blog/categories/micropython/atom.xml index 1b38a765d6..dc38ea8ef0 100644 --- a/blog/categories/micropython/atom.xml +++ b/blog/categories/micropython/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Micropython | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ @@ -13,6 +13,108 @@ Octopress + + <![CDATA[ESP8266 and MicroPython - Part 2]]> + + 2016-08-31T04:17:25+00:00 + https://home-assistant.io/blog/2016/08/31/esp8266-and-micropython-part2 + +So, part 1 of [ESP8266 and MicroPython](/blog/2016/07/28/esp8266-and-micropython-part1/) was pretty lame, right? Instead of getting information out of Home Assistant we are going a step forward and create our own sensor which is sending details about its state to a Home Assistant instance. + + + +Beside [HTTP POST](https://en.wikipedia.org/wiki/POST_(HTTP)) requests, MQTT is the quickest way (from the author's point of view) to publish information with DIY devices. + +You have to make a decision: Do you want to pull or to poll? For slowly changing values like temperature it's perfectly fine to wait a couple of seconds to retrieve the value. If it's a motion detector the state change should be available instantly. This means the sensor must take initiative. + +An example for pulling is [aREST](/components/sensor.arest/). This is a great way to work with the ESP8266 based units and the Ardunio IDE. + +### MQTT + +You can find a simple examples for publishing and subscribing with MQTT in the [MicroPython](https://github.com/micropython/micropython-lib) library overview in the section for [umqtt](https://github.com/micropython/micropython-lib/tree/master/umqtt.simple). + +The example below is adopted from the work of [@davea](https://github.com/davea) as we don't want to re-invent the wheel. The configuration feature is crafty and simplyfies the code with the usage of a file called `/config.json` which stores the configuration details. The ESP8266 device will send the value of a pin every 5 seconds. + + +```python +import machine +import time +import ubinascii +import webrepl + +from umqtt.simple import MQTTClient + +# These defaults are overwritten with the contents of /config.json by load_config() +CONFIG = { + "broker": "192.168.1.19", + "sensor_pin": 0, + "client_id": b"esp8266_" + ubinascii.hexlify(machine.unique_id()), + "topic": b"home", +} + +client = None +sensor_pin = None + +def setup_pins(): + global sensor_pin + sensor_pin = machine.ADC(CONFIG['sensor_pin']) + +def load_config(): + import ujson as json + try: + with open("/config.json") as f: + config = json.loads(f.read()) + except (OSError, ValueError): + print("Couldn't load /config.json") + save_config() + else: + CONFIG.update(config) + print("Loaded config from /config.json") + +def save_config(): + import ujson as json + try: + with open("/config.json", "w") as f: + f.write(json.dumps(CONFIG)) + except OSError: + print("Couldn't save /config.json") + +def main(): + client = MQTTClient(CONFIG['client_id'], CONFIG['broker']) + client.connect() + print("Connected to {}".format(CONFIG['broker'])) + while True: + data = sensor_pin.read() + client.publish('{}/{}'.format(CONFIG['topic'], + CONFIG['client_id']), + bytes(str(data), 'utf-8')) + print('Sensor state: {}'.format(data)) + time.sleep(5) + +if __name__ == '__main__': + load_config() + setup_pins() + main() +``` + +Subscribe to the topic `home/#` or create a [MQTT sensor](/components/sensor.mqtt/) to check if the sensor values are published. + +```bash +$ mosquitto_sub -h 192.168.1.19 -v -t "home/#" +``` + +```yaml +sensor: + - platform: mqtt + state_topic: "home/esp8266_[last part of the MAC address]" + name: "MicroPython" +``` + +[@davea](https://github.com/davea) created [sonoff-mqtt](https://github.com/davea/sonoff-mqtt). This code will work on ESP8622 based devices too and shows how to use a button to control a relay. + +]]> + + <![CDATA[ESP8266 and MicroPython - Part 1]]> diff --git a/blog/categories/micropython/index.html b/blog/categories/micropython/index.html index 7bfbae3f43..f02919440b 100644 --- a/blog/categories/micropython/index.html +++ b/blog/categories/micropython/index.html @@ -98,6 +98,44 @@

    2016

    + + + +
    @@ -189,6 +227,12 @@ diff --git a/blog/categories/mqtt/atom.xml b/blog/categories/mqtt/atom.xml index b539430a79..587efd4fbf 100644 --- a/blog/categories/mqtt/atom.xml +++ b/blog/categories/mqtt/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: MQTT | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ @@ -13,6 +13,108 @@ Octopress + + <![CDATA[ESP8266 and MicroPython - Part 2]]> + + 2016-08-31T04:17:25+00:00 + https://home-assistant.io/blog/2016/08/31/esp8266-and-micropython-part2 + +So, part 1 of [ESP8266 and MicroPython](/blog/2016/07/28/esp8266-and-micropython-part1/) was pretty lame, right? Instead of getting information out of Home Assistant we are going a step forward and create our own sensor which is sending details about its state to a Home Assistant instance. + + + +Beside [HTTP POST](https://en.wikipedia.org/wiki/POST_(HTTP)) requests, MQTT is the quickest way (from the author's point of view) to publish information with DIY devices. + +You have to make a decision: Do you want to pull or to poll? For slowly changing values like temperature it's perfectly fine to wait a couple of seconds to retrieve the value. If it's a motion detector the state change should be available instantly. This means the sensor must take initiative. + +An example for pulling is [aREST](/components/sensor.arest/). This is a great way to work with the ESP8266 based units and the Ardunio IDE. + +### MQTT + +You can find a simple examples for publishing and subscribing with MQTT in the [MicroPython](https://github.com/micropython/micropython-lib) library overview in the section for [umqtt](https://github.com/micropython/micropython-lib/tree/master/umqtt.simple). + +The example below is adopted from the work of [@davea](https://github.com/davea) as we don't want to re-invent the wheel. The configuration feature is crafty and simplyfies the code with the usage of a file called `/config.json` which stores the configuration details. The ESP8266 device will send the value of a pin every 5 seconds. + + +```python +import machine +import time +import ubinascii +import webrepl + +from umqtt.simple import MQTTClient + +# These defaults are overwritten with the contents of /config.json by load_config() +CONFIG = { + "broker": "192.168.1.19", + "sensor_pin": 0, + "client_id": b"esp8266_" + ubinascii.hexlify(machine.unique_id()), + "topic": b"home", +} + +client = None +sensor_pin = None + +def setup_pins(): + global sensor_pin + sensor_pin = machine.ADC(CONFIG['sensor_pin']) + +def load_config(): + import ujson as json + try: + with open("/config.json") as f: + config = json.loads(f.read()) + except (OSError, ValueError): + print("Couldn't load /config.json") + save_config() + else: + CONFIG.update(config) + print("Loaded config from /config.json") + +def save_config(): + import ujson as json + try: + with open("/config.json", "w") as f: + f.write(json.dumps(CONFIG)) + except OSError: + print("Couldn't save /config.json") + +def main(): + client = MQTTClient(CONFIG['client_id'], CONFIG['broker']) + client.connect() + print("Connected to {}".format(CONFIG['broker'])) + while True: + data = sensor_pin.read() + client.publish('{}/{}'.format(CONFIG['topic'], + CONFIG['client_id']), + bytes(str(data), 'utf-8')) + print('Sensor state: {}'.format(data)) + time.sleep(5) + +if __name__ == '__main__': + load_config() + setup_pins() + main() +``` + +Subscribe to the topic `home/#` or create a [MQTT sensor](/components/sensor.mqtt/) to check if the sensor values are published. + +```bash +$ mosquitto_sub -h 192.168.1.19 -v -t "home/#" +``` + +```yaml +sensor: + - platform: mqtt + state_topic: "home/esp8266_[last part of the MAC address]" + name: "MicroPython" +``` + +[@davea](https://github.com/davea) created [sonoff-mqtt](https://github.com/davea/sonoff-mqtt). This code will work on ESP8622 based devices too and shows how to use a button to control a relay. + +]]> + + <![CDATA[Smarter SmartThings with MQTT and Home Assistant]]> diff --git a/blog/categories/mqtt/index.html b/blog/categories/mqtt/index.html index 7d5cf24857..0cc6ccfc1c 100644 --- a/blog/categories/mqtt/index.html +++ b/blog/categories/mqtt/index.html @@ -98,6 +98,44 @@

    2016

    + + + +
    @@ -260,6 +298,12 @@ diff --git a/blog/categories/organisation/atom.xml b/blog/categories/organisation/atom.xml index 2cf5429676..1568ef736e 100644 --- a/blog/categories/organisation/atom.xml +++ b/blog/categories/organisation/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Organisation | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/organisation/index.html b/blog/categories/organisation/index.html index 0616cb62f9..7a36a62207 100644 --- a/blog/categories/organisation/index.html +++ b/blog/categories/organisation/index.html @@ -220,6 +220,12 @@ diff --git a/blog/categories/owntracks/atom.xml b/blog/categories/owntracks/atom.xml index 62d5933e85..c8a2daa423 100644 --- a/blog/categories/owntracks/atom.xml +++ b/blog/categories/owntracks/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: OwnTracks | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/owntracks/index.html b/blog/categories/owntracks/index.html index 64da2ac7dc..33850d3eac 100644 --- a/blog/categories/owntracks/index.html +++ b/blog/categories/owntracks/index.html @@ -225,6 +225,12 @@ diff --git a/blog/categories/presence-detection/atom.xml b/blog/categories/presence-detection/atom.xml index 44808f0af8..1ef4d13f7f 100644 --- a/blog/categories/presence-detection/atom.xml +++ b/blog/categories/presence-detection/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Presence-Detection | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/presence-detection/index.html b/blog/categories/presence-detection/index.html index ac40427858..f8b6889a76 100644 --- a/blog/categories/presence-detection/index.html +++ b/blog/categories/presence-detection/index.html @@ -189,6 +189,12 @@ diff --git a/blog/categories/public-service-announcement/atom.xml b/blog/categories/public-service-announcement/atom.xml index b04daf577f..71a349bbde 100644 --- a/blog/categories/public-service-announcement/atom.xml +++ b/blog/categories/public-service-announcement/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Public-Service-Announcement | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/public-service-announcement/index.html b/blog/categories/public-service-announcement/index.html index 671f68852b..59ae92d021 100644 --- a/blog/categories/public-service-announcement/index.html +++ b/blog/categories/public-service-announcement/index.html @@ -185,6 +185,12 @@ diff --git a/blog/categories/release-notes/atom.xml b/blog/categories/release-notes/atom.xml index 4219b21eee..769e80a706 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]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/release-notes/index.html b/blog/categories/release-notes/index.html index 4ca24c39a5..c82f521fcf 100644 --- a/blog/categories/release-notes/index.html +++ b/blog/categories/release-notes/index.html @@ -1502,6 +1502,12 @@ diff --git a/blog/categories/survey/atom.xml b/blog/categories/survey/atom.xml index 077ad9cc77..72cd7551df 100644 --- a/blog/categories/survey/atom.xml +++ b/blog/categories/survey/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Survey | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/survey/index.html b/blog/categories/survey/index.html index 2d1c86de0d..2415008f47 100644 --- a/blog/categories/survey/index.html +++ b/blog/categories/survey/index.html @@ -185,6 +185,12 @@ diff --git a/blog/categories/talks/atom.xml b/blog/categories/talks/atom.xml index 36b841bad2..7d505f19f0 100644 --- a/blog/categories/talks/atom.xml +++ b/blog/categories/talks/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Talks | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/talks/index.html b/blog/categories/talks/index.html index c672ccb2ec..7b9fbcdc02 100644 --- a/blog/categories/talks/index.html +++ b/blog/categories/talks/index.html @@ -187,6 +187,12 @@ diff --git a/blog/categories/technology/atom.xml b/blog/categories/technology/atom.xml index 25694ab051..02c2b5ef53 100644 --- a/blog/categories/technology/atom.xml +++ b/blog/categories/technology/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Technology | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/technology/index.html b/blog/categories/technology/index.html index dde8a8eb16..500fa65737 100644 --- a/blog/categories/technology/index.html +++ b/blog/categories/technology/index.html @@ -217,6 +217,12 @@ diff --git a/blog/categories/user-stories/atom.xml b/blog/categories/user-stories/atom.xml index 9734cc3e90..4a7df825de 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]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/user-stories/index.html b/blog/categories/user-stories/index.html index 2ac8ee6325..5fbc7f9bf6 100644 --- a/blog/categories/user-stories/index.html +++ b/blog/categories/user-stories/index.html @@ -220,6 +220,12 @@ diff --git a/blog/categories/video/atom.xml b/blog/categories/video/atom.xml index a9c6dfbbb1..975801df6c 100644 --- a/blog/categories/video/atom.xml +++ b/blog/categories/video/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Video | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/video/index.html b/blog/categories/video/index.html index e23f4fe926..eddfb87845 100644 --- a/blog/categories/video/index.html +++ b/blog/categories/video/index.html @@ -388,6 +388,12 @@ diff --git a/blog/categories/website/atom.xml b/blog/categories/website/atom.xml index 90ac253050..98e10f7fb4 100644 --- a/blog/categories/website/atom.xml +++ b/blog/categories/website/atom.xml @@ -4,7 +4,7 @@ <![CDATA[Category: Website | Home Assistant]]> - 2016-08-30T21:57:10+00:00 + 2016-08-31T05:03:39+00:00 https://home-assistant.io/ diff --git a/blog/categories/website/index.html b/blog/categories/website/index.html index d94a5d84e4..8997171481 100644 --- a/blog/categories/website/index.html +++ b/blog/categories/website/index.html @@ -220,6 +220,12 @@ diff --git a/blog/index.html b/blog/index.html index d0b1a9eddc..04e8c9498d 100644 --- a/blog/index.html +++ b/blog/index.html @@ -78,6 +78,57 @@ +
    +
    + +

    + ESP8266 and MicroPython - Part 2 +

    + + + +
    + + + three minutes reading time + + +
      + + +
    • ESP8266
    • + +
    • How-To
    • + +
    • MQTT
    • + +
    • Micropython
    • + + +
    +
    + + Comments + +
    + +
    + + +
    +

    +So, part 1 of ESP8266 and MicroPython was pretty lame, right? Instead of getting information out of Home Assistant we are going a step forward and create our own sensor which is sending details about its state to a Home Assistant instance.

    + + + + Read on → + +
    +
    +
    +
    @@ -842,56 +893,6 @@ One of the graphs created with this tutorial.

    -
    -
    - -

    - Visualize your IoT data -

    - - - -
    - - - five minutes reading time - - -
      - - -
    • How-To
    • - -
    • IoT-Data
    • - - -
    -
    - - Comments - -
    - -
    - - -
    -

    - -

    The history component is tracking everything that is going on within Home Assistant. This means that you have access to all stored information about your home. Our history is not a full-fledged graphical processing and visualization component as you may know from systems and network monitoring tools. The current limitation is that you only can select a day for a visual output of your information and not a period. Also, there is no possibility to drill down on a specific entity.

    - -

    This blog post will show you ways to export data for reporting, visualization, or further analysis of automation rules.

    - - - - Read on → - -
    -
    -
    - -
    -
    - -
    -
    - -

    - Raspberry Pi all-in-one installer -

    - - - -
    - - - Less than one minute reading time - - -
      - - -
    • Video
    • - - -
    -
    - - Comments - -
    - -
    - - -
    -

    We are always hard at work at the virtual Home Assistant headquarters to make it easier for you to get started with Home Assistant. That’s why @jbags81 recently introduced the all-in-one installer. It allows you to get up and running with a complete Home Assistant setup by entering one line of code into your Raspberry Pi running Raspbian Jessie:

    - -
    wget -Nnv https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/hass_rpi_installer.sh && bash hass_rpi_installer.sh;
    -
    -
    - -

    This feature wouldn’t be complete if it wasn’t accompanied by a new video by Ben from BRUH Automation. The video shows how to install Raspbian Jessie on your Raspberry Pi and use the new installation script to get a full Home Assistant system up and running.

    - -
    - -
    - - -

    diff --git a/blog/posts/3/index.html b/blog/posts/3/index.html index a871b6f6b6..6062d7b416 100644 --- a/blog/posts/3/index.html +++ b/blog/posts/3/index.html @@ -78,6 +78,58 @@ +
    +
    + +

    + Raspberry Pi all-in-one installer +

    + + + +
    + + + Less than one minute reading time + + +
      + + +
    • Video
    • + + +
    +
    + + Comments + +
    + +
    + + +
    +

    We are always hard at work at the virtual Home Assistant headquarters to make it easier for you to get started with Home Assistant. That’s why @jbags81 recently introduced the all-in-one installer. It allows you to get up and running with a complete Home Assistant setup by entering one line of code into your Raspberry Pi running Raspbian Jessie:

    + +
    wget -Nnv https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/hass_rpi_installer.sh && bash hass_rpi_installer.sh;
    +
    +
    + +

    This feature wouldn’t be complete if it wasn’t accompanied by a new video by Ben from BRUH Automation. The video shows how to install Raspbian Jessie on your Raspberry Pi and use the new installation script to get a full Home Assistant system up and running.

    + +
    + +
    + + + +
    +
    +
    +
    @@ -687,71 +739,6 @@

    Finally, if you see some content that could use more clarifcation or is outdated, don’t hesitate to use the ‘Edit in GitHub’ link that is present on each page.

    -
    -
    -
    - -
    -
    - -

    - 0.17: Onkyo, Panasonic, GTFS and config validation -

    - - - -
    - - - 1 minute reading time - - -
      - - -
    • Release-Notes
    • - - -
    -
    - - Comments - -
    - -
    - - -
    -

    Another awesome release ready to hit your homes. YAML can be hard for beginners and more experienced automators. So to help catch those pesky errors that sneak into your files we’ve been hard at work to introduce config validation! Especially huge thanks to @jaharkes for his hard work on this. Config validation is still in it’s early stages. More common platforms and components have been added but we didn’t do everything yet.

    - -

    When we encounter an invalid config we will now write a warning to your logs. You can see those in the frontend by clicking on the last developer tool. We’re looking into options to make it more clear - it is a work in progress.

    - -

    Another big thing is the addition of GTFS support. You probably don’t know it, but GTFS is the standard that public transit companies all over the world use to distribute their schedule. This means that you can now have the time of the next bus/train/etc right in your frontend.

    - -

    - - - -

    Breaking changes

    - -

    As of now we are not aware of any breaking changes. However, it might be that Home Assistant will not start for you because of an invalid configuration. A common mistake that people are making is that they are still referring to execute_service in their script configs. This should be service.

    - -

    diff --git a/blog/posts/4/index.html b/blog/posts/4/index.html index 69e897cac9..2ec71d5473 100644 --- a/blog/posts/4/index.html +++ b/blog/posts/4/index.html @@ -78,6 +78,71 @@ +
    +
    + +

    + 0.17: Onkyo, Panasonic, GTFS and config validation +

    + + + +
    + + + 1 minute reading time + + +
      + + +
    • Release-Notes
    • + + +
    +
    + + Comments + +
    + +
    + + +
    +

    Another awesome release ready to hit your homes. YAML can be hard for beginners and more experienced automators. So to help catch those pesky errors that sneak into your files we’ve been hard at work to introduce config validation! Especially huge thanks to @jaharkes for his hard work on this. Config validation is still in it’s early stages. More common platforms and components have been added but we didn’t do everything yet.

    + +

    When we encounter an invalid config we will now write a warning to your logs. You can see those in the frontend by clicking on the last developer tool. We’re looking into options to make it more clear - it is a work in progress.

    + +

    Another big thing is the addition of GTFS support. You probably don’t know it, but GTFS is the standard that public transit companies all over the world use to distribute their schedule. This means that you can now have the time of the next bus/train/etc right in your frontend.

    + +

    + + + +

    Breaking changes

    + +

    As of now we are not aware of any breaking changes. However, it might be that Home Assistant will not start for you because of an invalid configuration. A common mistake that people are making is that they are still referring to execute_service in their script configs. This should be service.

    + + +
    +
    +
    +
    @@ -779,62 +844,6 @@ Hold your NFC tag against the belly of Garfield to unlock the alarm.

    -
    -
    - -

    - Smarter SmartThings with MQTT and Home Assistant -

    - - - -
    - - - nine minutes reading time - - -
      - - -
    • How-To
    • - -
    • MQTT
    • - - -
    -
    - - Comments - -
    - -
    - - -
    -

    This is a guest post by Home Assistant users Jeremiah Wuenschel and St. John Johnson.

    - -

    So you own a SmartThings Hub. You probably bought it when you were looking to get into the whole Home Automation hobby because it worked with pretty much everything and offered you the ability to automate anything. After a week of ownership, you realized that building dashboards and automating required writing way more Groovy then you expected. Then one day you were browsing reddit and discovered the amazingness that is Home Assistant! A solution that offered dashboards, graphs, working support for Nest, and REAL EASY automation!

    - -

    You spent your weekend getting everything set up, showing it off to your significant other, but in the end you got stumped when it came to integrating with all your existing SmartThings toys. What do I do now? Should I buy another hub? Should I just buy a Z-Wave stick?

    - -

    That’s where we came in. We wanted a solution that can bridge the awesomeness of Home Assistant with the SmartThings hub that works with almost everything.

    - -

    - -

    - - - - Read on → - -
    -
    -
    - -
    -
    - -
    -
    - -

    - Community Highlights -

    - - - -
    - - - Less than one minute reading time - - -
      - - -
    • Community
    • - -
    • Video
    • - - -
    -
    - - Comments - -
    - -
    - - -
    -

    From time to time we come along things that are worth sharing with fellow Home Assisters. Here a list of some cool stuff from last week:

    - -

    First is the public beta of Let’s Encrypt. Let’s Encrypt is a new certificate authority that is free, automated and open. This means that it will now be very easy to secure your connection to Home Assistant while you are away from home. W1ll1am23 has written up a guide how to get started.

    - -

    The next thing is a show-off of some of the cool stuff people do with Home Assistant. This is miniconfig talking to Home Assistant using the Amazon Echo!

    - -
    - -
    - -

    And last but not least, Midwestern Mac did a microSD card performance comparison for the Raspberry Pi. If you’re using a Pi, make sure to check it out!

    - -

    diff --git a/blog/posts/6/index.html b/blog/posts/6/index.html index 4148fb798b..27245d7ceb 100644 --- a/blog/posts/6/index.html +++ b/blog/posts/6/index.html @@ -78,6 +78,59 @@ +
    +
    + +

    + Community Highlights +

    + + + +
    + + + Less than one minute reading time + + +
      + + +
    • Community
    • + +
    • Video
    • + + +
    +
    + + Comments + +
    + +
    + + +
    +

    From time to time we come along things that are worth sharing with fellow Home Assisters. Here a list of some cool stuff from last week:

    + +

    First is the public beta of Let’s Encrypt. Let’s Encrypt is a new certificate authority that is free, automated and open. This means that it will now be very easy to secure your connection to Home Assistant while you are away from home. W1ll1am23 has written up a guide how to get started.

    + +

    The next thing is a show-off of some of the cool stuff people do with Home Assistant. This is miniconfig talking to Home Assistant using the Amazon Echo!

    + +
    + +
    + +

    And last but not least, Midwestern Mac did a microSD card performance comparison for the Raspberry Pi. If you’re using a Pi, make sure to check it out!

    + + +
    +
    +
    +
    @@ -622,57 +675,6 @@ Inspried by a -
    - -

    - Using MQTT with Home Assistant -

    - - - -
    - - - eight minutes reading time - - -
      - - -
    • How-To
    • - -
    • MQTT
    • - - -
    -
    - - Comments - -
    - -
    - - -
    - -

    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 → - -
    -
    -
    - diff --git a/sitemap.xml b/sitemap.xml index 9cc86b464f..3001da43b6 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -1,6 +1,10 @@ +https://home-assistant.io/blog/2016/08/31/esp8266-and-micropython-part2/ +2016-08-31T04:17:25+00:00 + + https://home-assistant.io/blog/2016/08/28/notifications-hue-fake-unification/ 2016-08-28T03:30:25+00:00 @@ -1979,62 +1983,62 @@ https://home-assistant.io/demo/frontend.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/index.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-dev-event.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-dev-info.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-dev-service.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-dev-state.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-dev-template.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-history.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-iframe.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-logbook.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/demo/panels/ha-panel-map.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/googlef4f3693c209fe788.html -2016-08-30T21:56:21+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/static/fonts/roboto/DESCRIPTION.en_us.html -2016-08-30T21:56:22+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/static/fonts/robotomono/DESCRIPTION.en_us.html -2016-08-30T21:56:22+00:00 +2016-08-31T05:02:57+00:00 https://home-assistant.io/static/mdi-demo.html -2016-08-30T21:56:22+00:00 +2016-08-31T05:02:57+00:00 diff --git a/topics/platform_options/index.html b/topics/platform_options/index.html index dc2e57b1b2..cfbeef9aa3 100644 --- a/topics/platform_options/index.html +++ b/topics/platform_options/index.html @@ -170,6 +170,12 @@