Model House (Home Assistant)

by mpg28 in Circuits > Wireless

672 Views, 0 Favorites, 0 Comments

Model House (Home Assistant)

IMG_4999.jpg

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 temps 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/

Supplies

Hardware:

  • Wemos D1 Mini
  • PIR Motion Sensor
  • DHT11 Temperature and Humidity sensor
  • I2C 16x2 LCD Display
  • LED Red, Blue, Yellow
  • 330 ohm resistors x 3
  • Pushbutton switch x 2

Software:

House Model_bb.jpg
IMG_4998.jpg

The first step is to wire all the components together, you can see the connections I made in the diagram.

IMG_4841.jpg
IMG_4999.jpg

I then used a small box to put it all in.

Screenshot 2021-11-09 163902.jpg
Screenshot 2021-11-09 164012.jpg
Screenshot 2021-11-09 164113.jpg
Screenshot 2021-11-09 164218.jpg
Screenshot 2021-11-09 164316.jpg
Screenshot 2021-11-09 164421.jpg
Screenshot 2021-11-09 164530.jpg
Screenshot 2021-11-09 164941.jpg
Screenshot 2021-11-09 165141.jpg

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

Screenshot 2021-11-09 171102.jpg
Screenshot 2021-11-09 170703.jpg
Screenshot 2021-11-09 170725.jpg

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.

################### Displayi2c:  sda: 4  scl: 5display:    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 sensorsensor:  - 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

.

Capture.JPG

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.