In order to trigger automation based on alarms at home, I found that I was stuck to using tasker and my mobile phone based on the information I was able to find online. If you had an iphone, it seemed even tougher to find a solution.
After some digging around I managed to build a simple script that can trigger different events on home assistant based on a timer going off on google home or an alarm going off. You can run the script on any device even a PC, you would just need to make sure your device is running 24*7.
Currently, I have the alarm set up to trigger one of my bedroom lights to blink until I stop the google home alarm. For the timer, I have set my desk light to blink, since I usually use the timer on my desk and having the bedroom lights blinking for this would be pretty annoying.
PS: If you guys think this is useful, it should be pretty easy for me to build this as a HASSIO add-on. Let me know your thoughts!
Would be great if you could start an script when there is, for example, 5 minutes before an alarm goes off. Then I could have my lights slowly start lighting up the room.
I’m no coder so this might be a dumb question, but is there any way to have this simply pass the time the alarm is set so that home assistant can always know what time the alarm is set for? I’m trying to set up a way to have my lights start fading up some time before the alarm goes off similar to what the previous poster was referring to, but I want it to be more general use so it would be nice to have homeassistant know and update the set time for the alarm.
Not very sure about that, maybe our home assistant experts can help out. Would be actually more convinient too if this was a hass add on so anyone can configure any scene whenever alarm goes off.
I was looking forward to a solution for this some time ago but have since forgotten about it. Thanks for this, I will definitely try it!
Would love an addon though, if it’s even possible. Is it possible to run the script off of a HASSOS build? I’m still kind of new to all this.
Would love to set the alarm as a sensor for a wake-up light animation.
I copy the code from drndos post. But there I can get only the timer and its working. But I cant manage to implement the alarms
Can some one please post the code for the alarms
Thanks
Great, it’s working. Thanks for the help.
Now I have another two problems.
I manage to show time in minutes but there are many decimal numbers, can I set the code to show only minutes with no decimal
and can I show in alarm1_time only numbers like 14:00 without houer, minuteand second text
my current code for sensor is
- platform: rest
name: GoogleHomeAlarms
json_attributes:
# - timer
- alarm
resource: http://192.168.1.50:8008/setup/assistant/alarms
value_template: '{% if value_json.alarm[0] is defined %}{{ value_json.alarm[0].id }}{% endif %}'
force_update: true
- platform: template
sensors:
# timer1_remaining:
# value_template: '{% if states.sensor.googlehomealarms.attributes.timer[0] is defined %}{{ ((states.sensor.googlehomealarms.attributes.timer[0].fire_time + states.sensor.googlehomealarms.attributes.timer[0].original_duration) / 1000) - as_timestamp(now()) | int }}{% endif %}'
# unit_of_measurement: s
# entity_id: sensor.googlehomealarms
# timer1_end_time:
# value_template: '{% if states.sensor.googlehomealarms.attributes.timer[0] is defined %}{{ ((states.sensor.googlehomealarms.attributes.timer[0].fire_time + states.sensor.googlehomealarms.attributes.timer[0].original_duration) / 1000) | int }}{% endif %}'
# entity_id: sensor.googlehomealarms
alarm1_time:
value_template: "{% if states.sensor.googlehomealarms.attributes.alarm[0] is defined %}{{ states.sensor.googlehomealarms.attributes.alarm[0].time_pattern }}{% endif %}"
entity_id: sensor.googlehomealarms
alarm1_remaining:
value_template: "{% if states.sensor.googlehomealarms.attributes.alarm[0] is defined %}{{ ((states.sensor.googlehomealarms.attributes.alarm[0].fire_time / 1000) - as_timestamp(now())) /60 | int }}{% endif %}"
entity_id: sensor.googlehomealarms
unit_of_measurement: "min"