Page 1 of 1

“Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Tuesday 12 January 2021 21:32
by najtram
If you have iOS (14!) devices and you always charge at night time this works.

Quick and dirty description:
In domoticz create dummy switch for “phone charging” and lookup the idx.

In iOS app shortcuts create an personal automation for when cable connects. In the automation create an action to get URL headers. Give url as: http://IP:PORT/json.htm?type=command&param=switchlight&idx=IDX&switchcmd=On
(replace CAPS to yours).
Uncheck “Ask before tuning”
And run and help first time and give permissions to uppopping dialogs. After this it can run automaticly.

Repeat iOS process for “cable disconnects” and use “Off” in end of url.

With an additional dummy switch and a blockly event you could filter if charging starts after your avarage bedtime. (To filter out extra charge moments at daytime).

Best to use internal ip adress to only start domoticz automation based on dummy switches when your at home. (So no automation happens when away).


Let me know what you think of it. :roll:

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Thursday 04 February 2021 7:13
by krizzz
What is the additional benefit of having an “iPhone is charging” device in Domoticz? I don’t get it.


Verzonden vanaf mijn iPhone met Tapatalk

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Thursday 04 February 2021 9:08
by najtram
I've seen people creating complex things to detect if a bed is occupied. (Example: https://medium.com/@qz_li/smart-bed-7de9ad55276e)
This creates the possibility to automate actions based on the assumption that when (in my case two) iPhones are charging after an avarage bedtime, we are in bed. So this could trigger actions like switching scenes, or setting up alarm.

The above description is a proof of concept of a (IMHO) simpler method than the medium post.

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Thursday 04 February 2021 10:19
by kiddigital
Nice idea

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Thursday 04 February 2021 10:29
by krizzz
najtram wrote:I've seen people creating complex things to detect if a bed is occupied. (Example: https://medium.com/@qz_li/smart-bed-7de9ad55276e)
This creates the possibility to automate actions based on the assumption that when (in my case two) iPhones are charging after an avarage bedtime, we are in bed. So this could trigger actions like switching scenes, or setting up alarm.

The above description is a proof of concept of a (IMHO) simpler method than the medium post.
Got it!


Verzonden vanaf mijn iPhone met Tapatalk

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Thursday 04 February 2021 15:07
by Treve
Thank you for this description, it works well.
when the status changes, I get a notification via Safari, can this be turned off?

Can I use the same command line with a different IDX for arrival and departure in the iOS app shortcuts?

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Thursday 04 February 2021 15:20
by najtram
Not sure what you mean, did you use the action called URL headers (I think) → In dutch "Haal kopteksten van URL op" (I'm sure!)
And, as said, use/help it first times. After this it's automated. (Be sure to uncheck the last option in iOS).

Leave/arrive at home isn't possible in iOS shortcuts AFAIK. Not all actions in iOS can run stand alone. This description is based on the cable connect trigger, which can run without user interaction.

There might be a workaround if you always use carplay when you leave. (But that doens't fit my usage).

Triggers can be read here: https://9to5mac.com/2020/06/23/ios-14-s ... ders-more/

PS I use the app Pilot to achieve geofencing.

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Friday 05 February 2021 11:33
by Treve
I used (in Dutch) 'Open URLs' and turned off 'prompt to execute', Unchecked “Ask before tuning”, then allowed automatic execution at first startup.
All this works fine, but as soon as I plug in the charger, Safari get me the message,
{
"status" : "OK",
"title" : "SwitchLight"
}

Is this message normal or have I made a mistake somewhere? the switch in Domoticz has been switched from Off to On.
So technically it works

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Friday 05 February 2021 11:41
by najtram
Ok, then you should use the action with the name "Haal kopteksten van URL op" instead of "Open URL's"

That should work! Let me know.

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Friday 05 February 2021 12:49
by Treve
Yes, it works perfectly.
Thanks for your help

Re: “Sleep/bed” switch (if you charge an iOS14 device at night)

Posted: Friday 05 February 2021 17:25
by lost
kiddigital wrote: Thursday 04 February 2021 10:19 Nice idea Image
Charging lithium batteries every night? Can be, if you're really confident with your smoke detectors!