Sensor Attributes into Android Intent; Alarm

I have a sensor that has an attribute with a UNIX timestamp in it. Using a template I can retrieve the attribute into a template as follows:

state_attr('sensor.google_alarm', 'unixTimeToLeave')

I want to put this into an automation that I have triggering correctly, 3 hours before the event or when an event is created/moved and put it into the format of an android intent to set an alarm, but I don’t know how to create the template from the UNIX timestamp:

service: notify.mobile_app_nathaniel_mobile
data:
  message: command_activity
  data:
    tag: android.intent.action.SET_ALARM
    group: "android.intent.extra.alarm.HOUR:%H,android.intent.extra.alarm.MINUTES:%M,android.intent.extra.alarm.MESSAGE:Leave,android.intent.extra.alarm.RINGTONE:Roller Disco,android.intent.extra.alarm.SKIP_UI:true"

Any help would be appreciated :slight_smile:

If this attribut is a Unix timestamp then it shouldn’t be to hard.
Now().timestamp() is also a timestamp and can be manipulated like this:

{{ now().timestamp() | timestamp_custom("%H")}}

now in my timezone that returns 13.

So your yaml to get the hour and minute should be

Hour:

{{ (state_attr('sensor.google_alarm', 'unixTimeToLeave') | int) | timestamp_custom("%H")}}

and minute is the same but replace the %H with %M.

You could store the hour and minutes in variables to make the actual call service a bit nicer and easier to read.

I just noticed the three hour thing.
Is this Unix attribute with or without the three hours?

You can remove three hours with:

{{ (state_attr('sensor.google_alarm', 'unixTimeToLeave') | int - 3600*3) | timestamp_custom("%H")}}

Oh… the 3 hour thing I’ve figured out and that is done by the trigger… the part I’m not sure of is the phone intent part… I added the template, but I must have done it wrong or not really understood how it all works because it just yells “thats an error” at me:

service: notify.mobile_app_nathaniel_mobile
data:
  message: command_activity
  data:
    tag: android.intent.action.SET_ALARM
    group: "android.intent.extra.alarm.HOUR:{{ (state_attr('sensor.google_alarm', 'unixTimeToLeave') | int) | timestamp_custom("%H")}},android.intent.extra.alarm.MINUTES:{{ (state_attr('sensor.google_alarm', 'unixTimeToLeave') | int) | timestamp_custom("%M")}},android.intent.extra.alarm.MESSAGE:Leave,android.intent.extra.alarm.RINGTONE:Roller Disco,android.intent.extra.alarm.SKIP_UI:true"

Try it in the template tools, if it outputs the string correct then it’s correct.

puting it into the template tools it works fine… however when I go to create the automation it doesn’t do anything… and i don’t know how to even test that it’s doing things right there

edit: hmm i must have done something wrong… it works now

If you just run the action of the automation then it should set an alarm on the phone.
Because whatever the sensor says, we only use the hour and minute, so even if the date is yesterday, the alarm will be today or tomorrow.