Here’s the code which I mostly copied from someone else that starts the alarm sequence.
Caveats:
- it works for my wife but not for me as I have yet to find an android app that uses the API properly and thus works with the next alarm sensor (would welcome your confirmation about sleep as android).
- having this sequence for 2 mobile phones makes it go crazy, even at the level of the home assistant companion app. The next alarm sensor will start giving wrong times for both phones (both in home assistant and in the app configuration windows in the app itself). No clue why this is happening.
[{"id":"664bcf1c.d25e8","type":"delay","z":"7a3ae4e9.be665c","name":"wait until time","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":520,"y":220,"wires":[["dbe04d14.7bbab","2fea0326.b6ab7c","6ff082bf.fe0cdc"]]},{"id":"ffa8ad2e.133d4","type":"change","z":"7a3ae4e9.be665c","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":220,"wires":[["664bcf1c.d25e8"]]},{"id":"17ff4332.e9872d","type":"function","z":"7a3ae4e9.be665c","name":"time difference","func":"const now = Date.now();\nconst alarm = new Date(msg.payload);\n\nconst timeDifference = alarm - now;\n\nmsg.delay = timeDifference;\n\n// Reset the delay node before setting the new delay\nreturn [[{reset: true},msg]];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":180,"wires":[["664bcf1c.d25e8","96909069.97977","7510cf3b.04c65"]]},{"id":"2f50c59a.2439ea","type":"api-current-state","z":"7a3ae4e9.be665c","name":"get next alarm","server":"5c29d263.09d2ac","version":1,"outputs":2,"halt_if":"unavailable","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"sensor.mobile_florence_next_alarm","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":160,"y":140,"wires":[["17ff4332.e9872d"],[]]},{"id":"71576a68.4c7494","type":"server-state-changed","z":"7a3ae4e9.be665c","name":"Next Alarm Flo","server":"5c29d263.09d2ac","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mobile_florence_next_alarm","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"unavailable","halt_if_type":"str","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":120,"y":200,"wires":[["17ff4332.e9872d","96909069.97977"],["ffa8ad2e.133d4"]]},{"id":"8e4828e2.840ed8","type":"inject","z":"7a3ae4e9.be665c","name":"reboot or deploy","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":110,"y":100,"wires":[["2f50c59a.2439ea"]]},{"id":"5c29d263.09d2ac","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]