Creating a alarm clock

how can I achieve this?

I’m trying to update to use input_datetime instead, but last night my sunrise alarm went off at midnight so needs a little more work!

1 Like

Used/modified some of the approaches here to trigger a sunrise as my alarm!

1 Like

I have tried to follow your instructions how to create the alarmclock but it looks different. I have removed the input_booleans.
How can I get everything combined and also not showing the badge and not showing “automations” and "input number)?
Mine:


Yours:
333

Put them in a group.

i have done that in my group yaml. They are just shown under the same tab in the frontend and the sensor is shown as a badge.

  exterior_light:
    name: Exterior light
    view: true
    entities:
      - automation.udvendig_lys_on_hverdage
      - sensor.udv_lys_time
      - input_number.udv_lys_hour
      - input_number.udv_lys_minutes

Should be

view: no

Or remove the view line completely.

I erased the “view” line and now it looks fine in the frontend :slight_smile:
However I would like this look on its own tab in the top of the frontend,

So create a group that is a view, and put the group you just created in it :wink:

Works :wink:
I guess it is not possible to remove it from the home tab and only have it shown on its own tab?

Only if you create your own default view.

I thought so.
Thanks for helping :-):+1:

2 Likes

Hi,

Based on this post Phillips Hue Wakeup Light with fade-in I’ve made several adjustments to work with my lights (as only Hue and Lifx platforms accept transition).

I use MiLight but served by a NodeMCU running this project https://github.com/sidoh/esp8266_milight_hub, not the ibox. Basically you can have as many groups as you want and loose the ibox. The performance is much better and on the gateway can be created as many lights and groups as you want (instead of buying an ibox for each group of four lights) thus limiting costs to a single NodeMCU and a NRF24L01.

The scripts for fade-in should work on any light platform that can be dimmed.

Apart from transition I’ve made an input select (not limiting thus to a single light). There is a light named light.all_lights which is a group, however not in HA but a group made in MiLight gateway (as turning a group of lights in HA would set them individually). Also, there are input numbers for maximum brightness and transition time in seconds (this is only intermediary as, depending on the the total time for the fade-in, this would be adjusted to hurry-up or slow-down the transitions due to the fact that brightness can be served to bulbs only as integer).

When using with MiLight (probably also with other platforms) an automation should set the brightness to 1 before the alarm is set during the evening (after: sunset) / night (before: sunrise) as otherwise the light would start at the last known brightness level. Setting the brightness to 1 when the light turn all time has the disadvantage of flickering but using the input boolean “Enable wakeup light” as condition this can be limited only to the last hour/hours before sleep (this is not covered here).

My configuration is split into individual folders for each component so indentation needs to be amended if using a single configuration file (although I strongly advise splitting it).

#1. Automation
- alias: 'Wakeup Light'
  trigger:
    platform: template
    value_template: '{{ states.sensor.time.state == states.sensor.wakeup_start_time_lights.state }}'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.wakeup
        state: 'on'
      - condition: or
        conditions:
          - condition: state
            entity_id: input_boolean.wakeup_weekends
            state: 'on'
          - condition: time
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
  action:
    - service: script.wakeup_room

#2. Sensors
- platform: template
  sensors:
    wakeup_alarm_time:
      friendly_name: 'Alarm time'
      value_template: '{% if states.input_number.wakeup_hour.state|length == 3 %}0{% endif %}{{ states.input_number.wakeup_hour.state | int }}:{% if states.input_number.wakeup_minutes.state|length == 3 %}0{% endif %}{{ states.input_number.wakeup_minutes.state | int }}'
- platform: template
  sensors:
    wakeup_fadein_duration:
      friendly_name: 'Fade-in duration'
      value_template: '{{ states.input_number.wakeup_duration.state | int }}'
      unit_of_measurement: 'min'
- platform: template
  sensors:
    wakeup_start_time_lights:
      friendly_name: 'Fade-in start time'
      value_template: >
        {% if states.sensor.wakeup_alarm_time and states.input_number.wakeup_duration %}
        {% set alarmtime = states.sensor.wakeup_alarm_time.state %}
        {% set alarm_hour = alarmtime.split(":")[0] | int %}
        {% set alarm_min = alarmtime.split(":")[1] | int %}
        {% set light_dur = states.input_number.wakeup_duration.state | int %}
        {% set alarm_min_light = alarm_min - light_dur %}
        {% if alarm_min_light  < 0 %}
        {% set alarm_min_light = alarm_min_light + 60 %}
        {% set alarm_hour_light = alarm_hour - 1 %}
        {% if alarm_hour_light < 0 %}{% set alarm_hour_light = 23 %}{% endif %}
        {% if alarm_hour_light < 10 %}0{% endif %}{{ alarm_hour_light}}:{% if alarm_min_light < 10 %}0{% endif %}{{ alarm_min_light }}
        {% else %}
        {% if alarm_hour < 10 %}0{% endif %}{{ alarm_hour }}:{% if alarm_min_light < 10 %}0{% endif %}{{ alarm_min_light }}
        {% endif %}
        {% endif %}
