# Countdown Timer in C#

**URL:** <https://extensions.streamer.bot/t/countdown-timer-in-c/190>\
**Category:** Approved\
**Tags:** obs, chat, youtube, twitch\
**Created:** [July 3, 2023, 6:14pm UTC](https://extensions.streamer.bot/t/countdown-timer-in-c/190 "2023-07-03T18:14:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rondhi](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/rondhi/32/24_2.png) [@rondhi](https://extensions.streamer.bot/u/rondhi)\
**Post date:** [July 3, 2023, 6:14pm UTC](https://extensions.streamer.bot/t/countdown-timer-in-c/190/1 "2023-07-03T18:14:08Z")

</div>

## Description

Run a count down or count up timer and display in OBS, on a Stream Deck, or check elapsed/remaining time via Chat Command. Timer works for Twitch, YouTube, and Kick

## Import Code

[timer\_v0.2.4.sb](https://extensions.streamer.bot/uploads/short-url/v3DxNyNoJP46Q8etu8d6TtzorMN.sb) (20.9 KB)

## Installation

1. Download the .sb file
2. In Streamer.bot in select `Import` from the top left.
3. Find the sb file you downloaded and drag and drop into the `Import String` box of the Import dialog

 ![image](https://extensions.streamer.bot/uploads/default/original/2X/d/dd9af65908e433c1e064b34a2d16a2d8cc653897.png)

Imported commands are disabled by default as a security measure. Review each command’s permissions before enabling each one.

### In OBS

1. Add a scene called `[NS] Timer`
2. In the scene `[NS] Timer`, add a Text Source called `[TS] Timer`

You can add the scene `[NS] Timer` as a source in any scene you want to display the timer.

## Configuration

### Settings

Settings are located in the `Timer Settings` action.

 ![image](https://extensions.streamer.bot/uploads/default/original/2X/b/b89a92fda76733c281b6e5575d378a3bb820aef3.png)

| OBS Settings | Default Value | Description |
| --- | --- | --- |
| `timerCountdownObsConnection` | `0` | The index of your OBS connection you will use for displaying the timer in OBS |
| `timerCountdownScene` | `[NS] Timer` | Match the name of the nested scene created to display the timer text source |
| `timerCountdownSource` | `[TS] Timer` | Match the name of the text source created to display the timer |

| Chat Settings | Default Value | Description |
| --- | --- | --- |
| `sendAsBot` | `True` | Any actions using the `SendMessageToPlatformAction` method will use this to decide to send a message as the bot account or not |
| `sendAllPlatforms` | `True` | Any actions using the `SendMessageToPlatformAction` method will use this to send a message to all platforms that have used the timer actions (Twitch, YouTube, Trovo) |

| (Optional) Stream Deck Settings | Default Value | Description |
| --- | --- | --- |
| `streamDeckTimer` | `False` | Set to true if you want to update a Stream Deck button with the remaining time in the timer |
| `streamDeckButtonId` | `` | Set to the button ID of your Stream Deck button. You can get this by going to your Stream Deck application, creating a Streamer.bot Action button, and clicking the copy icon next to the Button ID. |

- If you want to be able to start the timer from the Stream Deck Button, assign the action to the `Timer Start` action, then add an argument with settings:

| Type | Name | Value |
| --- | --- | --- |
| String | value | _Number of minutes to set the timer to start_ |

 ![image](https://extensions.streamer.bot/uploads/default/original/1X/58fc2cadf369ba0935942b85a6a92ea66fcfe95f.png)

### Other actions with configuration

These settings apply to these actions: `Timer Cancel`, `Timer Pause`, and `Timer Done`

- Under Chat Settings, set argument `message` to what you want to send to chat
- Under OBS, set argument `obsText` to what you want to display in the OBS Text Source

 ![image](https://extensions.streamer.bot/uploads/default/original/2X/a/a88cd14e7af930f277ac2b6d02296512878d0c09.png)

## Commands

Imported commands are disabled by default as a security measure. Review each command’s permissions before enabling each one.

| Command | Action | Usage | Explanation |
| --- | --- | --- | --- |
| !timer | Timer Configuration and Start | `!timer duration` | Makes timer visible and starts the timer to the number specified in the command. You can use `!timer -0.02` if you want the timer to count up. |
| !timeradd | TimerAdd X Minutes | `!timeradd duration` | Adds your desired number of minutes to the timer. |
| !timercancel | Timer Cancel | `!timercancel` | Stops the timer, then hides the text source. Must type it in twice to confirm. |
| !timerpause | Timer Pause | `!timerpause` | Pause the timer |
| !timerresume | Timer Resume | `!timerresume` | Resume the timer |
| !timerelapsed | Timer Check Elapsed | `!timerelapsed` | This will display the elapsed time in Twitch chat |
| !timerremaining | Timer Check Remaining | `!timerremaining` | This will display the remaining time in Twitch chat |
| !timershow | Timer Countdown Action Group Enable | `!timershow` | This will make the text source visible in OBS |
| !timerhide | Timer Countdown Action Group Disable | `!timerhide` | This will make the text source hidden in OBS |

Duration can use the following syntax:  
`d for days, h for hours, m for minutes, s for seconds`  
Examples: `5d4h3m`, `1h30m`, `5m`, `1h`  
`1h30m` or `90m` should also work as equivalents.  
A timer value set to `up` will initiate a count up timer instead of countdown. Which then needs to be cancelled manually.

---

<div class="post-metadata">

**Author:** ![rondhi](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/rondhi/32/24_2.png) [@rondhi](https://extensions.streamer.bot/u/rondhi)\
**Post date:** [March 23, 2024, 3:23pm UTC](https://extensions.streamer.bot/t/countdown-timer-in-c/190/2 "2024-03-23T15:23:45Z")

</div>

Refactored some of the code for v0.2.3. I’ve only tested it with my own build, so reply if something is not working.

---

<div class="post-metadata">

**Author:** ![rondhi](https://extensions.streamer.bot/user_avatar/extensions.streamer.bot/rondhi/32/24_2.png) [@rondhi](https://extensions.streamer.bot/u/rondhi)\
**Post date:** [March 27, 2024, 7:02am UTC](https://extensions.streamer.bot/t/countdown-timer-in-c/190/3 "2024-03-27T07:02:17Z")

</div>

Fixed some bugs. Added a way to configure the way some actions change the timer display in OBS (timer cancel, timer pause, timer done).
