Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Underknowledge/e35f7c704ce8f081103b57356e54b2ba to your computer and use it in GitHub Desktop.
Save Underknowledge/e35f7c704ce8f081103b57356e54b2ba to your computer and use it in GitHub Desktop.
Home Assistant telegram gif
configuration.yaml
```
homeassistant:
packages: !include_dir_named packages
whitelist_external_dirs:
- /config/ffmpeg/
```
cam.sh
```
#!/bin/bash
date
folder=/share/ffmpeg
id=$(date +"%y-%m-%d_%H-%M-%S")
mpeg_url_opx=http://user:password@10.150.2.1:8080/video?profile=0
duration=5
bitrate=2048k
codec=libx264
filesize=2048k
echo "$id.mp4" >/config/ffmpeg/file.txt
ffmpeg -y -i $mpeg_url_opx -t $duration -b:v $bitrate -vcodec $codec -fs $filesize $folder/$id.mp4
echo "1" >/config/ffmpeg/done.txt
find $folder -type f -name '*.mp4' -mtime +30 -exec rm {} \;
sleep 20s
echo "0" >/config/ffmpeg/done.txt
```
camera_package.yaml
```
shell_command:
ipcam_sh: bash -x /config/shell_scripts/cam.sh >> /share/ipcam2.log 2>&1
ffmpeg:
sensor:
- platform: file
name: cam_file
file_path: /config/ffmpeg/file.txt
- platform: file
name: cam_done
file_path: /config/ffmpeg/done.txt
automation:
- alias: schicke gifs
initial_state: on
trigger:
platform: state
entity_id: binary_sensor.mija_keller
from: 'off'
to: 'on'
action:
- service: shell_command.ipcam_sh
- wait_template: "{{ is_state('sensor.cam_done', '1') }}"
timeout: '00:00:40'
continue_on_timeout: 'true'
- service: telegram_bot.send_video
data_template:
file: /config/ffmpeg/{{ states('sensor.cam_file')}}
- service: telegram_bot.send_message
data_template:
target: 'XXXXXXXXXX'
message: " Stand: {{ states('sensor.cam_file')}} gesendet: {{now().strftime('%H:%M:%S %Y-%m-%d')}}."
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment