# 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:** 19

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [June 13, 2022, 12:19am UTC](https://community.homey.app/t/configurable-time-trigger/63532/19 "2022-06-13T00:19:56Z")

</div>

Got something 😉

- Flow 1 - Convert departure time to numeric time  
(To be able to enter the departure time as normal time 00:00 format)

.

- Script:

```auto
// convertTime2NumericTime.js - Convert time to Numeric time (like: 15:30h -> 1550)

let timeIn = args[0]
let timeNumeric = 0;

if (timeIn == '' || timeIn == undefined) {
    console.log ('Missing argument');
    return(false);
} else {
  // If the hour is 1 - 9, add a leading 0 so time is formatted as f.i. 09:30
  var charCount = Array.from(timeIn.toString()).length;
  if (charCount < 5) {
    timeIn = "0" + timeIn;
  }

  // Split the hours and minutes
  hours = timeIn.slice(0,2);
  minutes = timeIn.toString().slice(-2);

  // Converting from minutes to Numeric hours
  hoursNumeric = Math.round(minutes / 0.6 ,0);
    // In case result = 0 -> make sure minutes are displayed as 00
  if (hoursNumeric < "1") {
    hoursNumeric = hoursNumeric + "0";
  }

  timeNumeric = hours + hoursNumeric;
  
  // Update Logics stringVar AB.timeNumeric
 await Homey.logic.updateVariable({id: 'Variable_ID_here', variable: { value: timeNumeric } });

}

return(true);

```

.

- Flow 2 - When numeric time “Start Charging time” changed, convert it to normal time format 00:00

.

- Script:

```auto
// convertNumeric2NormalTime.js - Convert numeric time to normal time (like: '1550' -> 15:30)

let timeNumeric = args[0]

// make sure timeNumeric it has no digits, round to zero digits
timeNumeric = Math.round(timeNumeric ,0)

let timeNormal = 0;

if (timeNumeric == '' || timeNumeric == undefined) {
    console.log ('Missing argument');
    return(false);
} else {
  // If the hour is 1 - 9, add a leading 0
  var charCountHrs = Array.from(timeNumeric.toString()).length;
  if (charCountHrs < 4) {
    timeNumeric = "0" + timeNumeric;
  }
  // Split the hours and numeric hours
  hours = timeNumeric.toString().slice(0,2);
  hoursNumeric = (timeNumeric).toString().slice(-2);
  // change f.i. 25 to 0.25
  hoursNumeric = hoursNumeric / 100;
  // converting from Numeric hours to minutes
  minutes = Math.round(hoursNumeric * 60 ,0);

  // In case result = 1 digit, then make sure minutes are displayed as 0x
  if (minutes < 10) {
    minutes = "0" + minutes;
  }

  timeNormal = hours + ":" + minutes;
 
  // Update Logics stringVar AB.timeNormal
  await Homey.logic.updateVariable({id: 'Variable_ID_here', variable: { value: timeNormal } });

}

return(true);

```

.

- Variables:  
The ones starting with “A.” are the ones to edit or readout  
 ![Screenshot from 2022-06-13 04-06-13](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/2/a27d58b8cc61a2ef364cb1a7e61ccaf6afc51102.png)  
.  
The ones starting with “AB.” are the other used Vars:  
 ![Screenshot from 2022-06-13 04-06-54](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/c/5c73aa5b7f5ba7b6a1ac8f4550f8d8fbcfae6e10.png)

.

- Finding a variable ID & its details:

```auto
// Replace MyVar with your variable name
let varName = "MyVar"

const logicVars = await Homey.logic.getVariables()
for (var iLogicVar in logicVars){
  if (logicVars[iLogicVar].name == varName)
  log("Variable: " + logicVars[iLogicVar].name + "\nType:\t " + logicVars[iLogicVar].type + "\nValue:\t " + logicVars[iLogicVar].value + "\nID:\t " + logicVars[iLogicVar].id)
}

```

---

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