Ok, so here’s one of the automations that I think is pretty fun-- my neighbours might disagree though. This is how I use Home Assistant to automatically trigger a goal celebration whenever the Winnipeg Jets score!

So, this relies on the Goalfeed component that is in the 0.63 release of Home Assistant, which requires an account with goalfeed.ca (full disclosure, I wrote and operate this service and there's a $1.99/month subscription to cover server cost and external services etc). Once you’ve got the account and your credentials are in your configuration, Home Assistant will fire events every time an NHL or MLB team scores. These events can be used to trigger whatever automation you want.

Now, the way this component works is that it fires an event called ‘goal’ for every goal or run scored, the event has some event data that is included which basically just identifies which team scored. Ultimately, the automation is going to look like this:

- alias: 'Jets Goal'
  hide_entity: true
  trigger:
    platform: event
    event_type: goal
    event_data:
      team_name: "Winnipeg Jets"
  action:
  - delay: "00:00:{{ states.input_number.goalfeed.state | int }}"

This is a new automation in my set-up, but it’s one I’m pretty happy with, not only because I think it’s a pretty cool effect, but for me, it’s actually a real money-saver.

Here’s how I used Philips Hue and Home Assistant to build a natural coloured sunrise in my bedroom and save over $400/year--

How does this save me money?

I am addicted to snoozing on alarms in the morning.

In the mornings, I can either have a nice relaxing 30 minute walk into the office, or I can rush to the bus stop about 7 minutes away and catch an 10 minute bus. This choice getting left to be made by the sleepiest version of myself is no good-- sleepy Craig sucks. He’s a lazy piece of shit. He’d sell his first-born child for an extra 13 minutes of sleep in to morning (this is why we don’t have children).

Over time, taking the bus adds up. By a conservative estimate of the e-cash fare ($2.35, for now...), and saving 4 trips/week for 48 weeks, that’s $451.20 back in my pocket! Fuck yeah!

This automation has significantly cut down on how many times I hit snooze, and I also find that waking up is less jarring and I’m a lot less groggy as a result.

If you are a Home Assistant user and you have Philips Hue bulbs or some other coloured smart lighting system setup that supports transitions, I definitely recommend setting something like this up!

How does it work?

I’m going to assume that you’ve already got Home Assistant set up and working with your lights. If not, head over to homeassistant.io and give it a try. It’s really pretty easy to get up and running and the learning curve is not as steep as it looks, plus, there is a fantastic community that will provide you with support if you hit a snag.

Now, to implement this, we are going to be creating a Home Assistant script, which will be what run to create our sunrise effect, we’ll create a couple of entities to use in the front end so that we can easily configure when we want this to run, and then we’ll create the automation that will ultimate trigger the script at the desired time.

The script

If you’ve played around with Home Assistant a bit, you might have already got a few scripts set-up, or you might just have everything configured right in the actions of your automations. There are a couple of advantages to doing this sort of thing in a script-- the first is that scripts allow us to reuse the actions easily and then if we want to change the action, we only need to adjust it in one place. This is especially nice when we are building more involved multi-step actions like our sunrise.

Here’s what our sunrise script looks like-- It’s a long one, but I’ve got some comments there to give you an idea of what each block is doing and separated it into blocks for readability:

sunrise:
  sequence:
    # light 1 dark red to medium warm orange
    - service: homeassistant.turn_on
      data:
        entity_id: light.craigs_bedroom_lamp
        rgb_color: [98,19,0]
        brightness: 1
    - delay:
        seconds: 1.00
    - service: homeassistant.turn_on
      data:
        entity_id: light.craigs_bedroom_lamp
        rgb_color: [249,123,0]
        brightness: 103
        transition: 15
    - delay:
        seconds: 15.00

    # light 2 dark warm orange to medium warm orange
    - service: homeassistant.turn_on
      data:
        entity_id: light.jessicas_bedroom_lamp
        rgb_color: [249,123,0]
        brightness: 1
    - delay:
        seconds: 1.00
    - service: homeassistant.turn_on
      data:
        entity_id: light.jessicas_bedroom_lamp
        rgb_color: [249,123,0]
        brightness: 103
        transition: 15
    - delay:
        seconds: 15.00

    # group medium warm orange to full bright
    - service: homeassistant.turn_on
      data:
        entity_id: light.sunrise
        rgb_color: [255,178,67]
        brightness: 255
        transition: 30
    - delay:
        seconds: 30.00


    # turn one bulb overhead on lowest and fade to full brightness slowly
    - service: homeassistant.turn_on
      data:
        entity_id: light.bedroom_fan_1
        brightness: 1
    - delay:
        seconds: 1.00
    - service: homeassistant.turn_on
      data:
        entity_id: light.bedroom_fan_1
        brightness: 255
        transition: 60
    - delay:
        seconds: 60.00

    # turn on the second bulb overhead and fade to full brightness a bit faster
    - service: homeassistant.turn_on
      data:
        entity_id: light.bedroom_fan_2
        brightness: 1
    - delay:
        seconds: 1.00
    - service: homeassistant.turn_on
      data:
        entity_id: light.bedroom_fan_2
        brightness: 255
        transition: 30

    # no delay - also through put the corridor outside the room on
    - service: homeassistant.turn_on
      data:
        entity_id: light.upstairs_corridor
        brightness: 200
        transition: 5

There are a couple of things worth noting about this script. What makes this effect work well is the use of the light entities ‘transition’ attribute in combination with the ‘delay’ action in the script.

Typically, Home Assistant wants to perform actions quickly and then immediately move on to the next action. Normally, that’s exactly what we want, but in this case, it’s not. By setting the ‘transition’ in the data when we call the ‘homeassistant.turn_on’ service, we are telling Home Assistant how long it should take to transition from the lights current state to the new state. Now, we need Home Assistant to wait before performing the next step so we use the ‘delay’ action and set it to the same number as the number we have as our transition time.

I’ve played with the times and I found that for me, these are the durations that work best, but you can play with them to suit your preference.

The entities

Now, before we write our automation to trigger this, lets create some entities that we can use to configure this a bit easier.

I’ve got this set as two separate automations in my set-up. One for weekdays, and the other for weekends. This lets me have separate wake-up times that I don’t need to mess with too often.

Here’s the entities I’ve created:

input_boolean:
  weekday_sunrise:
  weekend_sunrise:

input_number:
  weekday_alarm_hour:
    name: Hour
    icon: mdi:timer
    min: 0
    max: 23
    step: 1
  weekday_alarm_minutes:
    name: Minutes
    icon: mdi:timer
    min: 0
    max: 59
    step: 5
  weekend_alarm_hour:
    name: Hour
    icon: mdi:timer
    min: 0
    max: 23
    step: 1
  weekend_alarm_minutes:
    name: Minutes
    icon: mdi:timer
    min: 0
    max: 59
    step: 5

sensor:
  - platform: template
    sensors:
      weekday_alarm_time:
        friendly_name: 'Time'
        value_template: '{{ "%02d:%02d" | format(states("input_number.weekday_alarm_hour") | int, states("input_number.weekday_alarm_minutes") | int) }}'
      weekend_alarm_time:
        friendly_name: 'Time'
        value_template: '{{ "%02d:%02d" | format(states("input_number.weekend_alarm_hour") | int, states("input_number.weekend_alarm_minutes") | int) }}'

Okay, whoa, whoa, whoa! What the fuck are those sensors? They look complicated.

Yeah, you can add those and not touch them, but if you want to know what they are doing, I’ll try to explain. If you don’t give a shit or already know, skip ahead

As you may or may not know, Home Assistant has support for a template engine called Jinja. This allows you to evaluate and manipulate data at execution. These sensors that we are creating here basically takes the data and instructions that we are giving it and evaluate it as the sensors state. This is a really powerful tool to have in your Home Assistant arsenal, and I’d highly recommend looking at the Home Assistant documentation and the Jinja documentation to get a better grasp on this.

I’ll try to breakdown this statement and what happens behind the scenes: