Hi t0kn4r,
what do you mean by nvm
and readded “time_date” where?
thanks in advance.
Hi t0kn4r,
what do you mean by nvm
and readded “time_date” where?
thanks in advance.
I was configuring something related to this blueprint today and thought I’d just chime-in to say “Thank you” to @Sbyx as I’ve been relying in this little gem for a couple years now to ensure my kids wake-up nice and fresh
One minor tweak I did around the check_entity
configuration: for each of my kids I’ve created 8 inputs, an overall “wake up alarm enabled” and one additional one for each day of the week, than I have a little section on their dashboards where they can tweak it like this:
This gets around some oddities like my son having his Monday’s classes in the afternoon instead of morning. Also, on the occasional holiday during the week, all it takes is to flip the “enabled” switch off.
The entity to check is templated as follow: (it basically builds an entity ID by adding the day of the week to a fixed prefix, and gets the state of the switch that day. This is ANDed with the global “enabled” flag)
# determine if Rafael's wake-up light should run today:
- platform: template
sensors:
rafael_wakeup_should_run:
value_template: >
{% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
{% set today_name = sensor_names[now().weekday()] %}
{% set entity_id = 'input_boolean.rafael_wakeup_'+today_name %}
{{ is_state('input_boolean.rafael_wakeup_enabled', 'on') and is_state(entity_id, 'on') }}```
Hello, since a couple of weeks I’m having issue with the automation trigger.
I created a helper: input_datetime and a card on lovelace from where I can set a specific time and date.
On the automation trigger part (at the very beginning) I’m not able to find my helper entity which is correctly defined with device class: timestamp in configuration.yaml.
Any help please?
This has stopped working for me, and I’ve made no changes.
It starts, but then will stop at random points in the process or compete all automations. There seems to be no rhyme or reason (typical for HA).
I’m having an issue where if the automation is running, and I use a switch to turn off all lights, they turn back on a second later. Does anyone know why this might be? They seem to behave correctly if I turn them off from the Home Assistant app i.e. it stops the automation and they remain off.
Thanks for the card info, that’s helpful!
Here’s my boolean helper, created in the “Devices & Services” → “Helpers” section of settings
And here’s my automations:
I could have done this in one automation with “When Bedside Lamps is toggled… toggle Bedside Lamps opposite state” but I wanted to eliminate any error e.g. accidentally manually changing the state of the helper.
I’ve noticed the same at least a couple of times when I switch of my lights with a Hue controller switch. Perhaps it’s something to do with the order of commands received by HA?
e.g. it takes a moment for HA to receive the command of the physical switch press, but the automation already started processing the next step up in brightness and mired in that time, then it executes the switch off, but then it executes the next step up that had already started processing.
The couple of times I’ve experienced this, I’ve found that pressing the switch a second time successfully switched the lamps off.
Hmm, you may be right. It does seem to work after a while but I’ve found sometimes I have to do a dance of turning it off quite a few times until they stay off, which isn’t really what you want first thing in the morning.
Hi @samumar, after reading your post about the dashboard card to control the alarm time, I stumbled across the same issue after creating the input_datetime helper - it wasn’t showing up in the list in the “Alarm timestamp sensor” section.
I realised this is because the automation is looking for a sensor, not an input_datetime entity.
I fixed this by creating a sensor which reads the input_datetime helper. I created the sensor through adding the below code to my configuration.yaml (first I tried to create a template sensor helper, but I couldn’t get the syntax right).
template:
# Create a sensor for the Wake Up Alarm automation to read the input datetime from the dashboard
sensor:
name: "Wake Up Alarm"
unique_id: template_se_alarm_01
state: "{{ (states('input_datetime.wake_up_alarm') | as_datetime | as_local).isoformat() }}"
device_class: timestamp
Now the created sensor appears in the automation
Hope this helps you!
Super, it’s working just fine. Many thanks!!
Great to hear!
I’d be interested to hear if the alarm is now matching your input_datetime entity and not the manual alarm setting in the Automation.
Reason being when I check the state of the sensor.wake_up_alarm in Dev Tools Template, I get “unknown”.
I think there’s an issue with the Device Class “timestamp” expecting a different format than the datetime string provided by the input_datetime entity, I’m working through that now…
Ok, I’ve now fixed my sensor so it’s outputting correctly with the timestamp device class. I needed to change the template state as follows:
{{ (states('input_datetime.wake_up_alarm') | as_datetime | as_local).isoformat() }}
My sensor now outputs as expected:
I also worked out how to add it as a helper entity through the UI in the meantime
Solution found thanks to this post!
Hi, could it be set up like this:
Is there a way to do it or maybe there are other better solutions?
Hi,
I’ve been trying to set an alarm timestamp sensor, in order to be able to change from the dashboard the time I want the automation to run.
I created a time helper input_datetime.wake_up_alarm, and added a sensor in templates.yaml :
sensor:
- name: "Wake Up Alarm"
unique_id: template_se_alarm_01
state: "{{ (states('input_datetime.wake_up_alarm') | as_datetime | as_local).isoformat() }}"
device_class: timestamp
When I set the alarm timestamp sensor to sensor.wake_up_alarm, it doesn’t work as expected.
Am I missing something there ? Could anyone help me ? Thanks
Same here, I am also confused. The help says it needs a “Sensor with timestamp of next alarm with device_class: timestamp”. I tried a template sensor that returns datetime as well as isoformat.
{% set alarm_time = state_attr('sensor.pixel_5_next_alarm', 'Time in Milliseconds') / 1000 %}
{% set alarm_time_dt = as_datetime(alarm_time)| as_local %}
{{alarm_time_dt is datetime}}
{{alarm_time_dt}} # also alarm_time_dt.isoformat()
Both options raising the error
Error: In ‘template’ condition: ValueError: Template error: as_timestamp got invalid input ‘unknown’ when rendering template ‘{{0 < as_timestamp(states(sensor) if sensor != ‘none’ else states(‘sensor.date’) ~ ’ ’ ~ manual_time) - as_timestamp(states(‘sensor.date_time_iso’)) <= float(seconds) and states(check_entity) in [‘unknown’, ‘on’, ‘home’]}}’ but no default was specified
The helper in all cases show a valid value, unsure why it’s unknown
to the blueprint.
Any help is welcome!
Just realizing the problem is states('sensor.date_time_iso')
. I don’t have such a sensor. What should it yield?
@TomTom101 Your hint with the ISO timestamp gave me the right place to look. You have to add the following integration: Time & Date - Home Assistant
Hey guys, Hey @Sbyx,
I have enhanced the Wake-up Light Alarm Blueprint with a few features that I find useful:
A new option called "ignore_future_alarms" has been added. When enabled, alarms set for future days will be ignored, and the manual alarm time will be used instead.
The logic has been adjusted to better handle various alarm situations, including invalid or future alarms.
These changes allow for more flexible use of the blueprint, especially for those who want to use both daily and specific alarms.
Here is the updated code:
blueprint:
name: Wake-up light alarm with sunrise effect
description: "A wake-up light alarm with a brightness and color temperature sunrise effect. Note: Requires date_time_iso sensor in configuration, not manually executable!"
domain: automation
input:
light_entity:
name: Wake-up light entity
description: The light to control. Turning it off during the sunrise will keep it off. Color temperature range is auto-detected.
selector:
entity:
domain: light
timestamp_sensor:
name: Alarm timestamp sensor
description: "Sensor with timestamp of next alarm with device_class: timestamp (set to 'none' for manual alarm time)"
default: none
selector:
entity:
device_class: timestamp
manual_time:
name: Manual alarm time
description: Time to trigger alarm every day if timestamp sensor is not set or ignored. Settings at or shortly after midnight will not work as expected!
default: "7:00:00"
selector:
time: {}
ignore_future_alarms:
name: Ignore future alarms
description: If enabled, alarms set for future dates will be ignored and the manual time will be used instead.
default: false
selector:
boolean: {}
check_entity:
name: Additional entity to check before sunrise is triggered
description: If set, checks if entity is 'on' or 'home' before triggering. Use e.g. a (workday) sensor, device_tracker or person entity.
default: none
selector:
entity: {}
sunrise_duration:
name: Sunrise duration
description: The sunrise will start the configured number of minutes before the timestamp.
default: 25
selector:
number:
min: 5.0
max: 60.0
step: 5.0
unit_of_measurement: min
mode: slider
start_brightness:
name: Minimum brightness
description: The brightness to start with. Some lights ignore very low values and may turn on with full brightness instead!
default: 1
selector:
number:
min: 1.0
max: 255.0
step: 1.0
mode: slider
end_brightness:
name: Maximum brightness
description: The brightness will be transitioned from the minimum to the configured value.
default: 254
selector:
number:
min: 5.0
max: 255.0
step: 1.0
mode: slider
min_mired:
name: Minimum color temperature
description: "The minimum color temperature to use. (0: lowest supported)"
default: 0
selector:
number:
min: 0.0
max: 500.0
step: 5.0
mode: slider
unit_of_measurement: mired
pre_sunrise_actions:
name: Pre-sunrise actions
description: Optional actions to run before sunrise starts.
default: []
selector:
action: {}
post_sunrise_actions:
name: Post-sunrise actions
description: Optional actions to run after sunrise ends (around the alarm time).
default: []
selector:
action: {}
variables:
light_entity: !input "light_entity"
sensor: !input "timestamp_sensor"
sunrise_duration: !input "sunrise_duration"
start_brightness: !input "start_brightness"
end_brightness: !input "end_brightness"
range_brightness: "{{float(end_brightness)-float(start_brightness)}}"
manual_time: !input "manual_time"
seconds: "{{float(sunrise_duration) * 60}}"
min_mired: !input "min_mired"
start_mired: "{{state_attr(light_entity, 'max_mireds')}}"
end_mired: "{{[state_attr(light_entity, 'min_mireds')|int(0), min_mired|int(0)]|max}}"
tick_time: "{{float(seconds) / float(range_brightness)}}"
check_entity: !input "check_entity"
ignore_future_alarms: !input "ignore_future_alarms"
trigger:
- platform: time_pattern
minutes: "*"
condition: []
action:
- variables:
sensor_time: >
{% if sensor != 'none' and states(sensor) != 'unavailable' and as_timestamp(states(sensor)) %}
{% if ignore_future_alarms and as_timestamp(states(sensor)) | timestamp_custom('%Y-%m-%d') > now().strftime('%Y-%m-%d') %}
{{ states('sensor.date') ~ ' ' ~ manual_time }}
{% else %}
{{ states(sensor) }}
{% endif %}
{% else %}
{{ states('sensor.date') ~ ' ' ~ manual_time }}
{% endif %}
- wait_template: >
{{ 0 < as_timestamp(sensor_time) - as_timestamp(states('sensor.date_time_iso')) <= float(seconds) and states(check_entity) in ['unknown', 'on', 'home'] }}
- choose: []
default: !input "pre_sunrise_actions"
- service: light.turn_on
data:
brightness: "{{ start_brightness }}"
color_temp: "{{ start_mired if state_attr(light_entity, 'min_mireds') != None else omit }}"
entity_id: !input "light_entity"
- repeat:
while:
- condition: template
value_template: >
{{ 0 < as_timestamp(sensor_time) - as_timestamp(now()) <= float(seconds) }}
sequence:
- delay: "{{ tick_time }}"
- service: light.turn_on
data:
brightness: >
{{ (float(end_brightness) - (float(range_brightness) * (as_timestamp(sensor_time) - as_timestamp(now())) / float(seconds))) | int(0) }}
color_temp: >
{% if state_attr(light_entity, 'min_mireds') != None %}
{{ (float(end_mired) + (float(start_mired) - float(end_mired)) * ((as_timestamp(sensor_time) - as_timestamp(now())) / float(seconds))) | int(0) }}
{% else %}
{{ omit }}
{% endif %}
entity_id: !input "light_entity"
- choose: []
default: !input "post_sunrise_actions"
mode: single
max_exceeded: silent
Let me know what you think!