Home Automation (part 3)

My current Home-Assistant setup

Currently my HA homepage looks like this:

ha-ui

Let's first go over the various parts of the UI, and how my setup is currently working befor diving into the configuration file details.

The web UI

  • At the top, we have the status of various sensors
    • Update notification
    • Sun status, useful sensor to automate things based on sunset/sunrise
    • Device tracker status: My wife's and my phone are both at home
    • Z-Wave embedded switch current power consumption
    • Current Weather
    • Speedtest: download, ping, upload
    • Z-Wave embedded switch power consumption sum: so we know since we started using HA the living room light consumed 5.62kWh
    • Transmisison torrent download and upload speed
  • Weblink section are custom links to whatever URL you want, here my transmission webui
  • Input Select shows a custom dropdown I created: Mode, I am using it to select the current working mode of my HA setup
    • Jour (day): when switching to it, switch off the living room light, no automation
    • Soir (evening): light set to a medium dimming level (90/255), media center playing will dim the light to 30/255 for better atmosphere
    • SoirĂ©e (party): As for soir setting, light 90/255, but no automation
    • Nuit (night): set living room light to very very low level (10/255)
  • Switch: as you may have guessed, that section list the switches that are not for light control
    • PC raton is a wake-on-lan switch to wake my computer up, unfortunately not working as the FreeBSD jail that runs HA won't let the WOL packet out...
  • Light: the switches to control lights, for dimming you can click on the name and get a slider to adjust level.
    • Lampadaire is my wall plug on which I plug a standing light
    • Salon is the living room wall switch controlled lights
  • Kodi: is my Openelec installation, my main media center
  • Ratoncast: is a chromecast, that we mainly use for netflix

By default there can be a lot of other things showing up, with pretty awful names, for example the Fibaro Z-Wave switch has various sensors and parameters, they all appear in there but you can rename them to friendly names and hide the unused ones in your configuration.

The Automation

I have only a few automation for now, but they are actually pretty handy, most of them are based on the custom Input Select.

  • At sunset - 2.5h set the mode to evening: That switch the living room on, and enable the media centers automation
  • At 1:30am switch the mode to night: light to minimum in living room and no automation based on media centers
  • At sunrise set the mode to day: switch off the living room if needed and no automation based on media centers

If the automation based on media centers is enable there is: when a media player starts playing dim the light when paused or stop, raise the light to its usual level

It may sound like I didn't setup much, but just that is actually really nice, we actually don't use the wall switch anymore, and only on a very few occasion change settings manually, it just works and we don't have to do anything, that's pretty awesome.

The configuration

Now for the ugly, if you just wanted to know what I did with HA quickly, that's about it, you can stop reading here :).

The configuration isn't very hard to understand, but it still does require a bit of fiddling and tweaking before getting things right.

Most of the components pages explains pretty well what to do and how to configure you devices. In addition there is the Examples or Cookbook page where you can find configuration from other people and snippets of automation for some commonly used cases, like dimming the lights when playing a movie.

The configuration is in YAML and can be splitted in multiple files using !include, I didn't do it myself yet, but will probably have to go this way if it gets any more complex than it currently is.

Basics

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 48.80569
  longitude: 2.130699
  # C for Celsius, F for Fahrenheit
  temperature_unit: C
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Paris

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend
#conversation:

# View all events in a logbook
logbook:

# Enables the frontend
frontend:

# Track the sun
sun:

# Prediction of weather
sensor:
   platform: yr

# Show links to resources in log and frontend
#introduction:

# Enables support for tracking state changes over time.
history:

# Checks for available updates
updater:

You give your setup a name, a location (to fetch sunrise/sunset), unit for temperature and your timezone.