#replace with own light ids
- platform: template
  sensors:
    wakeup_light_current_brightness:
      friendly_name: 'Light brightness'
      value_template: >
        {% if is_state('input_select.wakeup_light_id', 'light.light1') %}
          {{states.light.light1.attributes.brightness | int}}
        {% elif is_state('input_select.wakeup_light_id', 'light.light2') %}
          {{states.light.light2.attributes.brightness | int}}
        {% elif is_state('input_select.wakeup_light_id', 'light.light3') %}
          {{states.light.light3.attributes.brightness | int}}
#add the other lights
        {% else %}
          0
        {% endif %}
- platform: template
  sensors:
    wakeup_adjusted_transition:
      friendly_name: 'Adjusted transition'
      value_template: >
        {% if states.sensor.wakeup_light_current_brightness.state|int < ((((states.input_number.wakeup_max_brightness.state|int/(states.input_number.wakeup_max_brightness.state|int*states.input_number.transition.state|int/(states.input_number.wakeup_duration.state|int*60))|round)|round)*(states.input_number.transition.state | int + 1)) -states.input_number.wakeup_duration.state|int*60)*(((states.input_number.wakeup_max_brightness.state|int)*(states.input_number.transition.state | int))/(states.input_number.wakeup_duration.state | int * 60))|round %}
          {{states.input_number.transition.state|int-([states.input_number.transition.state|int-(states.input_number.wakeup_duration.state|int*60/(states.input_number.wakeup_max_brightness.state|int/((states.input_number.wakeup_max_brightness.state|int*states.input_number.transition.state|int/states.input_number.transition.state|int)|round)|round)|round),0]|max)}}
        {% else %}
          {{states.input_number.transition.state|int-([states.input_number.transition.state|int-(states.input_number.wakeup_duration.state|int*60/(states.input_number.wakeup_max_brightness.state|int/((states.input_number.wakeup_max_brightness.state|int*states.input_number.transition.state|int/states.input_number.transition.state|int)|round)|round)|round),0]|max) + 1}}
        {% endif %}

#3. input boolean
wakeup:
  name: 'Enable wakeup light'
  icon: mdi:power
  initial: off
wakeup_weekends:
  name: 'Wakeup weekends'
  icon: mdi:power
  initial: off

#4. input number
wakeup_hour:
  name: Hour
  icon: mdi:clock-in
  initial: 7
  min: 0
  max: 23
  step: 1
wakeup_minutes:
  name: Minutes
  icon: mdi:clock-in
  initial: 30
  min: 0
  max: 55
  step: 5
wakeup_duration:
  name: Light fade-in duration
  icon: mdi:clock-in
  initial: 20
  min: 5
  max: 60
  step: 5
wakeup_max_brightness:
  name: Maximmum brightness
  icon: mdi:white-balance-sunny
  initial: 225
  min: 15
  max: 255
  step: 17
transition:
  name: Transition in seconds
  icon: mdi:clock-in
  initial: 10
  min: 1
  max: 60
  step: 1

#5. input select
  wakeup_light_id:
    name: Light id
    options:
     - light.all_lights
     - light.light1
     - light.light2
     - light.light3
#add the other lights
    initial: light.light1
    icon: mdi:weather-sunset-up

#6. scripts
wakeup_room_initial:
  alias: 'Wakeup initial'
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: '{{ states.input_select.wakeup_light_id.state}}'
        brightness: 0
        rgb_color: [1,1,1]
wakeup_room_turnon:
  alias: 'Wakeup turnon'
  sequence:
    - service: script.turn_off
      entity_id: script.wakeup_room_iterate
    - service: light.turn_on
      data_template:
        entity_id: '{{ states.input_select.wakeup_light_id.state}}'
        brightness: '{{ states.sensor.wakeup_light_current_brightness.state|int + (((states.input_number.wakeup_max_brightness.state|int)*(states.input_number.transition.state | int))/(states.input_number.wakeup_duration.state | int * 60))|round }}'
        rgb_color: [1,1,1]
    - delay: '00:00:{{states.sensor.wakeup_adjusted_transition.state|int}}'
    - service: script.turn_on
      entity_id: script.wakeup_room_iterate
wakeup_room_iterate:
  alias: 'Wakeup iterate'
  sequence:
    - service: script.turn_off
      entity_id: script.wakeup_room_turnon
    - service_template: >
        {% if states.sensor.wakeup_light_current_brightness.state|int < states.input_number.wakeup_max_brightness.state|int %}
          script.turn_on
        {% else %}
          script.turn_off
        {% endif %}
      data:
        entity_id: script.wakeup_room_turnon
