Phone alarm as a trigger in Home Assistant using the sensors in Home assistant companion app

Phone alarm as a trigger in Home Assistant using the sensors in Home assistant companion app.

First you need to turn on the sensor. Using the Phone you want to pull in sensor info from.
Open the Home assistant companion app.
Go to

Setting
	Companion app
		Manage sensors
			Alarm sensors
				Enable sensor

Add the template below in your template.yaml file or in Configuation.yaml. (Format and place in correct location in configuation.yaml depending on your setup)
change the name of the sensor.pixel_5_next_alarm to the name of the persons next alarm sensor.

 - sensor:
      - name: "rods alarm"
        
        state: >
          {{now().strftime("%a %h %d %H:%M %Z %Y") ==
          (((state_attr('sensor.pixel_5_next_alarm', 'Time in Milliseconds') |
           int / 1000)) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}        

Reload your Templates in Developer tools YAML configuration reloading.
BOOM
Now you have a next alarm sensor to be used as a trigger.

Automation UI trigger

platform: state
entity_id:
  - sensor.rods_alarm
from: "False"
to: "True"
3 Likes

Do you know if there is a way to set the phone alarm time from HA?

Not that I know of …
I’m not that smart.

Thanks for this script @Rod_Poplarchick I now have my lights turning on when my phone alarm goes off… Awesome!

1 Like

I was having some issues with this script as it was turning on my lights when any alarm was triggered including calendar events. I have added the following to the automation so it is only triggered by my phone alarm and when I am home.

{{ (now().strftime("%a %h %d %H:%M %Z %Y") ==
          (((state_attr('sensor.matt_s23_ultra_next_alarm', 'Time in Milliseconds') | int / 1000)) | timestamp_custom('%a %h %d %H:%M %Z %Y')) 
          and (state_attr('sensor.matt_s23_ultra_next_alarm', 'Package')) == 'com.sec.android.app.clockpackage') 
          and (states('sensor.mattgoogle') =='Home') }}
2 Likes
intent_package_name: com.google.android.deskclock
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
  {% set time = states('input_datetime.alarmtime') %}   
  {% set timelist = time.split(':') %}    
  {% set timehour = timelist[0]%}    
  {% set timemin = timelist[1] %}
    android.intent.extra.alarm.MESSAGE:{{'Work Alarm'}},android.intent.extra.alarm.HOUR:{{timehour}},android.intent.extra.alarm.MINUTES:{{ timemin }},android.intent.extra.alarm.SKIP_UI:true

2 Likes

Thanks for this. Was having same issue and your package specification was what i needed.