This templates takes a binary input from a push button and plays either a doorbell sound on a connected speaker or uses a dog barking sound to scare away any visitors if nobody is at home.
Additionally, a light can be flashed as a visual notification mechanism while playing the sound.
Changelog
Version 0.3
- adapted to new Javascript core library (by @kai)
Version 0.2
- adapted to the Community Marketplace (by @ysc)
Version 0.1
- initial release to the Eclipse Marketplace (by @kai).
Resources
[
{
"uid":"kaikreuzer:smartdoorbell",
"label":"Smart Doorbell",
"description":"Rings the doorbell or scares away people.",
"configDescriptions":[
{
"name":"doorbell",
"type":"TEXT",
"context":"item",
"filterCriteria":[
{
"name": "type",
"value": "Switch"
}
],
"label":"Doorbell",
"description":"The push button of the doorbell",
"required":true
},
{
"name":"presence",
"type":"TEXT",
"context":"item",
"filterCriteria":[
{
"name": "type",
"value": "Switch"
}
],
"label":"Presence information",
"description":"The switch that signals presence at home.",
"required":true
},
{
"name":"light",
"type":"TEXT",
"context":"item",
"filterCriteria":[
{
"name": "type",
"value": "Switch,Dimmer,Color"
}
],
"label":"Light to flash",
"description":"The light to flash (optional)",
"required":false
}
],
"triggers": [
{
"id": "1",
"label": "button is pressed",
"description": "",
"configuration": {
"itemName": "{{doorbell}}",
"state": "ON"
},
"type": "core.ItemStateUpdateTrigger"
}
],
"conditions": [],
"actions": [
{
"inputs": {},
"id": "2",
"label": "ring doorbell or bark",
"description": "Plays a doorbell sound and flashes the light if at home.\nPlays a dog barking sound if not at home.",
"configuration": {
"type": "application/javascript",
"script": "var presence = (items.{{presence}}.state == 'ON')
if(presence) {
var startTime = new Date().getMilliseconds()
var oldLightState = items.{{light}}.state
if(oldLightState != '') {
var onState = 'ON'
if(oldLightState.toString().contains(',')) onState = '0,100,100' // red as HSB
if(oldLightState != '') items.{{light}}.sendCommand(onState)
}
actions.Audio.playSound('doorbell.mp3')
var endTime = new Date().getMilliseconds()
if(endTime < startTime + 1000) {
java.lang.Thread.sleep(startTime + 1000 - endTime)
}
items.{{light}}.sendCommand(oldLightState)
} else {
actions.Audio.playSound('barking.mp3')
}"
},
"type": "script.ScriptAction"
}
]
}
]