Skip to content

Commit

Permalink
Added new setup method, more error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSleeps committed Feb 15, 2024
1 parent de85e6b commit 5c59d68
Show file tree
Hide file tree
Showing 27 changed files with 2,073 additions and 635 deletions.
Empty file removed .offline
Empty file.
94 changes: 56 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,53 @@
# Frigate Timelapser
## Frigate Timelapser

This is a node app that helps generate timelapse videos from a Frigate feed. It takes a snapshot every few seconds and when called will create a timelapse of the last 15 seconds.
This is a node app that helps generate timelapse videos from a Frigate feed. It takes a snapshot every few seconds and when called will create a timelapse of the last 15 seconds.

## Why did I write this?
## Why did I write this?

Because at the time Frigate didn't have a timelapse function and I find the one that it currently has clunky and unreliable. I wanted something that I could easily call from Home Assistant and it generate a video when, for example, my front door opens.
Because at the time Frigate didn't have a timelapse function and I find the one that it currently has clunky and unreliable. I wanted something that I could easily call from Home Assistant and it generate a video when, for example, my front door opens.

It's very much a work in progress and has next to no error checking. It does however work, I've been using it for a about a year, sending videos to my telegram via Home Assistant.


## How to get it running..

You can run it locally via node (and maybe PM2) or via Docker.

## Running locally.

Clone the repo:

```plaintext
git clone https://github.com/MrSleeps/FrigateTimelapser.git
cd FrigateTimelapser
```

Run `npm install` and wait for it to finish, once it's done it's business you need to edit your frigate.env file (scroll down for more information). Once your timelapse.env file is created you start the Timelapser by either of the following commands:

```plaintext
npm start
```

or

```plaintext
node server.js
```

### Docker install

You can either build it yourself or grab it from DockerHub.

If you are building it yourself:

```bash
```plaintext
git clone https://github.com/MrSleeps/FrigateTimelapser.git
cd FrigateTimelapser
./build
```
Once it's built (hopefully without errors), or you are grabbing it direct from DockerHub, you need to copy the docker-compose file below and make the relevant changes

Once it's built (hopefully without errors), or you are grabbing it direct from DockerHub, you need to copy the docker-compose file below and make the relevant changes

```bash
```plaintext
version: '3.6'
services:
Expand All @@ -45,77 +64,76 @@ services:

Before running you will need to do a few things, create a directory called files (or whatever) and update this line:

```bash
```plaintext
- ${PWD}/files:/app/files
```

Replacing ```${PWD}/files``` with whatever directory you created.
Replacing `${PWD}/files` with whatever directory you created.

Next you need to create your .env file. Create a file called timelapse.env and copy and paste the following (modifiy for your own setup):

```bash
```plaintext
# The URL of this docker (ex: https://frigate-timelapse.yourhost.tld)
# No / at the end please!
timelapseURL = "http://your.host"
timelapsePort = "8500"
# Comma seperated list of your cameras, no spaces please!
cameras = "camera1,camera2,camera3"
# The URL of your frigate install
frigateBaseURL = "https://your.frigate.url"
setLapseSeconds = 30
# The URL of your Home Assistant
homeAssistantURL = "https://your.homeassistant.url"
# Your Home Assistant API Token
homeAssistantToken = "Your Home Asssitant API Token"
postToHomeAssistant = 1;
```

Change ```timelapseURL``` to whatever url you will be using (if behind a proxy use the proxy address).
Change `timelapseURL` to whatever url you will be using (if behind a proxy use the proxy address).

**If you change ```timelapsePort``` remember to update your docker-compose.yml file!**
**If you change** `timelapsePort` **remember to update your docker-compose.yml file!**

Modify ```cameras``` by creating a comma seperated list of your cameras that you want the Timelapser to access, these cannot (currently) have spaces in the names and must match the name that Frigate knows them as.
Once that's all done, update the line in docker-compose.yml

Change ```frigateBaseURL``` to whatever url your Frigate setup uses.

If you plan to use Home Assistant to grab the timelapses you will need to add your Home Assistant url to ```homeAssistantURL```. Then you need to set up a webhook and paste the last bit in to ```homeAssistantToken``` (the bit after /webhook/). I'll post some examples of how mine works with Home Assistant at a later date.

Once that's all done, update the line in docker-compose.yml

```
```plaintext
- ${PWD}/timelapse.env:/app/.env
```

with the location of your timelapse.env file.

Save

Then run

