From 76b76065585b96fcf985a14c8ff555288855f329 Mon Sep 17 00:00:00 2001
From: ccostan <carlo@ipm.com>
Date: Fri, 5 Jan 2018 14:45:57 -0500
Subject: [PATCH] Added in some Twitter, Alexa and Conditions to prevent double
 runs and some spacing.

---
 automation/away.yaml    |  5 +++++
 packages/skybellhd.yaml | 16 +++++++++-------
 packages/twitter.yaml   | 13 ++++++++-----
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/automation/away.yaml b/automation/away.yaml
index 7bf76cfb..9a81e293 100755
--- a/automation/away.yaml
+++ b/automation/away.yaml
@@ -10,6 +10,9 @@
     - platform: state
       entity_id: group.family
       to: 'not_home'
+    - platform: state
+      entity_id: input_boolean.good_night
+      to: 'on'
 
   condition:
     - condition: state
@@ -23,3 +26,5 @@
     - service: script.interior_off
     - service: switch.turn_off
       entity_id: switch.back_landscaping
+    - service: input_boolean.turn_off
+      entity_id: input_boolean.good_night
diff --git a/packages/skybellhd.yaml b/packages/skybellhd.yaml
index 7789ce6d..24db6ac8 100755
--- a/packages/skybellhd.yaml
+++ b/packages/skybellhd.yaml
@@ -74,15 +74,17 @@ automation:
        # - platform: event
        #   event_type: skybell_pressed
 
+    condition:
+      - condition: template
+        value_template: >
+          {%- if states.binary_sensor.skybell_stone_door_button.attributes.last_triggered -%}
+            {{ (as_timestamp(now()) - as_timestamp(states.binary_sensor.skybell_stone_door_button.attributes.last_triggered)) > 200 }}
+          {%- else -%}
+            true
+          {%- endif -%}
+
     action:
-      # Disable this automation
-      - service: automation.turn_off
-        entity_id: automation.log_skybell_pressed_activity
       - service: script.skybell_pressed
-      - delay:
-          minutes: 1
-      # enable this automation - This prevents duplicate pushes.
-      - service: automation.turn_on
       - service: script.tweet_engine
         data_template:
           tweet: >
diff --git a/packages/twitter.yaml b/packages/twitter.yaml
index 7c4838a1..afb709e8 100755
--- a/packages/twitter.yaml
+++ b/packages/twitter.yaml
@@ -123,10 +123,15 @@ automation:
         hours: '/4'
         minutes: 01
         seconds: 00
-
+    condition:
+      - condition: template
+        value_template: >
+          {%- if states.automation.random_house_stats.attributes.last_triggered -%}
+            {{ (as_timestamp(now()) - as_timestamp(states.automation.random_house_stats.attributes.last_triggered)) > 10000 }}
+          {%- else -%}
+            true
+          {%- endif -%}
     action:
-      - service: automation.turn_off
-        entity_id: automation.random_house_stats
       - delay: '0{{ range(0,2) | random | int }}:{{ range(10,59) | random | int }}:00'
       - service: script.tweet_engine
         data_template:
@@ -150,5 +155,3 @@ automation:
             "My @getspectrum internet download speed is about {{states.sensor.speedtest_download.state}} Mbit/s and I am a #cordcutter. @TabloTV",
             "Average Cloud Coverage: {{states.sensor.dark_sky_cloud_coverage.state}}%, Average Temp: {{states.sensor.dark_sky_temperature.state}}°F #Solar"
             ] | random + " #RandomStat"}}
-      - service: automation.turn_on
-        entity_id: automation.random_house_stats