@niemehrarbeiten
it could be that the first alarm is one of health (ie sleepcycle) that seems to be another kind of alarm. I haven’t figured out how to use that yet.
Sorry
I don’t understand where to find/create “There you also find Helpers where you can create the helpers.”
Thanks, but it doesn’t help me.
In my case I wanted my home to do some wild stuff to improve alarm effectiveness. I added an input_button to HA and created an automation in shortcuts with the following configuration:
When: When the alarm is activated
Action:
Dictionary: entity_id: input_button.alarm_clock
Home Assistant Call input_button.press with data dictionary.
I then trigger my HA automations when the input_button is pressed, and only stop the house madness when I manually turn on a light in the kitchen
Hey,
maybe this helps to better understand how it works:
the iOS shortcut will put your alarm values via the Home Assistant app on your phone to 3 specific helpers. The template in the configuration.yaml is reading these helper values and converts it into sensor entities.
Now, how to configure the helper? This is being done in Settings - Devices and Services - and then at the top select Helpers. With the “+ create helpers” button on the lower right helpers can be added. You need to configure 3 helpers.
-
1x type Toggle, this is for the detection if an alarm has been set or not. The iOS shortcut will change the toggle state for you. To keep it simple, name the toggle “alarm_example” since this will exactly match the config in the iOS shortcut.
-
2x type Date and/or time. Here your iOS shortcut will publish the time value of your alarms to. Like above, convenient naming for these two would be first_alarm_example and last_alarm_example.
Now you can run your iOS shortcut. By clicking on your created helper you should be able to see the values coming in. Works like a charm for me! Thanks @Milofow for this
I am stuck at this place with this error message: “Set Dictionary Value failed because Shortcuts couldn’t convert Alarm to Date”
It seems that the issue is related to the fact that an Alarm object can’t go into the dictionary…
Anyone who has an idea for a solution?
Note: The Alarm set boolean works just fine and gets set in Home Assistant.
how does your dictionary look like?
missing information to see what and or where it stalls
I have the exact same error at the same spot. All my settings are by your default names and the Dictonary just says entity_id and then the 2 items are:
input_datetime.first_alarm_example and input_boolean.alarm_example
Hope that helps a little bit more.
Works like a charm, THX. Could you pls add to shorcut the days, when is alarm on? Now I dont know, if is the alarm is for today.
Hello, I had the problem that the alarm data was not transferred correctly.
I have found the error but I am having problems implementing the solution.
My better half has several alarm clocks that are always activated. Due to different working hours, she has alarms that only ring on Tuesday or Friday or Saturday, for example. These are not transmitted to HA. She has now been ill and therefore had all of them off. She once set a “normal” alarm clock and the data was transferred correctly.
In my opinion, this means that the shortcut should include a query for the current day of the week and then transmit the alarm time for this day. The alarm time is transmitted daily at 2.00 am.
Could someone please help me solve this problem?
Changing the server in the homeassistant calls (in the shortcut) and setting up the helpers (as described by @mrcgrndt94) was all it took.
Now I am able to turn on the lights on the first alarm Thanks a lot for sharing.
Hello,
the shortcut works great! Thank you very much!!
I just have the problem that when I set my alarm for 10 AM or 11 AM, the time in HA is set to 22 or 23 hours.
It seems to be related to the formatting of the date or time, but unfortunately, I can’t find the solution.
My location is Germany, maybe there is a different setting for Germany?
Hello,
I have exactly the same issue (from NL). Very strange. If anyone has any idea, that would be much appreciated!
Hey there, thank you for posting this! I got the shortcut imported just fine and changed the server to my HA server. One issue I am having though is with my config.yaml file. I don’t know much about .yaml yet, so that’s likely the issue and I’m hoping this is a simple fix. Anyways, here’s my config.yaml file (I added your code to the end of my config file):
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
# Text-to-speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Google Assistant Stuff
google_assistant:
project_id: home-assistant-79758
service_account: !include SERVICE_ACCOUNT.json
report_state: true
# ESPresense
sensor: !include mysensors.yaml
# Access temp folder for camera images
homeassistant:
allowlist_external_dirs:
- "/config/tmp"
# Wake on LAN for TVs
switch:
- platform: wake_on_lan
mac: 1c:30:08:37:c3:39
name: "Living TV switch"
turn_off:
service: media_player.turn_off
target:
entity_id: media_player.living_room_tv
# Notification Group
notify:
- platform: group
name: chris_allie_phone
services:
- service: mobile_app_chris_iphone
- service: mobile_app_iphone_19
# Spotify Spotcast HACS
spotcast:
sp_dc: !secret sp_dc
sp_key: !secret sp_key
country: SE #optional, added in 3.6.24
# Get alarms from iPhone
sensor:
- platform: time_date
display_options:
- "time"
template:
- sensor:
- name: "Alarm set"
state: "{{ states('input_boolean.alarm_example') }}"
- sensor:
- name: "First alarm"
state: "{{ state_attr('input_datetime.first_alarm_example', 'timestamp') | timestamp_custom('%H:%M', None) }}"
- sensor:
- name: "Last alarm"
state: "{{ state_attr('input_datetime.last_alarm_example', 'timestamp') | timestamp_custom('%H:%M', None) }}"
However, the error I see is:
duplicated mapping key (56:1)
53 | country: SE #optional, added ...
54 |
55 | # Get alarms from iPhone
56 | sensor:
------^
57 | - platform: time_date
I thought this was because I have a line of code in my config file that stores my sensors for ESPresence (sensor: !include mysensors.yaml) and tried to move the code over there, but also ran into some issues. Any idea what might be the causing this error?
Thanks!
I love this! The explanations can be pieced together from the various posts. I’ll try to add:
Elements of this project
Shortcuts app on Iphone
Reads next and last alarm set on the iphone and pushes it into homeassistant. We want this to be triggered every time the Clock app on the phone is closed.
- Add the shortcut to your iphone Shortcuts app as per link. You only need to change your homeassistant instance
- Go to Shortcuts app → Automation → App
When Clock app is closed run the shortcut we just added via the link.
In homeassistant
In configuration.yaml add the sensors and template as per initial post
Helpers
Variables for us to use are added here. They turn the iphone data into usable entities (?). Like @mrcgrndt94 explained:
Now, how to configure the helper? This is being done in Settings - Devices and Services - and then at the top select Helpers. With the “+ create helpers” button on the lower right helpers can be added. You need to configure 3 helpers.
1x type Toggle, this is for the detection if an alarm has been set or not. The iOS shortcut will change the toggle state for you. To keep it simple, name the toggle “alarm_example” since this will exactly match the config in the iOS shortcut.
2x type Date and/or time. Here your iOS shortcut will publish the time value of your alarms to. Like above, convenient naming for these two would be first_alarm_example and last_alarm_example.
Now you can run you
Automation
Now you can add an automation. In my case I want the coffee machine to go on 15min before my first alarm:
alias: Turn On Coffee Machine 15 Minutes Before Next Alarm
description: ""
trigger:
- platform: template
value_template: >-
{{ now() >= today_at(states('input_datetime.first_alarm_example')) -
timedelta(minutes =15) }}
condition:
- condition: state
entity_id: input_boolean.alarm_example
state: "on"
action:
- service: switch.turn_on
target:
entity_id:
- switch.coffee
data: {}
mode: single
I made sure timezones are correct on my homeassistant and app on the iphone and still had to convert my automation to this timestamp format. Before it was triggered an hour early. Maybe this is helpful
edit: I had date time as helper format and that only updates the time. So only have time on the helper and then I changed the automation…
Hi, seems to be related to your date and time settings on your iPhone.
When I disable the “24-hour Time” the shortcut works smoothly.
But as I like the 24 hour clock I will look into how to solve this issue.
For people running into this error
“Set Dictionary Value failed because Shortcuts couldn’t convert Alarm to Date”
You can use this fix;
Had to manually add hours and minutes to the format date section.
For people running into this error
“Set Dictionary Value failed because Shortcuts couldn’t convert Alarm to Date”
You can use this fix;
Had to manually add hours and minutes to the format date section.
Is there a way to calculate the time remaining until the next alarm?
I can´t figure out how to calculate “times” with these templates