Another thing I’d like HA to do would be to slowly turn the lights on in the bedroom when I need to get up. I could tie it into my phone alarm, but for now I’ll use voice control as it’s fairly easy. This can be done a few ways:

Automations:

For automations, we need a trigger and an action. I don’t want a conventional trigger, but we need to include one or HA won’t load the automation. For the trigger, I made a input_boolean in the configuration.yaml file:

input_boolean:
  morning_light_automation:
    initial: off

And then used that as a trigger in my automation.yaml file:

- id: morning_bedroom
  alias: "Morning Lights On"
  trigger:
    platform: state
    entity_id: input_boolean.morning_light_automation
  action:
  - service: light.turn_on
    data:
      entity_id: light.kyles_lamp
      brightness_pct: 100
      color_temp: 250
      transition: 30
  - service: light.turn_on
    data:
      entity_id: light.mels_lamp
      brightness_pct: 100
      color_temp: 250
      transition: 30
  - delay: 00:00:30
  - service: switch.turn_on
    data:
      entity_id: switch.master_bedroom_switch

The trigger could technically be used, but at this point I just want to trigger this by triggering the automation itself. The action has two parts, one for each lamp in the bedroom. It’s going to turn each lamp to 100% brightness over a period of 30 seconds. After the 30 seconds are up, it also turns on the main bedroom light.

To trigger it, I set up an IFTTT applet. For more details, see this post, but the part relevant here is the action:

URL: …services/automation/trigger…

This is telling IFTTT to use the automation.trigger service. We’re triggering this automation rather than turning it on, turning on an automation really just means that automation is active. If you wanted your light to always be on, you would turn off the automation associated with this light.

Now when I wake up but I’m not quite ready to get out of bed, I can say “OK Google, good morning” and the lamps come on at their lowest setting and slowly increase to 100% brightness over the next 30 seconds. It also uses a cool light (color_temp: 250), as blue light helps you wake up.

Scripts:

Scripts and Automations are so closely related in HA that it’s hard to know when to use on over the other, or really what the differences are. The main difference is in how scripts are triggered. Remember when I said I needed to make a input_boolean to fill the trigger section of the automation? There’s no need to do this in a script, because the script is basically just the action component of the automation. Since I don’t want to manually trigger this automation, I should have made a script instead. Another difference that isn’t going to appear super relevant here is the ability to cancel scripts. If I used 10 minutes for this automation instead of 30 seconds, but then after 5 minutes I realized today was a holiday and I could go back to sleep. With an automation, too bad, that light is coming on in another 5 minutes unless you stop HA. With a script, you could cancel it and go back to sleep.

Converting the automation to a script is fairly easy. For now I’ll leave the automation alone and duplicate it as a script. then once it’s working I’ll go back and delete the automation.

Step 1 – Copy the automation from the automations.yaml file and paste it into the scripts.yaml file.

Step 2 – Make the following changes. Delete 5 lines (strike out) and add 2 (bold):

- id: morning_bedroom
morning_bedroom:
  alias: "Morning Lights On"
  trigger:
    platform: state
    entity_id: input_boolean.morning_light_automation
  action:
  sequence:
  - service: light.turn_on
    data:
      entity_id: light.kyles_lamp
      brightness_pct: 100
      color_temp: 250
      transition: 30
  - service: light.turn_on
    data:
      entity_id: light.mels_lamp
      brightness_pct: 100
      color_temp: 250
      transition: 30
  - delay: 00:00:30
  - service: switch.turn_on
    data:
      entity_id: switch.master_bedroom_switch

Step 3 – Just Kidding, that’s it.

Their syntax is identical except for the way they start a new component and “action” becomes “sequence”. Final result in case that was confusing:

morning_bedroom:
  alias: "Morning Lights On"
  sequence:
  - service: light.turn_on
    data:
      entity_id: light.kyles_lamp
      brightness_pct: 100
      color_temp: 250
      transition: 30
  - service: light.turn_on
    data:
      entity_id: light.mels_lamp
      brightness_pct: 100
      color_temp: 250
      transition: 30
  - delay: 00:00:30
  - service: switch.turn_on
    data:
      entity_id: switch.master_bedroom_switch

Now this works the exact same, but we need to change our IFTTT:

URL: …services/script/turn_on…

Body: {“entity_id”:”script.morning_bedroom”}

Now everything works the exact same as with our automation, but our code is shorter. I’ll go back and delete the input_boolean from the configuration.yaml and delete that whole automation, and we’re done.

This isn’t a horrible setup, but I’m not 100% happy with it and can’t figure out a way to make it much better even within the script. The main problem I have with it is that it starts the lights at a cool light, rather than transitioning them from a warm light like I expected them to. Next time I’m going to try to re-do this script in Python and see if I can make it behave how I want.

Leave a comment

Your email address will not be published. Required fields are marked *