# Configurable time trigger

**URL:** <https://community.homey.app/t/configurable-time-trigger/63532>\
**Category:** Ideas & Suggestions\
**Created:** [May 11, 2022, 7:04pm UTC](https://community.homey.app/t/configurable-time-trigger/63532 "2022-05-11T19:04:45Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![zakraket](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/zakraket/32/17470_2.png) [@zakraket](https://community.homey.app/u/zakraket)\
**Post date:** [May 20, 2022, 1:50pm UTC](https://community.homey.app/t/configurable-time-trigger/63532/9 "2022-05-20T13:50:47Z")

</div>

Could it be done with Better Logic, specifically the Mathjs cards?

Say I need to leave at 17:00, and my car needs 3 hours to charge to full (according to the car), I need the car to start charging at 14:00

I don’t really need to work with times; if I use numeric times, 1700 instead of 17:00, I can calculate (( **1700** \*60/100)-( **180** ))/0.6 = **1400**

I only need a flow that, f.e. every 5 minutes, converts current time to a number and if that number \> 1400, start charging.

I found $timenow$ to convert current time to a number, I basically need $timenow$ epoch - current date epoch (today 0:00 epoch) which gives me the numeric time to compare to 1400

Anyone know how?

edit: okay, found a solution using Better logic, need to test but I think this works

Calculate epoch for “today 0:00”  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/4/5484ee0b259570f9b8ea662615e679be573e2098.png)  
Maybe this can be done in the next step but I don’t know the Mathjs to get “today 0:00” epoch

Calculate epoch $timenow$ to current time (HH,MM) in **decimal** format  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/f/fff82fc4871f3492c8b548f827b12033b128c0e5.png)  
small error; /60 needs to be /60/0,6 to get a correct “decimal time”

Calculate startingtime based on current charging time left againts “leave time”  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/4/14350396bc58ab02604f4d60225a459dcc645d29.png)  
This updates every minute, so it gets updated when the car reports longer or shorter charging times

If “now” \> “starting time” then start charging

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/c/5c6367296d75047aa92b23427c4824955acff960.png)  
The **A3 Start Laden** flow checks for charging state, battery level, charging plug etc  
The second logic condition makes it possible to set a time earlier than iNowEpoch which results in “tomorrow”  
I disable flows 3 and 4 (and also some other flows, f.e. to stop charging when solar is low) to prevent things from running while car is forced to charge

If I change the Leavetime to 0 (outside 700-2200), this disables the previous flows or enables them

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/4/c4d6bc5e24b775097499b805b12fc41940454cec.png)

I reset the Leavetime to 0 when the car is fully charged, so when I need to leave, I only need to set the Leavetime to somewhere between 1-2359

---

_[View the full topic](https://community.homey.app/t/configurable-time-trigger/63532)._
