For a work assignment I really wanted to try out connecting an Arduino to a sensor and then, if the sensor value got too high, the Google Home would notify anyone in the room with some kind of warning.
I managed to do a test-setup as you probably have guessed, so here i’m just recording my findings.
While doing the push-notification I also added a small switch in home-assistant for turning the internal Arduino LED on and off. Its nothing more than a small demo to illustrate how that’s possible. This could be used for switching any kind of Arduino controlled device on and off.
Setting up the Arduino
Start out by connecting a simple sensor to the Arduino, then connect the Arduino to the computer via for example CP2102. See here for more information about how to connect the Arduino to your computer.
Furthermore you need to upload the “StandardFirmata” file to the Arduino. This can be found by installing the “firmata” library in the Arduino IDE and then opening the File -> Examples -> firmata -> StandardFirmata.
Install home-assistant on your computer and make sure your computer and the Google Home is on the same wifi-network. Follow the guide on: https://home-assistant.io/
The following can be run with or without the sudo depending on what you need.
Start up homeassistant by running:
- sudo -u homeassistant -H /srv/homeassistant/bin/hass
And when editing configuration file run this:
- sudo -u homeassistant vi /home/homeassistant/.homeassistant/configuration.yaml
Also, you need to allow homeassistant to access the usb:
- sudo usermod -a -G dialout homeassistant
Now configure home assistant by adding the following to the configuration file (usually in /home/homeassistant/.homeassistant/configuration.yaml):
# Text to speech tts: platform: google # Arduino arduino: port: /dev/ttyUSB0 # Build-in LED, switching it on and off switch: platform: arduino pins: 13: name: Arduino build-in LED # Temperature sensor connected to analog pin 1 on the Arduino sensor: platform: arduino pins: 1: name: Temperature # When temperature reading gets too high, notify me on my Google Home automation: alias: Temperature too high trigger: platform: numeric_state entity_id: sensor.Temperature # Whatever value you want based on the temperature sensor you chose above: 1000 action: service: media_player.play_media entity_id: media_player.kitchen data: media_content_id: http://static1.grsites.com/archive/sounds/misc/misc031.mp3 media_content_type: audio/mp3
Remember to change the arduino port (/dev/ttyUSB0) , the threshold (1000), the name of the media player (media_player.kitchen) and the file you want to push to the google home when the threshold is exceeded.
Now, after a restart, the home-assistant should detect your Arduino and create a view similar to this:
Switching the “Arduino build-in LED” will turn the internal LED of the Arduino on and off and Temperature too high is currently switched on because the Temperature reading is 1023.
That’s it for now… These are just notes. Obviously there are tons of improvements and additions that could be done here, but for now I just wanted to know if it was possible, based on a sensor value to push a notification to Google Home and how you switch an Arduino connected gadget on and off… and lord and behold, it works… 🙂