My Home Assistant configuration - lights, rollers, movement

I think I’ve come far enough that it makes sense to share my config files, you might get some use of out them.

Home Assistant Config

System

Goal of automation

I would like to automate the home to such a degree that everything just works and we understand our home completely without intervention. That includes understanding intentions and behaviour and adjusting to it. We are far from the end goal, but a pretty good way along at least. The bedroom is fully automated when it comes to lights, fan and rollers, we never have to manually adjust it anymore. The livingroom is rather close to perfectly automated.

My vision of an automated home is one that adapts to the inhabitants, not the other way around. The lights should be the right level for the actions taken and the time of day, the home should clean itself when nobody is around to hear the vacuum, rollers should be down when changing clothes or sleeping and up during the day. The lawn should be cut when children are not out to play. The car should be started, removed from the garage and warmed up when someone is ready to leave.

Somethings are still dreams or just too expensive to accomplish at the moment, such as a washer and dryer that loads, starts and unloads by themselves. Getting a little bit closer to the dream every month is my goal though. I usually build or automate at least a few things per month.

Automations

Alarm system

  • Say good night when alarm is turned on
  • Set bedroom lights to bright or low depending on time and close bedroom rollers
  • Play music in the kitchen when alarm is turned off from home mode

Fan automation

  • Turn on fan in bedroom and livingroom if the temperature is too high. Only if alarm is off or in home mode (bedroom).
  • Turn off fans if temperature is lower again

Stairs

  • Turn on lights in stairs (leds under each step) when movement in upper or lower hallway and sun is down
  • Turn off lights in stairs when no movement for 3 minutes
  • Turn on light when sun goes down
  • Turn off light when sun rises

Dining room

  • Turn on light in cabinets if movement
  • Turn off light in cabinets if no movement for 10 minutes
  • Turn on aquarium in the morning and turn off in the evening

Kitchen

  • Turn on light (led strip) over cabinets if movement. Will be complemented with strips under cabinets as well. Turn off if no movement for 10 minutes
  • Turn on kitchen over cabinet lights when sun goes down

Livingroom

  • Turn on ceiling light and wall light if movement and sun is down
  • Turn off ceiling light and wall light if no movement for 10 minutes
  • Turn on lights/turn off lights and set brightness if Xiaomi double wall switch is pressed single or double
  • Turn on or off ceiling fan if both buttons on Xiaomi double wall switch is pressed twice
  • Turn on or off tv bench if both buttons on Xiaomi double wall switch is pressed once
  • Set Livingroom to tv mode if something is playing on the Apple TV
  • Turn on lights if door is opened and it’s dark
  • Turn on lights a bit before sun goes down or illumination is too low

Mailbox

  • Turn on light inside when hatch is opened and increase number of deposits by one, turn off light when closed
  • Turn on light inside when door is opened and set number of deposits to zero, turn off light when closed
  • Turn on light outside when it’s evening and turn off when it’s morning
  • Notify in app and email when mail arrives, also via TTS

Plants

  • Water plants if humidity is too low automatically
    TODO: set up individual watering, possibly with automatic adding of nutrition to water when nutrition is too low

Bedroom

  • Turn on light if movement, alarm is off and the light is not on already
  • Morning TTS played over Chromecast when button is pressed or bedside light is turned on in the morning (automated via alarm on phone). This contains traffic, weather, time and so on.
  • Turn off lights gradually in the evening and then turn off completely

Outside

  • Turn on entrace lights on sunset, movement, door bell ring or door open
  • Turn on driveway light on sunset and turn off on sun rise

Movement

  • Notify (TTS and app) if I leave work with travel time
  • Notify (TTS and app) if I stopped at one of the most common stores we shop at. My wife or kids can add things to shopping list via Echo Dot
  • Notify (TTS and app) if my daughter arrives at or leaves school
  • Turn on driveway light if I get close, then turn off a while after I get home

Other

  • Counters for TV time per unit, in hours per day
  • In bed sensor using Bayesian sensor
  • Mouse sensors with notifications

