# Time calculation from sun down time to end time to show seconds countdown for turn off lights and show time on dashboard

**URL:** <https://community.homey.app/t/time-calculation-from-sun-down-time-to-end-time-to-show-seconds-countdown-for-turn-off-lights-and-show-time-on-dashboard/96134>\
**Category:** Questions & Help\
**Tags:** app, dashboard, homey-pro, local-time\
**Created:** [November 28, 2023, 7:43pm UTC](https://community.homey.app/t/time-calculation-from-sun-down-time-to-end-time-to-show-seconds-countdown-for-turn-off-lights-and-show-time-on-dashboard/96134 "2023-11-28T19:43:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Kevin\_Ponsen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/kevin_ponsen/32/92414_2.png) [@Kevin\_Ponsen](https://community.homey.app/u/Kevin_Ponsen)\
**Post date:** [November 29, 2023, 4:07pm UTC](https://community.homey.app/t/time-calculation-from-sun-down-time-to-end-time-to-show-seconds-countdown-for-turn-off-lights-and-show-time-on-dashboard/96134/3 "2023-11-29T16:07:48Z")

</div>

thanks for you reply after 2 hours of trying i found a solution with excuteable code ect

My flow

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

First (voer // get the current time date and time)

```auto
// Get the current date and time
var currentDate = new Date();
var currentTimeInSeconds = Math.round((currentDate.getHours() * 3600) + currentDate.getMinutes() * 60) + (currentDate.getSeconds());

// Set the result in a Homey variable of type number
setTagValue("Tijd Nu", {type: "number", title: "Tijd Nu"}, currentTimeInSeconds);

// Log the result (optional)
console.log("Current Time in Seconds: " + currentTimeInSeconds);

```

Second (Voer // Define the time in hours and minutes)

```auto
// Define the time in hours and minutes
var weekhours = 22;
var weekminutes = 30;
var weekendhours = 00;
var weekendminutes = 30;

// Calculate the total seconds
var totalSecondsweek = (weekhours * 3600) + (weekminutes * 60);
var totalSecondsweekend = (weekendhours * 3600) + (weekendminutes * 60);

setTagValue("Tijd Week", {type: "number", title: "Tijd Week"}, totalSecondsweek);
setTagValue("Tijd Weekend", {type: "number", title: "Tijd Weekend"}, totalSecondsweekend);

// Log the result (optional)
console.log("22:30 in seconds: " + totalSecondsweek);
console.log("00:30 in seconds: " + totalSecondsweekend);

```

ALERT this is the normal time (no winter time for dutch)  
if you need this you have to add 3600 sec somewhere you want

i hope someone can use it good luck all

result  
 ![dashboard](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/7/f7e78057239f24fe3135c3f1d82b3b92eec5dd62.gif)

---

_[View the full topic](https://community.homey.app/t/time-calculation-from-sun-down-time-to-end-time-to-show-seconds-countdown-for-turn-off-lights-and-show-time-on-dashboard/96134)._
