Wake-up light based on Android alarm time (-10 min)

Hi!

What might be wrong with this flow? I cannot get it working…

Alarm time from phone works ok.

[{"id":"d5ba75a2.120728","type":"api-call-service","z":"c13bbcab.90a03","name":"Nelli Led \"on\" 1%","server":"a2ec974.6e15268","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.nelli_led3_light","data":"{\"brightness_pct\":1}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1150,"y":300,"wires":[[]]},{"id":"e8c56c70.3d816","type":"delay","z":"c13bbcab.90a03","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":980,"y":420,"wires":[["2f8bd8c2.9424c8"]]},{"id":"2f8bd8c2.9424c8","type":"api-call-service","z":"c13bbcab.90a03","name":"Kirkkauden kasvatus 100% 10 min","server":"a2ec974.6e15268","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.keittio_lamppu_light","data":"{\"brightness_pct\":100,\"transition\":60}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1220,"y":420,"wires":[[]]},{"id":"5fd4bf94.3d203","type":"join","z":"c13bbcab.90a03","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":340,"wires":[["3baa06b3.7b18fa"]]},{"id":"3baa06b3.7b18fa","type":"function","z":"c13bbcab.90a03","name":"Compare Times","func":"newmsg = {};\nif (msg.payload[0] == msg.payload[1]) {\n    newmsg.payload = \"True\";\n} else {\n    newmsg.payload = \"False\";\n}\n\nreturn newmsg;","outputs":1,"noerr":0,"x":820,"y":500,"wires":[["69f8941b.a2457c"]]},{"id":"69f8941b.a2457c","type":"switch","z":"c13bbcab.90a03","name":"Is it Time?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"True","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":890,"y":340,"wires":[["d5ba75a2.120728","e8c56c70.3d816"]]},{"id":"ed1570d4.2671d","type":"moment","z":"c13bbcab.90a03","name":"Alarm - 10min","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Berlin","adjAmount":"10","adjType":"minutes","adjDir":"subtract","format":"YYYY-MM-DD HH:mm","locale":"C","output":"payload","outputType":"msg","outTz":"Europe/Berlin","x":560,"y":460,"wires":[["5fd4bf94.3d203"]]},{"id":"c2b4d347.fde2","type":"moment","z":"c13bbcab.90a03","name":"Current Time","topic":"","input":"payload","inputType":"msg","inTz":"Europe/Helsinki","adjAmount":"0","adjType":"minutes","adjDir":"subtract","format":"YYYY-MM-DD HH:mm","locale":"C","output":"payload","outputType":"msg","outTz":"Europe/Helsinki","x":610,"y":500,"wires":[["5fd4bf94.3d203"]]},{"id":"6253e27d.b225ec","type":"trigger-state","z":"c13bbcab.90a03","name":"","server":"a2ec974.6e15268","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_datetime.next_alarm_nelli","entityidfiltertype":"exact","debugenabled":true,"constraints":[],"outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":200,"y":360,"wires":[["f1dc6940.7788c8"],[]]},{"id":"f1dc6940.7788c8","type":"time-range-switch","z":"c13bbcab.90a03","name":"","lat":"","lon":"","startTime":"07:00","endTime":"09:30","startOffset":0,"endOffset":0,"x":450,"y":360,"wires":[["90e3153c.d17408"],[]]},{"id":"90e3153c.d17408","type":"weekday","z":"c13bbcab.90a03","name":"","sun":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"x":350,"y":460,"wires":[["ed1570d4.2671d"],[]]},{"id":"a2ec974.6e15268","type":"server","name":"Home Assistant","addon":true}]

Hey man
On phone, so I cannot test your flow right now…but I think your missing a line from weekday to current time?

I have “Shift Schedule” on my Phone and

and I have this sensor

    minutes_next_alarm_stephan:
      friendly_name: "Minutes until Next Alarm Stephan"
      unit_of_measurement: "m"
      value_template: >-
        {% set dummy = states("sensor.time") %}
        {{((states('sensor.stephan_phone_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int}}
      availability_template: "{{ not is_state('sensor.stephan_phone_next_alarm','unavailable') }}"
      attribute_templates:
        time: "{{ state_attr('sensor.stephan_phone_next_alarm','Local Time') }}"

then have this automation

- id: '85cf493e-b8eb-4a8b-8645-b384b752d0fd'
  alias: My Phone Alarm about to go off
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.minutes_next_alarm_stephan
    below: '2'
  condition: 
  - condition: state
    entity_id: light.kitchen
    state: 'off'
  action:
  - data:
      entity_id: switch.kettle_power
    service: switch.turn_on
  - delay: '00:00:50'  
  - data:
      entity_id: light.his_side
    service: light.turn_on
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.day_night
            state: 'Night'
        sequence:
          - service: light.turn_on
            entity_id: light.kitchen
  mode: single

now all I do is setup my next cover set the alarm and the phone alarm wakes me and the kettle get turn on

This flow is supposed to get triggered every minute to work.
The 2 date/time formatter nodes (Alarm - 10min & Current Time) need to be compared every minute in order for it to work.

There is however, a new node “time” - which should be able to handle this whole thing much more easily.

 **time**

A node that can be scheduled to trigger at a future date and time from a Home Assistant entity.
1 Like

Thx all for your answers…

@AlmostSerious You have nice suggestion… Are you able to modify my flow to push me to the right direction… I’m kinda noob and everything form me try&learn track…

[{"id":"d5ba75a2.120728","type":"api-call-service","z":"dc990f43.6ea1c","name":"Nelli Led \"on\" 1%","server":"a2ec974.6e15268","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.nelli_led3_light","data":"{\"brightness_pct\":1}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1430,"y":300,"wires":[[]]},{"id":"e8c56c70.3d816","type":"delay","z":"dc990f43.6ea1c","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1260,"y":420,"wires":[["2f8bd8c2.9424c8"]]},{"id":"2f8bd8c2.9424c8","type":"api-call-service","z":"dc990f43.6ea1c","name":"Kirkkauden kasvatus 100% 10 min","server":"a2ec974.6e15268","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.keittio_lamppu_light","data":"{\"brightness_pct\":100,\"transition\":60}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1500,"y":420,"wires":[[]]},{"id":"5fd4bf94.3d203","type":"join","z":"dc990f43.6ea1c","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":970,"y":380,"wires":[["3baa06b3.7b18fa"]]},{"id":"3baa06b3.7b18fa","type":"function","z":"dc990f43.6ea1c","name":"Compare Times","func":"newmsg = {};\nif (msg.payload[0] == msg.payload[1]) {\n    newmsg.payload = \"True\";\n} else {\n    newmsg.payload = \"False\";\n}\n\nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1100,"y":500,"wires":[["69f8941b.a2457c"]]},{"id":"69f8941b.a2457c","type":"switch","z":"dc990f43.6ea1c","name":"Is it Time?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"True","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1170,"y":340,"wires":[["d5ba75a2.120728","e8c56c70.3d816"]]},{"id":"ed1570d4.2671d","type":"moment","z":"dc990f43.6ea1c","name":"Alarm - 10min","topic":"","input":"payload.alarm","inputType":"msg","inTz":"Europe/Berlin","adjAmount":"10","adjType":"minutes","adjDir":"subtract","format":"YYYY-MM-DD HH:mm","locale":"C","output":"payload","outputType":"msg","outTz":"Europe/Berlin","x":800,"y":440,"wires":[["5fd4bf94.3d203"]]},{"id":"c2b4d347.fde2","type":"moment","z":"dc990f43.6ea1c","name":"Current Time","topic":"","input":"payload.timenow","inputType":"msg","inTz":"Europe/Helsinki","adjAmount":"0","adjType":"minutes","adjDir":"subtract","format":"YYYY-MM-DD HH:mm","locale":"C","output":"payload","outputType":"msg","outTz":"Europe/Helsinki","x":690,"y":560,"wires":[["ee5d5d14.e6ef7"]]},{"id":"f1dc6940.7788c8","type":"time-range-switch","z":"dc990f43.6ea1c","name":"","lat":"","lon":"","startTime":"07:00","endTime":"09:30","startOffset":0,"endOffset":0,"x":630,"y":360,"wires":[["90e3153c.d17408"],[]]},{"id":"90e3153c.d17408","type":"weekday","z":"dc990f43.6ea1c","name":"","sun":false,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"x":630,"y":460,"wires":[["ed1570d4.2671d","c2b4d347.fde2"],[]]},{"id":"e16270fa.743bd","type":"inject","z":"dc990f43.6ea1c","name":"","props":[],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":290,"y":280,"wires":[["8d7f835e.be095"]]},{"id":"8d7f835e.be095","type":"api-current-state","z":"dc990f43.6ea1c","name":"","server":"918c55fd.ba9f58","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_datetime.next_alarm_nelli","state_type":"str","state_location":"payload.alarm","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":610,"y":280,"wires":[["f1dc6940.7788c8"]]},{"id":"ee5d5d14.e6ef7","type":"delay","z":"dc990f43.6ea1c","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":860,"y":560,"wires":[["5fd4bf94.3d203"]]},{"id":"a2ec974.6e15268","type":"server","name":"Home Assistant","addon":true},{"id":"918c55fd.ba9f58","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I use a very similar approach - a few more options, but it’s basically the same base.

Please note, this wouldn’t work if you set your alarm between 07:00 and 07:09 - if you want it to, you need to change the timerange node to 06:50 - 09:30.

Let me know if that works!

1 Like

I’ll test this one… thx…