From 06bab7092bf301948a5ebf8bbf9a6b41d1fcf7a6 Mon Sep 17 00:00:00 2001
From: ccostan <carlo@ipm.com>
Date: Sun, 8 Apr 2018 15:48:42 -0400
Subject: [PATCH] Closes #318 - Added in FOSCAM motion sensors.

---
 config/.HA_VERSION          |  2 +-
 config/group/motion.yaml    |  3 ++
 config/packages/foscam.yaml | 88 +++++++++++++++++++++++++++++++++++++
 config/travis_secrets.yaml  |  3 ++
 4 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100755 config/packages/foscam.yaml

diff --git a/config/.HA_VERSION b/config/.HA_VERSION
index 367d4880..d3072c43 100755
--- a/config/.HA_VERSION
+++ b/config/.HA_VERSION
@@ -1 +1 @@
-0.66.0
\ No newline at end of file
+0.66.1
\ No newline at end of file
diff --git a/config/group/motion.yaml b/config/group/motion.yaml
index aa3b0c8d..6f165094 100755
--- a/config/group/motion.yaml
+++ b/config/group/motion.yaml
@@ -4,3 +4,6 @@ motion:
     - binary_sensor.office_motion
     - binary_sensor.entry_alarm_panel
     - binary_sensor.bedroom_alarm_panel
+    - binary_sensor.camera1_motion_sensor
+    - binary_sensor.camera2_motion_sensor
+    - binary_sensor.camera3_motion_sensor
diff --git a/config/packages/foscam.yaml b/config/packages/foscam.yaml
new file mode 100755
index 00000000..19c3388f
--- /dev/null
+++ b/config/packages/foscam.yaml
@@ -0,0 +1,88 @@
+#-------------------------------------------
+# @CCOSTAN
+# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
+#-------------------------------------------
+# homeassistant:
+#   customize_glob:
+#     "*.*_sleep_hours":
+#       unit_of_measurement: hours
+#       icon: mdi:sleep
+#
+#       hidden: False
+#-------------------------------------------
+binary_sensor:
+  - platform: rest
+    name: "CAMERA1 Motion Sensor"
+    resource: !secret camera1_url
+    device_class: motion
+    scan_interval: 5
+    value_template: >-
+      {%- if "<motionDetectAlarm>2</motionDetectAlarm>" in value -%}
+        {{ true }}
+      {%- else -%}
+        {{ false }}
+      {%- endif -%}
+  - platform: rest
+    name: "CAMERA2 Motion Sensor"
+    resource: !secret camera2_url
+    device_class: motion
+    scan_interval: 5
+    value_template: >-
+      {%- if "<motionDetectAlarm>2</motionDetectAlarm>" in value -%}
+        {{ true }}
+      {%- else -%}
+        {{ false }}
+      {%- endif -%}
+  - platform: rest
+    name: "CAMERA3 Motion Sensor"
+    resource: !secret camera3_url
+    device_class: motion
+    scan_interval: 5
+    value_template: >-
+      {%- if "<motionDetectAlarm>2</motionDetectAlarm>" in value -%}
+        {{ true }}
+      {%- else -%}
+        {{ false }}
+      {%- endif -%}
+#-------------------------------------------
+# Motion Sensors added to other motion sensors in group yaml
+
+##############################################################################
+###  Automations - Detect when things are not right. Like any Good Watchdog.
+##############################################################################
+#automation:
+#Tweets pushed out to twitter.
+# automation:
+#   - alias: Someone on the MC server!
+#     trigger:
+#       - platform: state
+#         entity_id: sensor.bear_stone
+#
+#     action:
+#       - service: light.turn_on
+#         entity_id: light.justin_go
+#         data_template:
+#           color_name: >
+#             {% if states.sensor.bear_stone.state|int == 1 %}
+#               gold
+#             {% elif states.sensor.bear_stone.state|int == 2 %}
+#               green
+#             {% elif states.sensor.bear_stone.state|int == 3 %}
+#               blue
+#             {% else %}
+#               red
+#             {% endif %}
+#
+#       - service_template: >
+#             {% if states.sensor.bear_stone.state|int > 0 %}
+#               light.turn_on
+#             {% else %}
+#               light.turn_off
+#             {% endif %}
+#         entity_id: light.justin_go
+#
+#       - service: light.turn_on
+#         entity_id:
+#           - light.justin_go
+#         data:
+#           flash: short
diff --git a/config/travis_secrets.yaml b/config/travis_secrets.yaml
index 4e74e911..70fb30f5 100755
--- a/config/travis_secrets.yaml
+++ b/config/travis_secrets.yaml
@@ -10,6 +10,9 @@ ssl_certificate: 'www_traviswebsite_dot_com.fake_crt'
 ssl_key: 'www_traviswebsite.fake_key'
 http_base_url: your.website.com
 ifttt_key: iftttKEYPassphrase
+camera1_url: http://192.168.10.21:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=admin&pwd=password
+camera2_url: http://192.168.10.22:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=admin&pwd=password
+camera3_url: http://192.168.10.23:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=admin&pwd=password
 forecast_key: ForcastKeyphrase
 fitbit_user: User@email.com
 fitbit_password: abcdefghijklmnopqrstuvwxyz0123456789