Avoid this lame trigger and use this one instead
Below are some automations that are triggered Good Night This is an iPhone specific automation and is triggered when the phone is plugged in at bedtime. This automation has 2 parts. The first is setting up the automation in Home Assistant using Node-Red. The second part is setting up the trigger on your iOS device.
In Home Assistant
To keep things simple, this result of this automation is to call a link-out node that would run a list of desired automations.
[{"id":"0ff2a23041167917","type":"group","z":"6161d870e25ec591","name":"Run right before bed","style":{"fill":"#ffffff","label":true,"color":"#000000"},"nodes":["22138745eb6cbd78","0e3a89dcb4cdc2eb","29e4874b8d40526a","5ccf59b641caef15","f5b4c5db2c38c9bf","9fa93fa7bef49d81","dfc3ad15d5aef4ef"],"x":14,"y":479,"w":932,"h":182},{"id":"22138745eb6cbd78","type":"ha-webhook","z":"6161d870e25ec591","g":"0ff2a23041167917","name":"get iphone charge status","server":"228d3d53.df8e02","version":1,"outputs":1,"webhookId":"iphoneCharging","outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"data"},{"property":"webhookPayload","propertyType":"msg","value":"","valueType":"data"}],"payloadLocation":false,"payloadLocationType":false,"headersLocation":false,"headersLocationType":false,"x":150,"y":540,"wires":[["29e4874b8d40526a"]]},{"id":"0e3a89dcb4cdc2eb","type":"api-current-state","z":"6161d870e25ec591","g":"0ff2a23041167917","name":"and i'm home","server":"228d3d53.df8e02","version":3,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","entity_id":"device_tracker.michael_montaques_iphone","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":160,"y":600,"wires":[["f5b4c5db2c38c9bf"],[]]},{"id":"29e4874b8d40526a","type":"switch","z":"6161d870e25ec591","g":"0ff2a23041167917","name":"if charging","property":"webhookPayload.isCharging","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"false","repair":false,"outputs":2,"x":350,"y":540,"wires":[["5ccf59b641caef15"],["0e3a89dcb4cdc2eb"]]},{"id":"5ccf59b641caef15","type":"time-range-switch","z":"6161d870e25ec591","g":"0ff2a23041167917","name":"6:01am - 8:59pm","lat":"","lon":"","startTime":"06:01","endTime":"20:59","startOffset":0,"endOffset":0,"x":550,"y":520,"wires":[["dfc3ad15d5aef4ef"],[]]},{"id":"f5b4c5db2c38c9bf","type":"time-range-switch","z":"6161d870e25ec591","g":"0ff2a23041167917","name":"time is between 9pm - 3am","lat":"","lon":"","startTime":"21:00","endTime":"6:00","startOffset":0,"endOffset":0,"x":440,"y":600,"wires":[["9fa93fa7bef49d81"],[]]},{"id":"9fa93fa7bef49d81","type":"link out","z":"6161d870e25ec591","g":"0ff2a23041167917","name":"Start Shutdown House","mode":"link","links":["5971b19995f175e4"],"x":790,"y":620,"wires":[],"l":true},{"id":"dfc3ad15d5aef4ef","type":"link out","z":"6161d870e25ec591","g":"0ff2a23041167917","name":"Start turning on the house","mode":"link","links":["ad27715b645e4615"],"x":810,"y":520,"wires":[],"l":true},{"id":"228d3d53.df8e02","type":"server","name":"Home Assistant","addon":true}]
iOS Device
The automation above is triggered via a webhook which we will run using an iPhone. The instructions below show how to set personal automation which triggers a webhook when the phone is connected to power.
Open the Shortcuts app and go to the Automation tab and click the + button
Tap Create Personal Automation
Choose Charger ➡ Is Connected ➡ Next
Add a new action and choose Get Current Focus
Now choose the If-statement next and set it to say If Current Focus has any value as the condition
Set the action for this condition to be Get Contents of URL
Add the url to your webhook. It will look like:[your-home-assistant0url/api/webhook/iphoneCharging]
Change the Method to POST
Request Body is a JSON with the key of isCharging equal to True
Now if you plug in your phone while your phone is in sleep mode and its between 9pm and 3am, this will trigger in home assistant where you can start any automation you like.