I would like to give a shout out to Greg Dowling (@pavoni) as every release includes new work from him. He is constantly adding support for new platforms or improving the reliablity of existing components and platforms. Keep up the good work!
This release includes a very frequent requested feature: the ability to organize entities in different tabs in the frontend. See the demo to see this in action and read more in the group documentation how to get started.
Example of the new views in the frontend. Learn more.
/5
) (@kennedyshead)homeassistant
, switch
, light
and media_player
(@rmkraus)When people start using home automation, they always experience home control first: being able to control devices in new ways using a phone or computer. They believe the future is now and their app will be their remote for their lives. They only focus on what they are getting, not on what they are losing. You install some light bulbs and all of a sudden you are no longer able to use the light switches. Youâll arrive at home at night and have to pull out your phone, open the app, let it connect and finally youâll be able to turn on the light. All while turning the light on could have been a switch away.
Yes, you can solve this with presence detection. What if your phone runs out of battery? Youâll have to resort to the switch again.
If you find that using your new home devices is cumbersome, the promise of home automation technology has failed you. Your lights should work with both a switch (or button) at the entrance of your room and via presence detection. Honestly, there are hardly any valid use cases for being able to control lights from your phone except for showing off.
People tend to forget that they are not the only ones in their home. As the developer of your house youâre enthusiastic about the possibilities and are willing to overlook flaws. Chances are very high that the other people in your household have different hobbies and just want to mind their own business.
This means that everything you automate has to work flawlessly. If you successfully manage to cause a response to some stimulus 90% of the time, youâre going to have a disproportionately poor experience 10% of the time. A common automation that fits this pattern is to fade the lights when you start watching a movie or series in the living room. It only works if everyone is watching.
With every automation, you always have to think: what will be the impact if it doesnât work? Home automation is composed of many different systems by many different vendors that speak many different protocols: things will go wrong. Itâs up to you to make sure that they have a limited impact when they fail. Ideally, devices should fall back to a pre-smart home experience. A Philips Hue bulb will act like a standard white light if turned on/off using a normal switch or when not connected to a hub. If things get worse when your system is out of order, your users will revolt. Take for example the Nest thermostat that had a bug in the beginning of January which caused it to stop heating the house, yikes!
Home automation should blend with your current workflow, not replace it. For most devices, there is no faster way to control most devices than how you are already doing it today. Most of the time, the best app is no app. The only interface that can be more convenient, and is accessible for visitors of your home of all ages is a voice interface. The industry has realized this too and there are some major players focussing on voice interaction. Take Apple for example: the only way to control your HomeKit devices is with Siri. Amazon has taken it one step further with the Amazon Echo, providing an always-listening connected speaker/microphone for the living room. I expect a lot more companies to join this segment in 2016.
Voice interfaces are not perfect either. The speed at which you can issue commands is low because you have to wait for a response. There are also issues with the discoverability of commands, recognition of accents and dependency on the cloud for processing your voice. I believe that all but the first one are problems that are going to be solved eventually.
This however doesnât mean there isnât a place for apps, there definitely is. They are perfectly well-suited for checking in while youâre away, browsing the state changes of your house or making the lights go all funky when there are kids visiting.
The cloud is a magical thing. Somewhere in the world there are computers collecting the data that your house generates, testing them against your automation rules and sending commands back when needed. The cloud will receive updates and improve itself over time so it is able to serve you better. Until itâs not. There are many reasons why your home might lose its connection to the cloud. The internet can stop working, an update might have gone wrong or the servers running the cloud crash.
When this happens, your house should be able to keep functioning. The cloud should be treated as an extension to your smart home instead of running it. That way youâll avoid awkward situations like when Amazon AWS was down and the Amazon Echo stopped working.
Good home automation never annoys but is missed when it is not working.
Thanks to Chris LaRose for this feedback and comments.
]]>is_state_attr(entity_id, name, value)
added (@andythigpen)binary_sensor
component.This release introduces templates. This will allow you to parse data before it gets processed or create messages for notifications on the fly based on data within Home Assistant. The notification component and the new Alexa/Amazon Echo component are both using the new template functionality to render responses. A template editor has been added to the developer tool section in the app so you can get instant feedback if your templates are working or not.
The temperature at home is {{ states('sensor.temperature') }}.
More information and examples can be found in the template documentation.
Templates will now be the only way to extract data from ârawâ sources like REST, CommandSensor or MQTT. This will replace any specific option that used to do this before. This means that precision
, factor
, attribute
or json_path
etc will no longer work.
Affected components and platforms:
This tutorial will take you through the steps to setup a dynamic DNS for your IP and allow trusted encrypted connection to it - for free using DuckDNS and Letâs Encrypt.
The DuckDNS part of this tutorial has no requirements but there are a few requirements as of now to run the Letâs Encrypt client.
The first step is to set up DuckDNS. This is a free dynamic DNS service that you can use to get a DuckDNS.org subdomain to point at your house. A dynamic DNS service works by having your home computer tell DuckDNS.org every 5 minutes what its IP is so that DuckDNS can make sure your domain name is set up correctly.
For this example we will assume our domain is hass-example.duckdns.org.
First step is to acquire and set up our domain name. For this, go to DuckDNS, log in with any of the supported login providers and add a domain. After this check out their installation instructions to finish your installation of DuckDNS. If youâre on a Raspberry Pi, see âPiâ in the category âOperating Systemsâ.
Letâs Encrypt is a free, automated, and open certificate authority (CA). We will use this to acquire a certificate that can be used to encrypted our connection with Home Assistant.
Letâs Encrypt will give you a free 90-day certificate if you pass their domain validation challenge. Domains are validated by having certain data be accessible on your domain for Letâs Encrypt (they describe it better themselves).
Assuming that your home is behind a router, the first thing to do is to set up port forwarding from your router to your computer that will run Letâs Encrypt. For the Letâs Encrypt set up we need to temporary forward ports 80
(http connections) and 443
(https connections). This can be set up by accessing your router admin interface (Site with port forwarding instructions per router).
Now youâre ready to run Letâs Encrypt:
$ git clone https://github.com/letsencrypt/letsencrypt [âŠ] $ cd letsencrypt $ ./letsencrypt-auto certonly --email $ ./letsencrypt-auto certonly --email your@email.address -d hass-example.duckdns.org Updating letsencrypt and virtual environment dependencies....... Running with virtualenv: sudo /path/letsencrypt/bin/letsencrypt certonly --email your@e-mail.address -d hass-example.duckdns.org IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/hass-example.duckdns.org/fullchain.pem. Your cert will expire on 2016-03-12. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - If like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
If youâre using Docker, run the following command to generate the required keys:
sudo mkdir /etc/letsencrypt /var/lib/letsencrypt sudo docker run -it --rm -p 443:443 -p 80:80 --name letsencrypt \ -v "/etc/letsencrypt:/etc/letsencrypt" \ -v "/var/lib/letsencrypt:/var/lib/letsencrypt" \ quay.io/letsencrypt/letsencrypt:latest certonly \ --email your@e-mail.address -d hass-example.duckdns.org
With either method your certificate will be generated and put in the directory /etc/letsencrypt/live/hass-example.duckdns.org
. As the lifetime is only 90 days, you will have to repeat this every 90 days.
Before updating the Home Assistant configuration, we have to update the port forwarding at your router config. We can drop the port forwarding for port 80
as we no longer care about unecrypted messages. Update port 443
to forward to port 8123
on the computer that will run Home Assistant.
The final step is to point Home Assistant at the generated certificates. Before you do this, make sure that the user running Home Assistant has read access to the folder that holds the certificates.
http: api_password: YOUR_SECRET_PASSWORD ssl_certificate: /etc/letsencrypt/live/hass.example.com/fullchain.pem ssl_key: /etc/letsencrypt/live/hass.example.com/privkey.pem
You can now navigate to https://hass-example.duckdns.org and enjoy encryption!
Big thanks to Fabian Affolter for his help and feedback on this article.
]]>
Philips Hue FAQ entries regarding reversing the decision.
Original post:
Philips Hue was one of the first to get smart lights accepted by the mainstream. Their Zigbee-based hub is rock solid, never crashes, great API and worked with other Zigbee light bulbs too. They are a bit expensive but the platform was worth every penny, till now.
Yesterday a thread on /r/homeautomation published that Philips Hue now blocks all but their own bulbs and those of âfriends of Hueâ. I have been able to confirm this in the Philips Hue FAQ (Update Dec 14: they have removed the entries - mirror here):
Philips Hue FAQ entries regarding 3rd party light bulbs.
This means that after you update your Hue bridge to the latest version:
If you own a Philips Hue hub and are using 3rd party light bulbs, make sure you do not upgrade your hub if you want to be able to pair new 3rd party lightbulbs. But do realize that you are sitting on a ticking time bomb.
I have read, but have been unable to confirm it, that resetting your hub will force a software upgrade. So beware of that too.
I will no longer suggest people to buy into the Philips Hue ecosystem.
]]>You could also do this with the automation component instead so whenever you put your house to sleep mode for example your Android device will open up Google Play Books or the Kindle app ready for you to read as well as dimming your lights, but this tutorial is all about the switches.
First things first you should install Tasker and AutoRemote onto your Android device and launch AutoRemote. You should see a URL above the QR code, visit it in your browser and it should bring up a page a bit like this.
Now type in SayOn
in the Message
box and you should see a box appear on the right with a URL in it, this is what we will be using in the Python script later on so save that for later. Do the same thing again but this time replace SayOn
with SayOff
. Now just click the Send message now!
button to test that your commands will get sent to your Android device, if they do you will see a toast message at the bottom of your screen like this one.
Open up Tasker and make sure youâre in the PROFILES
tab, then select the plus icon to create a new profile. Select Event
-> Plugin
-> AutoRemote
-> AutoRemote
and then the pencil icon to configure the AutoRemote event. Select Message Filter
and enter in SayOn
then go back until it asks you for a task. Select New task
then just leave the next field blank and select the tick icon.
This is where weâll configure our task, so select the plus icon to select an action. Select Alert
-> Say
to add a Say action. Enter On
in the text field and go back to test your task, make sure your media volume is up then select the play icon, you should hear your device say âOnâ.
Now you can go back to the main Tasker screen and create another profile but this time replace SayOn
with SayOff
and On
with Off
. After youâve done that go to the main screen again and select the menu button at the top then Exit
and Save first
to make sure everything is saved properly.
Now itâs time to set it up the script, so create a new Python script and name it On.py
then enter this code:
import requests requests.get('[URL]')
Enter in your âOnâ URL then save it. Create another script but this time call it Off.py
and enter your âoffâ URL instead.
Add a command line switch to your Home Assistant configuration:
switch: platform: command_switch switches: tasker_say: oncmd: python "[LocationOfOnScript]" offcmd: python "[LocationOfOffScript]"
Now load up Home Assistant and whenever you toggle the switch you created your Android device will respond with either âOnâ or âOffâ. :-)
]]>The influxdb
component makes it possible to transfer all state changes from Home Assistant to an external InfluxDB database.
The first step is to install the InfluxDB packages. If you are not running Fedora, check the installation section for further details.
$ sudo dnf -y install http://influxdb.s3.amazonaws.com/influxdb-0.9.5.1-1.x86_64.rpm
Launch the InfluxDB service.
$ sudo systemctl start influxdb
If everything went well, then the web interface of the database should be accessible at http://localhost:8083/. Create a database home_assistant
to use with Home Assistant either with the web interface or the commandline tool influx
.
InfluxDB web frontend
$ influx Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring. Connected to http://localhost:8086 version 0.9.5.1 InfluxDB shell 0.9.5.1 > CREATE DATABASE home_assistant
An optional step is to create a user. Keep in mind to adjust the configuration (add username
and password
) in the next step if you prefer to go this way.
> CREATE USER "home-assistant" WITH PASSWORD 'password'
To use the influxdb
component in your installation, add the following to your configuration.yaml
file:
influxdb: host: 127.0.0.1
After you restart Home Assistant you should see that the InfluxDB database gets filled. The language to query the database is similar to SQL.
$ influx [...] > USE home_assistant Using database home_assistant > SELECT * FROM binary_sensor name: binary_sensor ------------------- time domain entity_id value 1449496577000000000 binary_sensor bathroom_door 0 1449496577000000000 binary_sensor bathroom_window 0 1449496577000000000 binary_sensor basement_door 0 1449496577000000000 binary_sensor basement_window 0 1449496684000000000 binary_sensor bathroom_window 1 [...]
Grafana is a dashboard that can create graphs from different sources including InfluxDB. The installation is simple, and there are detailed steps for many different configurations on the Grafana installation page. For a recent system that is running Fedora:
$ sudo dnf -y install https://grafanarel.s3.amazonaws.com/builds/grafana-2.5.0-1.x86_64.rpm
Start the grafana server.
$ sudo systemctl daemon-reload $ sudo systemctl start grafana-server $ sudo systemctl status grafana-server
Login with the username admin
and the password admin
at http://localhost:3000/login. Now follow the InfluxDB setup instructions.
Now you can start to create dashboards and graphs. You have various options to get the data from the graph. The next image just shows a screenshot of the setting for a temperature sensor.
Grafana settings
If the graph is not showing up in the dashboard you need to adjust the time range in the right upper corner. The graph is created for all state changes recorded by Home Assistant.
Grafana Temperature graph
To update, run pip3 install --upgrade homeassistant
.
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!
]]>The idea was to anonymously collect some details about the usage of the different parts of Home Assistant and a little bit about the environment its running in.
Thanks to Python, users are running Home Assistant on the most popular Linux distributions and other operating systems including OS X and Microsoft Windows. One quarter of the operating systems are unknown which leads to the assumption that it is possible to run Home Assistant on most of the available operation systems today. We hope that *BSD users have fun too. The Hardware platform of choice seems to be x86_64 and ARM.
Of course most users are running with the automation component otherwise it would make much sense to use Home Assistant. The sun component is used a lot too. We hope that this is not because this component is enabled by default.
The Alarm control panels and the camera component are both used by around one third of the participants of the survey. Itâs safe to say that they cover a niche, but they will gain momentum when people discover how they can build alarm systems with Home Assistant.
Philips Hue is the âwinnerâ in the light category closely followed by MQTT lights. Google Cast and Plex are the top media player platforms. Pushbullet is by far the most-used notification platform. If you followed the recent efforts to improve this platform itâs comprehensible.
Itâs interesting to see that most of the sensor, switch, and thermostat platforms are used. A lot of people seem to be interested in the weather data provided by the Forecast sensor. The MQTT sensors and switches are deployed in almost 50% of all Home Assistant setups.
Home Assistant releases
Operating systems
Hardware platforms
Components
Alarm Control Panels and Cameras
Device trackers
Lights
Media players
Notifications
Sensors
Switches
Thermostats
The conclusion is that MQTT is popular in almost every section from Alarm Control Panel, presence detection with owntracks, sensors and switches, and now even for lights.
The interpretation of the data is up to you. Again, thanks for participating in this survey.
]]>mdi:
and stick it into your customize
section in configuration.yaml
:
homeassistant: customize: switch.ac: icon: 'mdi:air-conditioner'
customize
key in configuration.yaml
(@balloob)configuration.yaml
(@balloob)As part of this release we did some cleanup which introduced backwards incompatible changes:
Heat Control thermostat no longer includes scheduling features.
This feature has been removed completely. Use the automation component instead to control target temperature.
Config changed for calling a service from a script.
execute_service:
has been replaced with service:
. See component page for example. The old method will continue working for some time.
Scenes can no longer be turned off.
It is no longer possible to turn a scene off after it has been activated. The way it worked was unpredictable and causes a lot of confusion.
Downloader treats relative paths now relative to the config dir instead of the current working dir.
This makes more sense as most people run Home Assistant as a daemon
For this tutorial, Iâll walk through how to get going with ESP8266, get the temperature and humidity and report it to MQTT where Home Asssistant can pick it up.
Picture of the final setup (+ 2 LED for decoration)
Home Assistant will keep track of historical values and allow you to integrate it into automation.
Iâve been using Adafruit for my shopping:
Besides this, you will need the usual hardware prototype equipment: a breadboard, some wires, soldering iron + wire, Serial USB cable.
On your breadboard, make the following connections from your ESP8266 to the HDC1008:
ESP8266 | HDC1008 |
---|---|
GND | GND |
3V | Vin |
14 | SCL |
#2 | SDA |
I picked #2
and 14
myself, you can configure them in the sketch.
Follow these instructions on how to install and prepare the Arduino IDE for ESP8266 development.
After youâre done installing, open the Arduino IDE, in the menu click on sketch
-> include library
-> manage libraries
and install the following libraries:
If you have followed the previous steps, youâre all set.
File
-> New
)Tools
-> Serial Monitor
) to see the output from your deviceThis sketch will connect to your WiFi network and MQTT broker. It will read the temperature and humidity from the sensor every second. It will report it to the MQTT server if the difference is > 1 since last reported value. Reports to the MQTT broker are sent with retain set to True
. This means that anyone connecting to the MQTT topic will automatically be notified of the last reported value.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
#include <ESP8266WiFi.h> #include <Wire.h> #include <PubSubClient.h> #include <Adafruit_HDC1000.h> #define wifi_ssid "YOUR WIFI SSID" #define wifi_password "WIFI PASSWORD" #define mqtt_server "YOUR_MQTT_SERVER_HOST" #define mqtt_user "your_username" #define mqtt_password "your_password" #define humidity_topic "sensor/humidity" #define temperature_topic "sensor/temperature" WiFiClient espClient; PubSubClient client(espClient); Adafruit_HDC1000 hdc = Adafruit_HDC1000(); void setup() { Serial.begin(115200); setup_wifi(); client.setServer(mqtt_server, 1883); // Set SDA and SDL ports Wire.begin(2, 14); // Start sensor if (!hdc.begin()) { Serial.println("Couldn't find sensor!"); while (1); }} void setup_wifi() { delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(wifi_ssid); WiFi.begin(wifi_ssid, wifi_password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("Attempting MQTT connection..."); // Attempt to connect // If you do not want to use a username and password, change next line to // if (client.connect("ESP8266Client")) { if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) { Serial.println("connected"); } else { Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying delay(5000); } } } bool checkBound(float newValue, float prevValue, float maxDiff) { return newValue < prevValue - maxDiff || newValue > prevValue + maxDiff; } long lastMsg = 0; float temp = 0.0; float hum = 0.0; float diff = 1.0; void loop() { if (!client.connected()) { reconnect(); } client.loop(); long now = millis(); if (now - lastMsg > 1000) { lastMsg = now; float newTemp = hdc.readTemperature(); float newHum = hdc.readHumidity(); if (checkBound(newTemp, temp, diff)) { temp = newTemp; Serial.print("New temperature:"); Serial.println(String(temp).c_str()); client.publish(temperature_topic, String(temp).c_str(), true); } if (checkBound(newHum, hum, diff)) { hum = newHum; Serial.print("New humidity:"); Serial.println(String(hum).c_str()); client.publish(humidity_topic, String(hum).c_str(), true); } } } |
The last step is to integrate the sensor values into Home Assistant. This can be done by setting up Home Assistant to connect to the MQTT broker and subscribe to the sensor topics.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
mqtt: broker: YOUR_MQTT_SERVER_HOST username: your_username password: your_password sensor: platform: mqtt name: "Temperature" state_topic: "sensor/temperature" qos: 0 unit_of_measurement: "ÂșC" sensor 2: platform: mqtt name: "Humidity" state_topic: "sensor/humidity" qos: 0 unit_of_measurement: "%" |
This release also includes some new platforms (because they keep coming!):
Also, the media player was extended by @maddox to support the play media command. This has been implemented for the iTunes platform.
]]>We have added a new getting started section to get up and running.
Map in Home Assistant showing two people and three zones (home, school, work)
Ofcourse more things happened in the last three weeks. Iâm moving away from my usual long post to a short summary of highlights:
See GitHub for more detailed release notes.
Migration note: the scheduler
component has been removed in favor of the automation
component.
Sonos
Sonos support has been added by @rhooper and @SEJeff. Home Assistant is now able to automatically detect Sonos devices in your network and set them up for you. It will allow you to control music playing on your Sonos and change the volume.
iTunes and airplay speakers
@maddox has contributed support for controlling iTunes and airplay speakers. For this to work you will have to run itunes-api on your Mac as middleware.
# Example configuration.yaml entry media_player: platform: itunes name: iTunes host: http://192.168.1.50 port: 8181
Automation
Automation has gotten a lot of love. It now supports conditions, multiple triggers and new types of triggers. The best to get started with it is to head over to the new getting started with automation page.
# Example of entry in configuration.yaml automation: alias: Light on in the evening trigger: - platform: sun event: sunset offset: "-01:00:00" - platform: state entity_id: group.all_devices state: home condition: - platform: state entity_id: group.all_devices state: home - platform: time after: "16:00:00" before: "23:00:00" action: service: homeassistant.turn_on entity_id: group.living_room
Verisure Alarms
We now support arming and disarming your verisure alarm from within Home Assistant thanks to added support by @persandstrom.
The basic problem is to get the data from the remote host. Starting with psutil that is used by the systemmonitor sensor, a possible solution is only a click away and named Glances. Glances has a nice curses-based interface and a RESTful API.
The Glances sensor sensor uses that API to get all needed data.
In this post a default Fedora 22 Workstation installation is used on the host that should be monitored. In fact, it doesnât matter if the system is the local one or a remote one as long as Glances is available. With some adjustments it should work on your own systems too. The difference will be the package and the firewall management tools.
First some extra packages are needed beside Glances, especially the bottle webserver. I guess that Glances is available for your distribution as well. Otherwise follow those instructions.
$ sudo dnf -y install glances python-bottle
On Fedora the Firewall settings are strict. Letâs open port 61208 to allow other hosts to connect to that port. This is not needed if you just want to observe your local machine.
$ sudo firewall-cmd --permanent --add-port=61208/tcp $ sudo firewall-cmd --reload
Launch glances
and keep an eye on the output.
$ glances -w Glances web server started on http://0.0.0.0:61208/
Now browse to http://IP_ADRRESS:61208/. You should see the webified view of Glances.
Glances web interface
Another check is to access the API located at http://IP_ADRRESS:61208/api/2/mem/used and to confirm that a detail about your memory usage is provided as a JSON response. If so, you are good to proceed.
$ curl -X GET http://IP_ADDRESS:61208/api/2/mem/used {"used": 203943936}
Add the glances sensor entry to your configuration.yaml
file and restart Home Assistant then.
# Example configuration.yaml entry - platform: glances name: NAS host: IP_ADDRESS resources: - 'disk_use_percent' - 'disk_use' - 'disk_free'
If there are no error in the log file then you should see your new sensors.
The Glances sensors
Glances has a couple of optional dependencies which are extenting the range of provided information. This means that it would be possible to get details about the RAID system, HDD temperature, IP addresses, sensors, etc., please create a Pull request with your additions or a Feature request if you want see more details in your Home Assistant frontend.
]]>It is now possible to disable your irregation system if it is going to be cloudy tomorrow or tweet if your smoke alarm goes off.
Head over to the setup instructions to get started with IFTTT. Click the read more button for some example recipes.
In each of the following examples, make sure to replace the XXX in the url with your correct host address and api password.
Maker channel setup:
Field | Value |
---|---|
URL | http://xxx.xxx.xxx.xxx:8123/api/services/switch/turn_off?api_password=xxxxxxxx |
METHOD | POST |
CONTENT TYPE | application/json |
BODY | { âentity_idâ: âswitch.irrigationâ } |
This will tweet a message when an MQTT message is received that the smoke alarm has been triggered. Setup Maker channel with event name HA_FIRE_ALARM
and Twitter channel to tweet the message in value1
.
# Configuration.yaml entry automation: - alias: Post a tweet when fire alarm is triggered trigger: platform: mqtt mqtt_topic: home/alarm/fire mqtt_payload: 'on' action: service: ifttt.trigger data: {"event":"HA_FIRE_ALARM", "value1":"The fire alarm just triggered!"}
Maker channel setup:
Field | Value |
---|---|
URL | http://xxx.xxx.xxx.xxx:8123/api/services/light/turn_on?api_password=xxxxxxxx |
METHOD | POST |
CONTENT TYPE | application/json |
BODY | { âentity_idâ: âlight.kitchenâ } |
Maker channel setup:
Field | Value |
---|---|
URL | http://xxx.xxx.xxx.xxx:8123/api/services/light/turn_on?api_password=xxxxxxxx |
METHOD | POST |
CONTENT TYPE | application/json |
BODY | { âentity_idâ: âgroup.all_lightsâ, âflashâ:âyesâ } |
Maker channel setup:
Field | Value |
---|---|
URL | http://xxx.xxx.xxx.xxx:8123/api/events/do_button_pressed?api_password=xxxxxxxx |
METHOD | POST |
CONTENT TYPE | application/json |
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.
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 |
mqtt: broker: 127.0.0.1 sensor: - platform: mqtt name: "Fabian's Mood" state_topic: "home-assistant/fabian/mood" |
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
This is a really bad example. Donât do this in the real world because you wonât be able to create diagrams of historical data. Better use a numerical value.
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â and the unit of measurement will be âNo.â.
1 2 3 4 |
- platform: mqtt name: "Lottery" state_topic: "home-assistant/lottery/number" unit_of_measurement: "No." |
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.
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: "cd" |
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.
]]>