Smart Doorbell

logo

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.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 = states.get('{{presence}}') == ON\nif(presence) {\n  var startTime = new Date().getMilliseconds()\n  var oldLightState = states.get('{{light}}').toString()\n  if(oldLightState != '') {\n    var onState = ON\n    if(oldLightState.toString().contains(',')) onState = '0,100,100' // red as HSB\n    if(oldLightState != '') events.sendCommand('{{light', onState)\n  }\n  audio.playFile('doorbell.mp3')\n  var endTime = new Date().getMilliseconds()\n  if(endTime < startTime + 1000) {\n    java.lang.Thread.sleep(startTime + 1000 - endTime)\n  }\n  events.sendCommand('{{light}}', oldLightState)\n} else {\n  audio.playFile('barking.mp3')\n}"
      },
      "type": "script.ScriptAction"
    }
  ]
}
]
1 Like