Wake-up light alarm with sunrise effect

Sadly that doesn’t seem to work for templates in the trigger section (which was what I tried with in the first place actually). Result is an error in the log like:

homeassistant.exceptions.TemplateError: UndefinedError: 'timestamp_sensor' is undefined

I just remembered I have a non-color-temperature light in my attic. Used that to write down the necessary choose-blocks. Code has been updated. I also took the advice with the default: [] for the action-block. Seems to do just fine, thanks!

Well damn. I was SO sure that part of it (variables defined in a trigger template) that I didn’t even test it before suggesting it. Testing it now, it fails exactly as you’ve indicated. It’s likely an oversight and would be fixed with a bug report. But, I’m not sure.

I am getting this in my log, hopefully it will help track down the error @f4stb00t is seeing. I’m using it with a Tasmota RBGW LED strip:

Error while processing template: Template("{{ 0 < as_timestamp(states(timestamp_sensor)) - as_timestamp(states('sensor.date_time_iso')) < 60 * float(sunrise_duration) }}")
Error while processing template: {{ 0 < as_timestamp(states(timestamp_sensor)) - as_timestamp(states('sensor.date_time_iso')) < 60 * float(sunrise_duration) }}
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 353, in async_render
    render_result = compiled.render(kwargs)
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 462, in async_render_to_info
    render_info._result = self.async_render(variables, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 355, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

Does the blueprint get automatically updated? Or do I need to do it manually?

@PurelyNicole:
The issue above could be a missing date_time_iso sensor. Could you please check you added something like this to your configuration.yaml and have restarted HA?

sensor:
  - platform: time_date
    display_options:
      - 'date_time_iso'

@Deadpool:
Unfortunately not afaik. You can however simply delete the blueprint in the UI and readd it with the same URL and then reload automations. This should update existing automations based on the blueprint without needing to recreate them.

…I for some reason got it in my head that “date_time_iso” was part of the default config. Sorry about that.

Is it also possible to create a person at home away input? So when you set an alarm and you are not at home, it doesn’t trigger the wake up light.

And when I press execute automation, it doesn’t trigger the automation. But when I set the alarm on my phone app, it works the way it should.

The 5 minute offset is a bug in Samsung’s clock app. It was reported 2 years ago to Samsung, but never fixed. You can switch to any other app and it will not happen.

I have another issue with the latest version of this blueprint - the brightness goes to 100%, and instead of stopping there it jumps to 50% and continues to rise again, then it jumps again and doesn’t stop for whatever reason

Unfortunately I could not find the sensors#next-alarm-sensor in the iPhone companion app. It seems it is an Android only feature.
I am afraid there is no way to use the phone’s settings.
Is there any idea how to use the automation?

@Deadpool interesting idea. What you could do already is enable / disable the whole automation, i.e. make another automation that switches on / off the light alarm automation based on your home presence.
Also yeah you cannot launch this with the execute button since there are conditions within the actions depending on a timer.

@vlives thanks for the info on the Samsung bug. On the issue: do you have more details on the settings (duration, max_brightness) and the kind of lamp? Do you have other automations or integrations adjusting the target light like flux, circadian lighting or adaptive lighting?

@rlajos Sorry wasn’t aware of this limitation on Apple. I have described e.g. how to use an input_datetime in the original post. Personally at home I’m querying the alarm set by voice on a Google Home via a REST API. Not sure what is a useful approach here in your case.

I used a virtual group of 2 custom ESPHome lights, with 10 minutes sunrise duration and a 100% max brightness. No additional automations/integrations. I went back to my own script for now, I guess there is no point in changing things if it works :slight_smile:
Btw, thanks for working on this blueprint, I’m sure it will help a lot of people :smiley:

1 Like

Hi.

The new version is working with the ZHA group of the Iris Lamps! :slight_smile:

Some hints maybe for newcomers.

  1. You have to enable Customizations before you can see this options. Click bottom left on your user and enable advance mode
  2. If you want to change the Customizations you have to add the following to your configuration.yaml. Otherwise it will give you and error that its not loaded
homeassistant:
  customize: !include customize.yaml

Can anyone tell me please how I can set the timers in HA Core? Actually I have more than one timer on my mobile, this would lead to issues I guess. Like one alarm clock just to get wake and a second and third one just in case I fell asleep again. So I would like to set this in HA Core. I’ve added already a helper, but not sure how I can tell it to use the wake-up light from MO-FR at 07:00AM for example.

In addition it would be just awesome to have the possibility to change the colors if you have a light with colors like I do. At the moment it uses the last set color. In my case it was red. I would like to use this with white light. A bonus would be to set it back to the last color it had before.

Thanks a lot for this great work. I love it. Cant wait to wake up this way tomorrow :slight_smile:

With the latest update I added support for manual alarm times now if you are setting the sensor to ‘none’ whatever is set as manual alarm time is honored instead. I also added a small paragraph on how to define additional conditions for the alarm with a couple examples. It relies on Wait-actions that can be used in the custom pre-sunrise actions.

Btw. I noticed that setting device_class to timestamp on sensors via customizations is not strictly necessary. One can always input the sensor name manually and it is still accepted.

1 Like

When I set a manual time, I get the following template error:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/template.py", line 353, in async_render
    render_result = compiled.render(kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/srv/homeassistant/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/srv/homeassistant/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

The above exception was the direct cause of the following exception:


Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/template.py", line 462, in async_render_to_info
    render_info._result = self.async_render(variables, **kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/template.py", line 355, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
2020-12-17 20:46:51 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: {{ 0 < as_timestamp(states(timestamp_sensor) if timestamp_sensor != 'none' else now().year ~ '-' ~ now().month ~ '-' ~ now().day ~ ' ' ~ manual_time) - as_timestamp(states('sensor.date_time_iso')) < 60 * float(sunrise_duration) }}
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/template.py", line 353, in async_render
    render_result = compiled.render(kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/srv/homeassistant/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/srv/homeassistant/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

My second issue is I can’t get this to work with my Android alarm and my ZHA bulbs (Philips Hue or Yeelight Color 2)

I’ve have my sensor.pixel_3a_next_alarm updating and working correctly.

I’ve added this to my configuration.yaml:

sensor:
  - platform: time_date
    display_options:
      - 'date_time_iso'
      - 'date'

and I have the latest version of your blueprint.

I set sunrise time to 5 minutes and set my alarm to less than 5 minutes from now, and nothing happens with my lights, and no errors are logged. Any help would be hot?

Thanks, @Sbyx, for an awesome blueprint and continued work in it! I m excited to move away from my custom sketchy automation to something more robust :boom:

Just an idea, perhaps you can add “weekdays only” for manual alarm entry and another toggle for “weekends”, because for iPhone users who would choose to manually set the alarm that could be helpful.
I ll look at implementing your idea to shoot an API call fetching alarm times from google home api. Do you have any suggestion where to start?

1 Like

Thanks for the feedback @Ilja_Leiko You can already select by weekday via the pre-sunrise actions. Just add a wait-action at the top with the following contents:

    pre_sunrise_actions:
      - wait_template: '{{ 1 <= now().isoweekday() <= 5 }}'

Alternatively you can use other conditions like a workday sensor and / or combine with presence etc.
I put some examples and how to set them up via the UI in the original post at the top.

On the Google Home thing it is a bit complicated since you need an external script that feeds authentication tokens into HA so it probably won’t work with just Home Assistant OS. I found a Github Repo describing it here: https://github.com/chvancooten/homeassistant-googletokenretriever

@sidequestboy for some reason it seems your manual time cannot be parsed correctly. Could you please send me the YAML block of your automation based on the blueprint (in UI use the 3 dots menui and choose ‘edit as YAML’ and copy the contents)?

1 Like

Sorry, it’s possible that error was with an older version of your blueprint. Right now I get a different error when setting a manual time. My lights do successfully get set to 1% it seems, but then do not fade. The log shows:

2020-12-18 07:19:07 ERROR (MainThread) [homeassistant.components.automation.new_automation] Wake up lights: Repeat at step 5: Choose at step 2: choice 1: Choose at step 1: choice 1: Error executing script. Invalid data for call_service at pos 1: value must be at most 100 for dictionary value @ data['brightness_pct']
2020-12-18 07:19:07 ERROR (MainThread) [homeassistant.components.automation.new_automation] Wake up lights: Repeat at step 5: Choose at step 2: choice 1: Error executing script. Invalid data for choose at pos 1: value must be at most 100 for dictionary value @ data['brightness_pct']
2020-12-18 07:19:07 ERROR (MainThread) [homeassistant.components.automation.new_automation] Wake up lights: Repeat at step 5: Error executing script. Invalid data for choose at pos 2: value must be at most 100 for dictionary value @ data['brightness_pct']
2020-12-18 07:19:07 ERROR (MainThread) [homeassistant.components.automation.new_automation] Wake up lights: Error executing script. Invalid data for repeat at pos 5: value must be at most 100 for dictionary value @ data['brightness_pct']
2020-12-18 07:19:07 ERROR (MainThread) [homeassistant.components.automation.new_automation] While executing automation automation.new_automation
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/automation/__init__.py", line 404, in async_trigger
    await self.action_script.async_run(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 570, in _async_repeat_step
    await async_run_sequence(iteration)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 538, in async_run_sequence
    await self._async_run_script(script)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 670, in _async_run_script
    await self._async_run_long_action(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 419, in _async_run_long_action
    long_task.result()
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 596, in _async_choose_step
    await self._async_run_script(script)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 670, in _async_run_script
    await self._async_run_long_action(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 419, in _async_run_long_action
    long_task.result()
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 596, in _async_choose_step
    await self._async_run_script(script)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 670, in _async_run_script
    await self._async_run_long_action(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 419, in _async_run_long_action
    long_task.result()
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 1026, in async_run
    await asyncio.shield(run.async_run())
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 242, in async_run
    await self._async_step(log_exceptions=False)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 250, in _async_step
    await getattr(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/script.py", line 457, in _async_call_service_step
    await service_task
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/core.py", line 1399, in async_call
    processed_data = handler.schema(service_data)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/validators.py", line 218, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/validators.py", line 340, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/validators.py", line 336, in _exec
    v = func(v)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/validators.py", line 215, in _run
    return self._exec(self._compiled, value, path)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/validators.py", line 340, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/validators.py", line 338, in _exec
    v = func(path, v)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/srv/homeassistant/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: value must be at most 100 for dictionary value @ data['brightness_pct']

and the automation yaml is:

alias: Wake up lights
description: ''
use_blueprint:
  path: sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
  input:
    max_brightness: '100'
    light_entity: light.yeelight_color_0x0000000007e72c35
    manual_time: '23:28:00'
    sunrise_duration: '10'
    pre_sunrise_actions: []

Hi

I really love this idea!
However, for some reason stopped to work completelly…

Previous version was just turning light on.

I have latest version and it worked a just a bit, but after cycle was over, it turned off (with magic light controller and fluxled component which doesn’t like “transition” effect at all). I manually removed those lines with transition and… stopped working at all.
I remove again completelly this blueprint and automation and… still doesn’t work with fluxled, mqtt nor WLED… Atuomation is activated, but light does not turn on.

I removed the transitions now as it was more trouble then what it was worth. Instead latest version now goes through the 255 absolute brightness steps instead of the 100 percentage steps. This should make transitions obsolete here anyway.

2 Likes