```
```plaintext
docker-compose up -d
```

If all goes to plan Frigate Timelapser will be up and running and listening at your.host:8500

When you first visit Frigate Timelapser it will run you through a few setup questions, you will need to enter the following:

**Frigate URL** - This is fairly self explanatory, enter in the format http://your.host.tld (**no trailing /**)

**Frigate Cameras** - Enter your cameras, seperate cameras by a comma. For example ```camera1,camera2,camera3```

If you are using the Home Assistant post back doobrie you will need to fill out the following two fields:

**Home Assistant URL** - Again, self explanatory and **no trailing slashes**.

**Home Assistant Webhook ID** - You can find this in your Home Assistant, under automations->triggers->webhooks. It'll give you the ID and paste it here.

Click save and off you go!

## Generating a timelapse

If you want to generate a timelapse you need to call (via a GET call) the url /:camera/timelapse/:hass/:json with the variables changed. What you set will generate different views.
If you want to generate a timelapse you need to call (via a GET call) the url **/:camera/timelapse/:hass/:json** with the variables changed. What you set will generate different views.

Start with the variables..

**:camera** is the name of your camera, office for example
**:hass** is if you are calling it from Home Assistant
**:camera** is the name of your camera, office for example
**:hass** is if you are calling it from Home Assistant
**:json** if you would like a json reply

The **:hass** option generates the video and then returns via POST to your Home Assistant URL that you set in the timelapse.env file. I use this to then send a copy of the timelapse on to my Telegram account
The **:hass** option generates the video and then returns via POST to your Home Assistant URL that you set in the timelapse.env file. I use this to then send a copy of the timelapse on to my Telegram account
The **:json** option decides if you want a json reply with the url of the timelapse or you actually want to view it on the website. **1** returns json and **2** returns a webpage with the video embeded.

So for example, to generate a timelapse manually from a camera called "frontdoor" and watch it via your phone you would visit http://your.host.tld:8500/frontdoor/timelapse/0/0

If you were calling it from Home Assistant and wanted to get a copy of the timelapse sent back to Home Assistant you would visit http://your.host.tld:8500/frontdoor/timelapse/1/0

And finally, if you wanted to return a json which you can use in some other webpage/script/whatever you'd call http://your.host.tld:8500/frontdoor/timelapse/0/1 which would return json like: ```{"action":"finishedTimelapse","filename":"frontdoor/2024-02-12-02-55-06.mp4","camera":"frontdoor"}```
And finally, if you wanted to return a json which you can use in some other webpage/script/whatever you'd call http://your.host.tld:8500/frontdoor/timelapse/0/1 which would return json like: `{"action":"finishedTimelapse","filename":"frontdoor/2024-02-12-02-55-06.mp4","camera":"frontdoor"}`

Generating the timelapse takes some time, it's not an instant thing. Obviously the faster the host system is the quicker it will be.

It's very much written for my needs and as such will have bugs (and zero error checking), suggestions/problems in "Issues" here on Github.
It's very much written for my needs and as such will have bugs (and zero error checking), suggestions/problems in "Issues" here on Github.
11 changes: 0 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,3 @@ PACKAGE_VERSION=$(cat package.json \

echo Building Timelapser v$PACKAGE_VERSION
docker build -t mrsleeps/frigate-timelapser .
#echo "What is the version number?"
#read versionNumber
docker images | grep frigate-timelapser
echo "What is the docker hash?"
read dockerHash
dockerString="docker tag ${dockerHash} mrsleeps/frigate-timelapser:${PACKAGE_VERSION}"
dockerPushOne="docker push mrsleeps/frigate-timelapser:${PACKAGE_VERSION}"
dockerPushTwo="docker push mrsleeps/frigate-timelapser:latest"
eval $dockerString
eval $dockerPushOne
eval $dockerPushTwo
12 changes: 6 additions & 6 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const dotenv = require('dotenv');
dotenv.config();
var config = {};
const cameras = process.env.cameras.split(",");
//const cameras = process.env.cameras.split(",");
config.listenPort = process.env.timelapsePort;
config.cameras = cameras;
config.frigateBaseURL = process.env.frigateBaseURL;
//config.cameras = cameras;
//config.frigateBaseURL = process.env.frigateBaseURL;
config.setLapseSeconds = process.env.setLapseSeconds;
config.imageSaveDir = "images/";
config.videoSaveDir = "videos/";
config.httpOrHttps = "http";
config.timeLapseDir = "time-lapse-vids";
config.timeLapseURL = process.env.timeLapseURL;
config.homeAssistantURL = process.env.homeAssistantURL;
config.homeAssistantToken = process.env.homeAssistantToken;
config.postToHomeAssistant = process.env.postToHomeAssistant;
//config.homeAssistantURL = process.env.homeAssistantURL;
//config.homeAssistantToken = process.env.homeAssistantToken;
//config.postToHomeAssistant = process.env.postToHomeAssistant;
module.exports = config;
1 change: 1 addition & 0 deletions data/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"needsSetup":1,"frigateURL":"https://your.frigate.host","frigateCameras":"camera1,camera2,camera3","hassURL":"https://your.hass.host","hassWebhookInput":"","usingHomeAssistant":0}
1 change: 1 addition & 0 deletions data/config.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"needsSetup":1,"frigateURL":"https://your.frigate.host","frigateCameras":"camera1,camera2,camera3","hassURL":"https://your.hass.host","hassWebhookInput":"","usingHomeAssistant":0}
Binary file added data/timelapser.db
Binary file not shown.
Binary file added data/timelapser.db.orig
Binary file not shown.
67 changes: 57 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c59d68

Please sign in to comment.