wakeup_room:
  alias: 'Wakeup'
  sequence:
    - service: script.turn_on
      entity_id: script.wakeup_room_initial
    - delay: '00:00:{{states.input_number.transition.state|int-([states.input_number.transition.state|int-(states.input_number.wakeup_duration.state|int*60/(states.input_number.wakeup_max_brightness.state|int/((states.input_number.wakeup_max_brightness.state|int*states.input_number.transition.state|int/states.input_number.transition.state|int)|round)|round)|round),0]|max)}}'
    - service: script.turn_on
      entity_id: script.wakeup_room_turnon
3 Likes

I finally got all my lights connected (combination zwave & wink/zigbee) and want a similar automation. I copied your example and modified for a few of my lights for testing but I do not understand all the configurables & scripts.

Would you mind explaining each?

1 Like

Hi @Corey_Johnson,

As long as it works and it doesn’t hide the remote or leaves dirty dishes, does it really matter? :slight_smile:

So here it is: in addition to the components set in the initial topic (based on Hue) I added the maximum brightness level as input number/slider (which could be lower than default of 255), then a sensor for current brightness of the light (used to compare against the target), input number/slider for transition (MiLight component doesn’t support transition however by setting the script to issue the light.turn_on command at a set time interval the same effect can be reached) and adjusted transition as a sensor (this is due to the fact that, in order to reach the target brightness in a specified amount of time, the transition interval should be in fraction of seconds, however the platform only supports rounded numbers; at a certain moment there is the need for hurry-up or slow-down the scripts as the default transition would not be sufficient).

I’ve started with the following script which would increase the brightness from 1 to 255 (actually I haven’t written 255 components but only one and then used Microsoft Excel to substitute the values from prior). Obviously there are a lot of problems with this (as I haven’t written each and every script component it wasn’t such a big issue to start with) because the file is large, the transition interval is fixed at 4 seconds and the end brightness is not adjustable. And for each room I should have created a different set of components (script, input number, sensor, etc).

wakeup_bedroom:
  alias: 'wakeup'
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: light.bedroom1
        brightness: 1
        rgb_color: [1, 1, 1]
    - delay:
        seconds: 4
    - service: light.turn_on
      data_template:
        entity_id: light.bedroom1
        brightness: 2
        rgb_color: [1, 1, 1]
    - delay:
        seconds: 4
    - service: light.turn_on
      data_template:
        entity_id: light.bedroom1
        brightness: 4
        rgb_color: [1, 1, 1]
    - delay:
        seconds: 4
    - service: light.turn_on
      data_template:
        entity_id: light.bedroom1
        brightness: 5
        rgb_color: [1, 1, 1]
... => there are a lot of intermediary items :slight_smile: 
    - delay:
        seconds: 4
    - service: light.turn_on
      data_template:
        entity_id: light.bedroom1
        brightness: 254
        rgb_color: [1, 1, 1]
    - delay:
        seconds: 4
    - service: light.turn_on
      data_template:
        entity_id: light.bedroom1
        brightness: 255
        rgb_color: [1, 1, 1]

The scripts can be definitely improved.

You can hide the last three scripts in the group.

2 Likes

How do I split this configuration into multiple files ? Thanks !

Do you want to split the whole thing in to one file, or split the various parts in to files?

Check the docs for packages and includes.

I want to easily be able to cut and paste this alarm clock project and change entities to suit my lights. I am lost as some of the automation have - and some such as scripts, input number don’t in the above example. I am using Notepad ++ and get frequently locked with invalid config for even simple changes. This is going to be a weekend project learning indents with yaml and such !!

Create a folder in your .homeassistant directory called packages.

In your configuration.yaml, under the homeassistant: bit (where you have your longitude and latitude set) , put packages: !include_dir_named packages/ (indented 2 spaces so it lines up with long, lat, timezone etc).

Then inside the packages folder create a new file called alarm_clock.yaml , and then copy and paste the whole thing into it. Go through and change the entity_id’s, save the file, restart HA, profit :+1:

(edit) - I don’t know why but the OP has added # marks before all the component declarations, so you’ll have to remove them and then check all the indentations too.

2 Likes

If it helps, I’ve got prepackaged alarm clocks in my config. The Bedroom one is the most intricate.

Triggers at alarm time (if we’re home), plays Free Radio (local radio) over the chromecast and (if it’s dark) fades up the lights. Also has a repeat boolean so you can set it for 5am tomorrow and it will go off at 5 every morning, or it will just go off tomorrow as a one off.

link removed

(note that the condition I use for the lights is based on a virtual ‘dark outside’ sensor in another package, but you could just use sunrise / sunset)

4 Likes