New - Help with conditions (Android Next-Alarm function)

Hi there!

I’m quite new so I apologise if this is the wrong place. I’ve done a lot of looking into this on the forums and haven’t (perhaps out of a lack of familarity with how YAML works) been able to formulate a working condition within an automation to capture a certain condition. Would somebody be able to give me some guidance on how to set up this condition, and why it needs to be set up this way?

To summarise and contextualise my question:

The “Next Alarm” function gives you a time in milliseconds when the next alarm event on your phone will go off on an Android. This generally will be either from Calendar, or from Clocks (Clocks being alarm clocks). As part of my project, I want to start turning on my lights and activating automation on alarms triggered from Clocks. This data seems to be stored an in attribute called “Packages”, and will give either
com.android.providers.calendar for calendar events, or com.sec.android.app.clockpackage for the Clock.

I have therefore set up an automation where the trigger is detecting when there is two minutes left on the timer, and begins to turn on lights and other devices in anticipation for waking up. So far so good - the automation triggers, activating the lights two minutes after the trigger runs. This is tied to an uncontroversial condition of me also being at home.

The difficulty is creating a condition that looks at the sensor.sm_g980f_next_alarm that my phone is providing, and reading only the attribute package and comparing it against the relevant string above.

I expected that the following would work - I have placed in bold the section that I have added.

- id: '1598793994141'
  alias: Morning - Lights on with Alarm
  description: 'Wake-up Lights synced with Android Clocks App'
  trigger:
  - below: '2'
    entity_id: sensor.minutes_next_alarm
    platform: numeric_state
  condition:
  - condition: zone
    entity_id: person.kita
    zone: zone.home
  **- condition: state**
**    entity_id: sensor.minutes_next_alarm**
**    attribute: Package**
**    state: com.sec.android.app.clockpackage**
  action:
  - delay: 0:02:00
  - scene: scene.lights_on_home_arrivals
  - delay: 0:10:00
  - scene: scene.lights_on_home_arrivals
  mode: single

Can any of the more experienced hands explain why this isn’t working?

Cheers,
Kitacatter

For clarity, given that botched the bolded formatting the code area:

Working Code:

- id: '1598793994141'
  alias: Morning - Lights on with Alarm
  description: ''
  trigger:
  - below: '3'
    entity_id: sensor.minutes_next_alarm
    platform: numeric_state
  condition:
  - condition: zone
    entity_id: person.kita
    zone: zone.home
  action:
  - delay: 0:02:00
  - scene: scene.wakeup
  - delay: 0:10:00
  - scene: scene.lights_on_home_arrivals
  mode: single

Condition to amend the above code:

- condition: state
  entity_id: sensor.minutes_next_alarm
  attribute: Package
  state: com.sec.android.app.clockpackage
- id: '1598793994141'
  alias: Morning - Lights on with Alarm
  description: 'Wake-up Lights synced with Android Clocks App'
  trigger:
  - below: '2'
    entity_id: sensor.minutes_next_alarm
    platform: numeric_state
  condition:
  - condition: zone
    entity_id: person.kita
    zone: zone.home
  - "{{ is_state_attr('sensor.minutes_next_alarm', 'package', 'com.sec.android.app.clockpackage') }}"
  action:
  - delay: 0:02:00
  - scene: scene.lights_on_home_arrivals
  - delay: 0:10:00
  - scene: scene.lights_on_home_arrivals
  mode: single
1 Like

Thank you! Works a charm, you’re a lifesaver!

Final code is as follows for anyone else following in the footsteps, noting a capital added to “Package” - works fantastically!

- id: '1598793994141'
  alias: Morning - Lights on with Alarm
  description: ''
  trigger:
  - below: '5'
    entity_id: sensor.minutes_next_alarm
    platform: numeric_state
  condition:
  - condition: zone
    entity_id: person.kita
    zone: zone.home
  - condition: template
    value_template: '{{ is_state_attr(''sensor.sm_g980f_next_alarm'', ''Package'',
      ''com.sec.android.app.clockpackage'') }}'
  - after: 04:00
    before: '11:00'
    condition: time
  action:
  - delay: 0:02:00
  - scene: scene.wakeup
  - delay: 0:02:00
  - scene: scene.lights_on_home_arrivals
  mode: single
1 Like