Edits

  • Ordered a Dell R710 server with 72 GB RAM, 2 four core CPU and initially 1 TB HD (will expand, have room for 8 2.5" drives, planning on running RAID 10). This machine will run VMs for SMB share, my Ghost blog, Grafana + Influx, a network boot server, probably Zoneminder for cameras, Docker containers, a DB VM, Pi Hole, a log server (Splunk?), a monitoring system (Nagios?), and probably a lot more fun things. A bit of a home lab server. Will probably add more of these as time passes.
  • Building a Raspberry Pi 3 cluster. I have 3 Pis already and ordered two more. Will try out Docker Swarm. If it’s reliable enough, I will move HA to the swarm. Each Pi will boot from a USB stick, not SD cards, for longer life.
10 Likes

Hi,

your installation appears really complete !!!
I’ve got a question about the bayesian sensor that you are using: could you explain his role and how you’ve done ?

Thank you !!!

how did you connect that digo camera? I love your system, thats something like what I want mine to be like when I finish it.

I would also like to know what’s the use of the bayesian sensor, since you already got a movement sensor there. Is it to determine if you’re really in bed or just walking in that room?

I’m interested to know more about the Xiaomi gateway since it is pretty cheap. I’ve read that the gateway is using zigbee to control devices. If I want to integrate the gateway as a component into my home assistant, do I need to have a zigbee controller in my raspberry or is it working with wifi?
Thanks!

The xiaomi gateway connects to your Raspberry with wifi

Yes, it’s to make sure I’m actually in bed for the night, not just walking in the room. Then I can also detect that I’ve woken up in the morning.

The way I’ve done it, is just through this code:

- name: 'In bed sensor'
    platform: 'bayesian'
    prior: 0.25
    probability_threshold: 0.95
    observations:
      - entity_id: 'binary_sensor.motion_sensor_158d0001656600' # Livingroom movement
        prob_given_true: 0.4
        prob_given_false: 0.2
        platform: 'state'
        to_state: 'off'
      - entity_id: 'binary_sensor.motion_sensor_158d0001655fde' # Hallway movement
        prob_given_true: 0.4
        prob_given_false: 0.2
        platform: 'state'
        to_state: 'off'
      - entity_id: 'binary_sensor.motion_sensor_158d0001655ff2' # Diningroom movement
        prob_given_true: 0.4
        prob_given_false: 0.2
        platform: 'state'
        to_state: 'off'
      - entity_id: 'binary_sensor.motion_sensor_158d0001656584' # Kitchen movement
        prob_given_true: 0.4
        prob_given_false: 0.2
        platform: 'state'
        to_state: 'off'
      - entity_id: 'binary_sensor.bedroom_movement'             # Bedroom movement
        prob_given_true: 0.6
        platform: 'state'
        to_state: 'on'
      - entity_id: 'sensor.sun'
        prob_given_true: 0.7
        platform: 'state'
        to_state: 'below_horizon'
      - entity_id: 'alarm_control_panel.hemgatan_alarm'
        prob_given_true: 0.9
        platform: 'state'
        to_state: 'armed_home'

It’s pretty reliable as far as I can see.

1 Like

I use
input: rtsp://username:password@ip:554/onvif1
FFMPEG needs to be installed, it’s set up as an FFMPEG camera.

  • platform: ffmpeg
    input: !secret front_door_camera
    name: Front-door

As AfonsoFF wrote, The Xiaomi gateway use the local network to connect to the gateway.

xiaomi_aqara:
  discovery_retry: 5
  gateways:
    - mac: 34:CE:00:8C:1B:B1
      key: !secret xiaomi_key

my rpi3 is a bit weak for ffmpeg probably, will give it a try, thanks!

Hey @eiolos thanks for this amazing share.

I had a few questions before I buy the products you have.

  1. The Blitzwolf Vacuum: how good is it in cleaning, moving around and working with HA?

  2. Custom built rollers: have you got any images of it? And can it work with a vertical blind?

  3. Custom built mailbox automation : how have you connected it to the Internet and how is it powered? Can it work or be modified in/for a flat where the mailbox is on the lower ground?

Thanks a lot.

Thanks for the kind words @bachoo786!

  1. The Blitzwolf is ok, works decent with HA. But I will replace it with a Xiaomi Vacuum and move the Blitzwolf to the upper floor. That seems like a much better product and easier to get into HA. It cleans pretty good though, just not as smart as the Xiaomi.
  2. The rollers, I’ll see if I can take some pics. But it’s basically just a continuous rotation servo that gets input from an ESP8266/NodeMCU. You can see the code for it at https://github.com/AndreasAhrens/D1-boards/tree/master/D1_Covers_Buttons_IR_DHT. Should be able to get it to work with vertical blinds as well in some way, but I haven’t tried it.
  3. Code available for the mailbox at https://github.com/AndreasAhrens/Mailbox-Automation. I’m sure you can adapt it to an apartment, but if the mailbox is on the lower ground that might be harder. It’s using WiFi from a NodeMCU so depending on how far it is from your apartment, it might not have coverage. I have it powered with a 12v cable that I dug down in a plastic pipe from the house to the mailbox. Works well. For the LED strips, continuous power is needed for sure, but if you just want the detection, you could probably use a smaller ESP-01 or something. I think if you use a NO magnet and connect it to the reset pin, you can just run a script that connects to WiFi, connect to MQTT and transmit message (use Last Will and Testament to get persistent status if you reboot HA) and then enter deep sleep. That way, you should be able to operate it on a battery, possibly even a coin cell.
1 Like

Thanks @eiolos How have you connected the Blitzwolf to HA?

Also you can run pfSense on your server and replace your router pfsense has an option to point to a network boot server so DHCP clients can see it. You can also setup VLANS to keep all of your home automation gear secure and organized with static leases. This is what I plan to do when I get my server in a few days.

Hi, very good, can you explain me a little bit More about your roller blinds?it’s a 360 rotation servo?what model?can i stop The courtains in any position? How do you installed?what values do i need to change in The code?sorry for all The questions i want to build this