Create a model smart home in preparation for a real house.
Things used in this project
Hardware components
Hand tools and fabrication machines
Soldering iron (generic)
Story
This project is to put together some ideas for creating a smart home and test it on a model before an installation to a real house. The project has a temperature and Humidity sensor, a Display that shows inside and outside temp and the live price of Bitcoin, a PIR motion sensor, 2x button switches and 3 x LED lights (these indicate a 5v voltage that could be sent to a relay to operate any 230v device)
You will need to have Home Assistant already up and running first, there are guides in the link https://www.home-assistant.io/getting-started/
The next step is to wire all the components together, you can see the connections I made in the diagram below.
I then used a small box to put it all in.
Next step is to flash the Wemos with ESPHome and upload some code so that it can connect to Home Assistant.
In Home Assistant install ESPHome from the Addon Store. Open up the Web UI and click on the green + at the bottom right. Next name the board, mine's "bob5" and enter your wifi details for it to connect to. The WeMos is a ESP8266 so select that one. Next click on the three dots and select manual download, this will compile the code, save the file when ready mine's bob5.bin. Then plug the WeMos into your computer via USB, select the Serial port for that device and open the file (bob5.bin). Click Flash ESP and it will install the code onto the WeMos. Now your Home Assistant can connect to the Wemos.
Here is the link to ESPHome Flasher
Next click Edit and insert the YAML code for the board. Now that the device is connected to Home Assistant you can install the changes over wifi. Below is an example that you can use.
################### Display
i2c:
sda: 4
scl: 5
display:
platform: lcd_pcf8574
dimensions: 16x2
address: 0x27
id : mydisplay
lambda: |-
it.printf(0, 0, "$ %.0f", id(btc).state);
it.printf(0, 1, "%.1f'C", id(inside_temperature).state);
it.printf(10, 1, "%.1f'C", id(outside_temperature).state);
it.print(8, 0, "BTC =)");
########################### Temperature and Humidity sensor
sensor:
- platform: dht
pin: D0
temperature:
name: "Bedroom Temperature"
humidity:
name: "Bedroom Humidity"
update_interval: 30s
######################### Voltage sensor on default A0
- platform: adc
pin: VCC
name: "VCC Voltage"
######################################## Information feed for the display
- platform: homeassistant
id: inside_temperature
entity_id: sensor.bedroom_temperature
internal: true
- platform: homeassistant
id: outside_temperature
entity_id: sensor.bme280_temperature
internal: true
- platform: homeassistant
id: btc
entity_id: sensor.xbt_usd_ask
internal: true
############################################ LED lights
switch:
- platform: gpio
pin: D5
name: "LED Blue"
- platform: gpio
pin: D8
name: "LED Red"
- platform: gpio
pin: D3
name: "LED Yellow "
############################### Motion sensor that will turn on the display backlight for 90s when motion detected.
binary_sensor:
- platform: gpio
pin: D6
name: "eyeball"
device_class: motion
on_press:
then:
- binary_sensor.template.publish:
id: backlight
state: ON
- binary_sensor.template.publish:
id: backlight
state: OFF
- platform: template
id: backlight
filters:
- delayed_off: 90s
on_press:
then:
- lambda: |-
id(mydisplay).backlight();
on_release:
then:
- lambda: |-
id(mydisplay).no_backlight();
########################################## D4 has internal pullup for Switch 1
- platform: gpio
pin:
number: D4
mode: INPUT_PULLUP
inverted: True
name: "Switch 1"
device_class: light
filters:
- delayed_on: 50ms
############################################ D7 has internal pullup for Switch 2
- platform: gpio
pin:
number: D7
mode: INPUT_PULLUP
inverted: True
name: "Switch 2"
device_class: light
filters:
- delayed_on: 50ms
Now that we have the inputs and outputs connected to Home Assistant we can tell it to do things. The easiest way that I have found is to use Node-RED. Below is a simple example of Switch 1 toggling the Red LED on and off, Switch 2 toggling Blue LED on/off and the motion sensor (called 'eyeball') turning the Yellow LED on for 30s when motion is detected.
Schematics
house_model_bb_HKbSezOr9c.jpg
Code
Wemos board YAML example
YAML
################### Display
i2c:
sda: 4
scl: 5
display:
platform: lcd_pcf8574
dimensions: 16x2
address: 0x27
id : mydisplay
lambda: |-
it.printf(0, 0, "$ %.0f", id(btc).state);
it.printf(0, 1, "%.1f'C", id(inside_temperature).state);
it.printf(10, 1, "%.1f'C", id(outside_temperature).state);
it.print(8, 0, "BTC =)");
########################### Temperature and Humidity sensor
sensor:
- platform: dht
pin: D0
temperature:
name: "Bedroom Temperature"
humidity:
name: "Bedroom Humidity"
update_interval: 30s
######################### Voltage sensor on default A0
- platform: adc
pin: VCC
name: "VCC Voltage"
######################################## Information feed for the display
- platform: homeassistant
id: inside_temperature
entity_id: sensor.bedroom_temperature
internal: true
- platform: homeassistant
id: outside_temperature
entity_id: sensor.bme280_temperature
internal: true
- platform: homeassistant
id: btc
entity_id: sensor.xbt_usd_ask
internal: true
############################################ LED lights
switch:
- platform: gpio
pin: D5
name: "LED Blue"
- platform: gpio
pin: D8
name: "LED Red"
- platform: gpio
pin: D3
name: "LED Yellow "
############################### Motion sensor that will turn on the display backlight for 90s when motion detected.
binary_sensor:
- platform: gpio
pin: D6
name: "eyeball"
device_class: motion
on_press:
then:
- binary_sensor.template.publish:
id: backlight
state: ON
- binary_sensor.template.publish:
id: backlight
state: OFF
- platform: template
id: backlight
filters:
- delayed_off: 90s
on_press:
then:
- lambda: |-
id(mydisplay).backlight();
on_release:
then:
- lambda: |-
id(mydisplay).no_backlight();
########################################## D4 has internal pullup for Switch 1
- platform: gpio
pin:
number: D4
mode: INPUT_PULLUP
inverted: True
name: "Switch 1"
device_class: light
filters:
- delayed_on: 50ms
############################################ D7 has internal pullup for Switch 2
- platform: gpio
pin:
number: D7
mode: INPUT_PULLUP
inverted: True
name: "Switch 2"
device_class: light
filters:
- delayed_on: 50ms