Alarm clock sensor doesn't trigger Automation

Hi there,

I’m trying to start an automation to switch on my espresso machine, when my alarm clock on my mobile phone is ringing. I use the official homeassistant app for android to get the next alarm, which works fine. The problem is, that although the sensor switches to “true” correctly, the automation won’t start. However, if I manually set the variable “fabians_mobile_alarmclock_triggered” to true in dev tools, the automation is triggered. Maybe the time, the sensor variable is set to “true” is to short (apprx. 1 second) to trigger the automation? I don’t see what else could be the difference between setting the variably automatically vs. manually.

Thanks and kind regards
Fabian

configuration.yaml

sensor:
  - platform: template
    sensors:
      fabians_mobile_alarmclock_triggered:
        entity_id:
          - sensor.fabians_sm_g9700_next_alarm
          - sensor.time
        friendly_name: "Fabians Handywecker hat ausgelöst"
        value_template: >-
          {{now().strftime("%a %h %d %H:%M %Z %Y") == (((state_attr('sensor.fabians_sm_g9700_next_alarm', 'Time in Milliseconds') | int / 1000) + 0*60 ) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}

automation.yaml:

- id: '1605608124444'
  alias: Schalte Kaffeemaschine ein wenn Wecker klingelt
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.fabians_mobile_alarmclock_triggered
    from: "false"
    to: "true"
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: group.inhabitants
      state: home
    - condition: state
      entity_id: input_boolean.automatic_coffee
      state: 'on'
    - condition: state
      entity_id: input_boolean.vacation
      state: 'off'
  action:
  - type: turn_on
    device_id: 6b2ef3f547a041708e89f5f3b0ac7bfc
    entity_id: switch.sonoff01
    domain: switch
  mode: single

Hassio-Version: 0.117.5
Mobile App Version: 3.0.2-full

If I am not mistaken, your problem is that your trigger is “true”/“false” which are a strings.
Your value_template appears to evaluate to True/False (no quotes first letter capitalized). which are boolean objects
Try:

  trigger:
  - platform: state
    entity_id: sensor.fabians_mobile_alarmclock_triggered
    from: False
    to: True

Hi @itkfilelor,

thanks for your quick reply. Apparently the value_template needs strings as input (if I type it like you said I get the error “Message malformed: expected str for dictionary value @ data[‘to’]”) but I changed the first letter to upper case (‘True’ and ‘False’) and it seems to work. The boolean expression is obviously case sensitive. I’m still wondering why the automation is triggered when I set the object manually, though.

This is my automation:

I start it one minute before the alarm because the state of next alarm disappear very quickly when the alarm goes off.

Fair enough, I don’t personally use bools in any of my automation. Either on/off or plain strings (e.g. ‘idle’,‘Netflix’,etc.) Glad I was at least able to inspire you to the right direction :grin:

I use my snooze button too much for this to work for me. Plus on days off, I still want my coffee started or even done by the time I make it to the kitchen.
What I did was combine Tasker on android with Hassio. When I connect my bluetooth in the morning, It cancels any upcoming alarms, tells me the current weather and forecast at home (if it’s a work day, also at work as it is an hour away and about 800ft higher in elevation), cancels sleep mode on my watch, and triggers an HA script(coffee maker on [mqtt switch], den lights on, and turns sleep mode off, which silences most notifications). it will also eventually turn on an automation to start my car 10,15,or 20 minutes before it is time to leave for work based on outside and car interior temperature with an integration we are currently trying to make here.

That doesn’t make sense.

I assume “my bluetooth” means bluetooth headphones/watch or something like it, then if that is the trigger then the coffee won’t be done, unless the weather report takes about 10-15 minutes to read.

Headphones yes. It also starts my podcasts which is what even got me started on this path even before I got into the smart home scene.
It usually is done or near done based on my morning routine, I don’t just pop up and head for the cup :wink:

I did this

1 Like