[SOLVED] Openhab linking items, create a sitemap and run script when doorbell is pushed

Thanks Dim. It works now

I installed VSCode thanks for the tip.

But now my Doorbel:

This is the item I created:

and this the thing:

And the rule is:

rule "Deurbel"

when                                                                                                                                                                                          
        Item Deurbel changed to ON                                                                                                                   
then                                                                                                                                                                                          
        executeCommandLine("sudo /etc/openhab2/scripts/deurbel.sh",10000)                                                                                 
end

And what is the problem with that rule?

1 Like

It doesn’t trigger the script. I ran it with openhab user and it runs fine.

And do you need sudo to execute that script?

Yes. I tried without but that didn’t work

Ok, can you post your script, please?

This is my script:

 #!/bin/sh
now=$(date +"%T")

SnapFile="/home/jeroen/Deurbel/frontdoorcam.mp4"    	# Temp name of the video, change it when using this script for multiple cams
VideoLength=5     													# Seconds to record
WaitTime=10       													# Seconds the script waits before it sends another video
User=admin         													# Username which has access to the RTSP stream
Password=i5oullQ6xHmy												# Password for above provided user
rtspUrl="rtsp://$User:$Password@192.168.1.32:88/videoMain"   		# Use https://sourceforge.net/projects/onvifdm/ to find your correct RTSP stream url
ChatID=-245000261  													# Telegram chat ID   See https://www.domoticz.com/wiki/Installing_Telegram_Notification_System for setup instructions
TelegramAPIToken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx		# Telegram API token

filedate=`stat -L --format %Y $SnapFile`
retc=$?
if [ $retc -eq 0 ] ; then
        sec=$(( `date +%s`-$filedate))
        echo file found and age is $sec seconds
else
        sec=999
        echo File not found $SnapFile
fi
if [ $sec -gt $WaitTime ] ; then    
        echo file older than $WaitTime seconds:  $sec sending video
        ffmpeg -y -i $rtspUrl -r 30 -vcodec copy -an -t $VideoLength $SnapFile
        curl -s -F chat_id=$ChatID -F video="@$SnapFile" -F caption="$De deurbel gaat.." https://api.telegram.org/bot$TelegramAPIToken/sendVideo
else
        echo There was another try within $WaitTime seconds: $sec
fi

But this one works fine. I tried it with openhab user, and the script worked

You are not running it with openhab user, you are running it with sudo.
Give sudo rights to openhab user for that script only

The script runs fine now. One problem. It;s a switch so it turns on but doesn’t turn off . How can I make a button of it.

What do you mean? In the sitemap?

I did this in paper UI > Control