Then in my case: enable discovery (that's how the chromecast is found), disable conversation: you can give voice command to HA from the webui, but I'm not a native english speaker, so I don't like talking to my phone in english, plus I do hope to do a better voice control system (always on) at some point. enable logbook, frontend, history and update checker enable sun tracking, based on location, that will create the sensor on top of the web UI and allow automation based on sunset and sunrise times * disable introduction: that is a nice to have at first when learning HA, but after that it mostly get annoying to me.

When using Z-Wave, you have to configure your dongle, as explained on the Z-Wave page:

zwave:
  usb_path: /dev/cuaU0
  config_path: /usr/local/lib/python3.4/site-packages/libopenzwave-0.3.1-py3.4-freebsd-10.3-RELEASE-amd64.egg/config
  polling_interval: 60000

Customization

As explained earlier, by default, all sensors, switches, and their various settings will show up once HA detects them, the annoying part is that can create a lot of clutter and be pretty ugly as the default names of some devices are pretty awful.

To solve this HA provides the customize: section, where you can hide some devices, and change the friendly_name too. In the configuration you will still have to reference the original name, but at least for the UI you'll get a nice name.

Note that this is a subsection of the homeassistant: section, this one would be a good candidate for the first !include in my configuration file.

  customize:
    sensor.fibaro_system_fgd212_dimmer_2_energy_3:
      friendly_name: Total Salon
    sensor.fibaro_system_fgd212_dimmer_2_power_3:
      friendly_name: Instant. Salon
    sensor.yr_symbol:
      friendly_name: Meteo
    sensor.everspring_ad147_plugin_dimmer_module_alarm_level_2:
      hidden: true
    sensor.everspring_ad147_plugin_dimmer_module_alarm_type_2:
      hidden: true
    sensor.everspring_ad147_plugin_dimmer_module_power_management_2:
      hidden: true
    sensor.everspring_ad147_plugin_dimmer_module_sourcenodeid_2:
      hidden: true
    sensor.fibaro_system_fgd212_dimmer_2_alarm_level_3:
      hidden: true
    sensor.fibaro_system_fgd212_dimmer_2_alarm_type_3:
      hidden: true
    sensor.fibaro_system_fgd212_dimmer_2_heat_3:
      hidden: true
    sensor.fibaro_system_fgd212_dimmer_2_power_management_3:
      hidden: true
    sensor.fibaro_system_fgd212_dimmer_2_sourcenodeid_3:
      hidden: true
    sensor.fibaro_system_fgd212_dimmer_2_system_3:
      hidden: true

    light.everspring_ad147_plugin_dimmer_module_level_2:
      friendly_name: Lampadaire
    light.fibaro_system_fgd212_dimmer_2_level_3:
      friendly_name: Salon
    light.fibaro_system_fgd212_dimmer_2_level_3_2:
      hidden: true
    light.fibaro_system_fgd212_dimmer_2_step_size_3:
      hidden: true
    light.fibaro_system_fgd212_dimmer_2_step_size_3_2:
      hidden: true

I don't think it is worth going over every part here, it is pretty clear, and definetily won't match anyone else setup, it is just here as a reference.

Sensors

Here I use the sensor word in as a generic term, I'll include quite a list of various things within it, first the device tracker: I currently don't use it but it can be a great way to automate things based on weither you're home or not.

device_tracker:
  platform: nmap_tracker
  hosts: 192.168.0.1/24
  home_interval: 10
  track_new_devices: no

There are other possibilities as you can see on the Presence Detection section of the components, one of the most popular being owntracks. But I went for a simple nmap on my local subnet, this will create a known_devices.yaml containing the list of the known hosts. As you can see I used the track_new_devices: no option, to avoid having any new device showing up, a friend who borrow your wifi for example etc, by default they will all show at the top of your homepage, that's why I used this option and the track: no option in known_devices.yaml file to limit to only tracking our two phones.

I also added speedtest to test our link speed periodically, and transimission to see if torrents are actually doing anything:

sensor 2:
  platform: speedtest
  minute: 30
  hour:
    - 0
    - 6
    - 12
    - 18
  monitored_conditions:
    - ping
    - download
    - upload

sensor 3:
  platform: transmission
  host: 192.168.0.2
  port: 9091
  monitored_variables:
    - 'download_speed'
    - 'upload_speed'

And that's it.

Media Players

The chromecast is automatically detected via the discover: module and there is no configuration entry related to it, except for the automation which is another part of this post.

So I only had to configure our Openelec media center, which is based on Kodi, which have its own component:

media_player:
  platform: kodi
  host: http://192.168.0.X
  port: 80
  name: Kodi

Custom Switches

I have 2 switches added manually in the configuration, the wake-on-lan for my computer:

switch 1:
  platform: wake_on_lan
  mac_address: "XX:XX:XX:XX:XX:XX"
  name: PC raton
  host: "192.168.0.X"

The host ip is used to check if it is up for the switch in the web UI.

The second one is the input select to choose mode:

input_select:
  current_mode:
    name: "Mode"
    options:
      - Jour
      - Soir
      - Soiree
      - Nuit
    initial: Jour
    icon: mdi:power-settings

It creates a current_mode device you can refer to in the automation, you simply list the options and the initial setting to use when restarting HA, I added an icon, but that's optional.

You can also add sliders or boolean input, they are listed in the Automation components page.

Weblinks

If like me you use HA as your browser homepage, it can be useful to add links to some often used website or services, this is where you can use the weblink component, I simply added my transmission url:

weblink:
  entities:
    - name: Torrents
      url: http://192.168.0.X:9091
      icon: mdi:download

Automation

That's it about the devices and sensors we can now dive into the automation, I'm not sure it is really worth to detail everything, it can help getting a grasp of how it works, but every setup will be different, and most Examples will cover this better than I'll be able to. So what I'll do is simply explain what part of the automation I'm talking about, and paste the configuration part related to it.

All the automation rules will reside in the automation: section (who whould have guessed?)

Mode Switching Events

So, most of my automation is based on the mode the setup is running at, and when switching from one to another changing the light accordingly.

Switching to day mode, turn off all the lights. Currently we only have 2 lights both in the living room, so it make sense to simply use the service light witouth parameter so it act on all the light:

  - alias: Jour
    trigger:
      - platform: state
        entity_id: input_select.current_mode
        state: "Jour"
    action:
      service: light.turn_off

Switching to evening or party mode, turn the living room above and behing tv to 90/255 setting, only difference is that the media playing automation won't trigger if mode isn't evening:

  - alias: Soir
    trigger:
      - platform: state
        entity_id: input_select.current_mode
        state: "Soir"
    action:
      service: light.turn_on
      data:
        entity_id: light.fibaro_system_fgd212_dimmer_2_level_3
        brightness: 90

  - alias: Soiree
    trigger:
      - platform: state
        entity_id: input_select.current_mode
        state: "Soiree"
    action:
      service: light.turn_on
      data:
        entity_id: light.fibaro_system_fgd212_dimmer_2_level_3
        brightness: 90

Switching to night mode, set the light to the lowest level, we generally leave it running overnight, at this level, the consumption is about 2W, which really isn't much:

  - alias: Nuit
    trigger:
      - platform: state
        entity_id: input_select.current_mode
        state: "Nuit"
    action:
      service: light.turn_on
      data:
        entity_id: light.fibaro_system_fgd212_dimmer_2_level_3
        brightness: 10

Mode Switching Triggers

To automate switching from one mode to another, we have 3 time triggers, one for the evening, starting 2.5 hours before sunset

  - alias: "evening time"
    trigger:
      - platform: sun
        event: sunset
        offset: "-02:30:00"
    action:
      service: input_select.select_option
      data:
        entity_id: input_select.current_mode
        option: "Soir"

One for the night, with a hard limit set at 1:30am:

  - alias: "night time"
    trigger:
      - platform: time
        hours: 1
        minutes: 30
        seconds: 0
    action:
      service: input_select.select_option
      data:
        entity_id: input_select.current_mode
        option: "Nuit"

And one to go back to daytime mode, using the sunrise time:

  - alias: "day time"
    trigger:
      - platform: sun
        event: sunrise
    action:
      service: input_select.select_option
      data:
        entity_id: input_select.current_mode
        option: "Jour"

Now we have the mode switching automatically, let's handle the dimming of lights when watching movies!

Media Playing

Now based of if we are in the evening mode or not, we want the media players to trigger dimming the light. I tried to add a check on the content type for kodi, to avoid the dimming when listening to music, but it apparently dosen't work, and I didn't find out why yet.

For kodi:

  - alias: "Kodi paused/stopped"
    trigger:
      - platform: state
        entity_id: media_player.kodi
        from: 'playing'
    condition:
      - condition: state
        entity_id: input_select.current_mode
        state: Soir
      - condition: template
        value_template: '{{ states.media_player.kodi.media_content_type != "video" }}'
    action:
      service: light.turn_on
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_3
      data:
        brightness: 90

  - alias: "Kodi playing"
    trigger:
      - platform: state
        entity_id: media_player.kodi
        to: 'playing'
    condition:
      - condition: state
        entity_id: input_select.current_mode
        state: Soir
      - condition: template
        value_template: '{{ states.media_player.kodi.media_content_type != "video" }}'
    action:
      service: light.turn_on
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_3
      data:
        brightness: 30

For chromecast:

  - alias: "chromecast paused/stopped"
    trigger:
      - platform: state
        entity_id: media_player.ratoncast
        from: 'playing'
    condition:
      - condition: state
        entity_id: input_select.current_mode
        state: Soir
    action:
      service: light.turn_on
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_3
      data:
        brightness: 90

  - alias: "chromecast playing"
    trigger:
      - platform: state
        entity_id: media_player.ratoncast
        to: 'playing'
    condition:
      - condition: state
        entity_id: input_select.current_mode
        state: Soir
    action:
      service: light.turn_on
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_3
      data:
        brightness: 30

Future

Currently one thing I would like to automate is running a script that would switch off the tv/amp when both media player have been idling for 30 minutes and if my wife computer isn't on.

For the light, I would like to replace the modes/timeslots in most cases except the night by a lux detection, and adjust brightness based on how much light there is in the living room.

I want to add other light in this room for other situation, I would love to have some sensors for temperature and humidity both inside and outside, automate the curtains too, and add some kind opened door/window detection too.

The possibilities are endless, only money, and ability in diy is the limits!

And that wraps it up for this serie of post on home automation, I'll try to keep posting the changes and hopefully my DIY sensors/controller based on ESP8266 in the near future.


31 juillet 2016 12:42:45 -- tags [ home-automation , home-assistant , light , dimming , configuration , yaml ]

0 Comments