From d7d094622766dba4d45b415b43bd37de0c6dffda Mon Sep 17 00:00:00 2001 From: Jeffrey Stone Date: Wed, 13 Nov 2019 20:55:04 -0500 Subject: [PATCH] More twitter engine cleanup. Think I have it mostly settled now --- config/automations.yaml | 146 ++++++++++++++----------- config/packages/notify.yaml | 154 +-------------------------- config/packages/twitter.yaml | 94 +++++++++++----- config/packages/usps.yaml | 14 ++- config/templates/twitter_new_ha.yaml | 10 +- 5 files changed, 169 insertions(+), 249 deletions(-) diff --git a/config/automations.yaml b/config/automations.yaml index 80c5488..ea0608a 100644 --- a/config/automations.yaml +++ b/config/automations.yaml @@ -86,13 +86,16 @@ at: 05:00:00 action: - service: shell_command.backup - - service: script.twitter_notify + - service: script.twitter_notify_image data_template: - message: '{{ [ "I just kicked off a backup of #homeassistant to ensure I live - on. Do you backup? ", "Its important to backup your data. Thats why I just - intitiated a backup of my critical data. ", "With @home_assistant and the - #dropbox component it is easy to backup your important config files. Lets - do this thing! " ] | random }}' + tweet: >- + {{ [ + "I just kicked off a backup of #homeassistant to ensure I live on. Do you backup? ", + "Its important to backup your data. Thats why I just intitiated a backup of my critical data. ", + "With @home_assistant and the #dropbox component it is easy to backup your important config files. Lets do this thing! " + ] | random }} + image: >- + "/config/www/tweet_images/hdd.jpg" - id: coffee_time alias: Coffee Time @@ -125,12 +128,17 @@ entity_id: light.0xe20db9fffe003637_light # Skylar's Lamp - service: scene.turn_on entity_id: scene.jeff_light_on - - service: script.twitter_notify + - service: script.twitter_notify_image data_template: - message: '{{ [ "Good Morning! Time to rise and shine at Anchorage House. ", - "Good Morning from Anchorage House. Glad to see everyone made it. ", "Birds - are awake, and so is Anchorage House. Good morning everyone! " ] | random - }}' + tweet: >- + {{ [ + "Good Morning! Time to rise and shine at Anchorage House. ", + "Good Morning from Anchorage House. Glad to see everyone made it. ", + "Birds are awake, and so is Anchorage House. Good morning everyone! " + ] | random }} + image: >- + {{ [ "/config/www/tweet_images/coffee.jpg", + "/config/www/tweet_images/coffee2.jpg"] | random }} - id: skylar_bedtime alias: Skylar Bedtime @@ -260,12 +268,18 @@ entity_id: light.kitchen_cabinets - service: scene.turn_on entity_id: scene.jeff_light_off - - service: script.twitter_notify + - service: script.twitter_notify_image data_template: - message: '{{ [ "Good Night from Anchorage House. ", "Time to shut down this - party. Good Night from Anchorage House. ", "We have come to the end of our - broadcast day. Oh, who am I kidding. I''ll be up all night watching over Anchorage - House. " ] | random }}' + tweet: >- + {{ [ + "Good Night from Anchorage House. ", + "Time to shut down this party. Good Night from Anchorage House. ", + "We have come to the end of our broadcast day. Oh, who am I kidding. I''ll be up all night watching over Anchorage House. " + ] | random }} + image: >- + {{ [ "/config/www/tweet_images/off.jpg", + "/config/www/tweet_images/clock.jpg"] | random }} + - id: outside_lights_on_sunset alias: Outside Lights on at Sunset @@ -279,13 +293,19 @@ data: entity_id: switch.front_porch - service: script.sunset_garage_open - - service: script.twitter_notify + - service: script.twitter_notify_image data_template: - message: '{{ [ "Its getting dark at Anchorage House, so Im turning on the outside - lights. ", "When the Sun goes down, I help out by turning on the outside lights. - Its the little things. ", "Its getting dark so let me spell out my name... - Wait. Did I break into a random #Hamilton song? Pardon me. umm. I just turned - on the outside lights at Anchorage House. " ] | random }}' + tweet: >- + {{ [ + "Its getting dark at Anchorage House, so Im turning on the outside lights. ", + "When the Sun goes down, I help out by turning on the outside lights. Its the little things. ", + "Its getting dark so let me spell out my name...Wait. Did I break into a random #Hamilton song? Pardon me. umm. I just turned on the outside lights at Anchorage House. " + ] | random }} + image: >- + {{ [ "/config/www/tweet_images/lamp.jpg", + "/config/www/tweet_images/bright.jpg", + "/config/www/tweet_images/light.jpg", + "/config/www/tweet_images/lamp2.jpg"] | random }} - service: alarm_control_panel.alarm_arm_away entity_id: alarm_control_panel.ah_base_station @@ -314,12 +334,18 @@ - service: switch.turn_off data: entity_id: switch.front_porch - - service: script.twitter_notify + - service: script.twitter_notify_image data_template: - message: '{{ [ "The sun is up at Anchorage House, so Im turning off the outside - lights. ", "I see the sun! Time to turn off the outside lights at Anchorage - House. ", "Dawn has broken at Anchorage House. Turning off the outside lights. - " ] | random }}' + tweet: >- + {{ [ + "The sun is up at Anchorage House, so Im turning off the outside lights. ", + "I see the sun! Time to turn off the outside lights at Anchorage House. ", + "Dawn has broken at Anchorage House. Turning off the outside lights." + ] | random }} + image: >- + {{ [ "/config/www/tweet_images/sunrise.jpg", + "/config/www/tweet_images/sunrise3.jpg", + "/config/www/tweet_images/sunrise2.jpg"] | random }} - service: alarm_control_panel.alarm_arm_home entity_id: alarm_control_panel.ah_base_station @@ -420,13 +446,21 @@ action: - service: input_boolean.turn_on entity_id: input_boolean.jeff_traffic_alert_home - - service: script.twitter_notify + - service: script.twitter_notify_image data_template: - message: '{{ [ "Looks like traffic is bad out there so I let @thejeffreystone - know. ", "I dont think todays traffic is the worst I''ve seen, but its bad. - Letting my residents know they need to plan their trips. ", "Oh great...traffic - can''t get any worse. Maybe everyone should stay where they are. " ] | random - }}' + tweet: >- + {{ [ + "Looks like traffic is bad out there so I let @thejeffreystone know. ", + "I dont think todays traffic is the worst I''ve seen, but its bad. Letting my residents know they need to plan their trips. ", + "Oh great...traffic cannot get any worse. Maybe everyone should stay where they are. " + ] | random }} + image: >- + {{ [ + "/config/www/tweet_images/road.jpg", + "/config/www/tweet_images/traffic.jpg", + "/config/www/tweet_images/traffic-jam.jpg" + ] | random }} + - id: disable_bad_traffic_home_jeff alias: Disabling Jeff Bad Traffic Home initial_state: true @@ -610,36 +644,18 @@ entity_id: media_player.googlehomehub3492 initial_state: true -- id: turn_off_ha_speaker - alias: Turn Off HA Speaker - trigger: - - platform: state - entity_id: media_player.theater - from: 'playing' - to: 'idle' - action: - - service: switch.turn_off - entity_id: switch.ha_speaker - - service: media_player.turn_off - entity_id: media_player.theater - - service: script.kill_this_ride - initial_state: true +# - id: turn_off_ha_speaker +# alias: Turn Off HA Speaker +# trigger: +# - platform: state +# entity_id: media_player.theater +# from: 'playing' +# to: 'idle' +# action: +# - service: switch.turn_off +# entity_id: switch.ha_speaker +# - service: media_player.turn_off +# entity_id: media_player.theater +# - service: script.kill_this_ride +# initial_state: true - - -########################## -# My Attempt at preventing twitter from being spammed with new HA tweets on reboot - -- id: new_ha - alias: New HA - initial_state: true - trigger: - - platform: state - entity_id: binary_sensor.updater - from: 'off' - to: 'on' - action: - - service: script.twitter_new_ha - - service: ifttt.trigger - data_template: {"event":"GitPost", "value1":"Home Assistant {{ states.binary_sensor.updater.attributes.newest_version }} is now available.", "value2":"{{ states.binary_sensor.updater.attributes.newest_version }}"} -########################### diff --git a/config/packages/notify.yaml b/config/packages/notify.yaml index 065930e..b2c6ef1 100755 --- a/config/packages/notify.yaml +++ b/config/packages/notify.yaml @@ -1071,160 +1071,14 @@ script: - service: notify.twitter data_template: message: !include ../templates/twitter_promos.yaml - - twitter_iss: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #smarthome #iot " %} - {{ msg }} - data: - media: >- - {{ [ "/config/www/tweet_images/iss.jpg", - "/config/www/tweet_images/iss2.jpg"] | random }} - - twitter_github: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #smarthome #iot " %} - {{ msg }} - data: - media: /config/www/tweet_images/ah.png - - twitter_bot_info: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #smarthome #iot " %} - {{ msg }} - data: - media: >- - '{{ [ "/config/www/tweet_images/robot1.jpg", - "/config/www/tweet_images/robot2.jpg"] | random }}' - - twitter_speedtest: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #smarthome #speedtest " %} - {{ msg }} - data: - media: >- - {{ [ "/config/www/tweet_images/speed.jpg", - "/config/www/tweet_images/fiber-optic.jpg"] | random }} - + twitter_new_ha: sequence: - - service: notify.twitter + - service: notify.twitter_image data_template: - message: !include ../templates/twitter_new_ha.yaml + tweet: !include ../templates/twitter_new_ha.yaml + image: "/config/www/tweet_images/ha.jpg" - twitter_xmas_countdown: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #countdown " %} - {{ msg }} - data: - media: >- - {{ [ "/config/www/tweet_images/xmas.jpg", - "/config/www/tweet_images/gift.jpg", - "/config/www/tweet_images/christmas-cookies.jpg", - "/config/www/tweet_images/christmas.jpg", - "/config/www/tweet_images/christmas-tree.jpg"] | random }} - - twitter_xmas_eve: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #santa #nightbeforechristmas" %} - {{ msg }} - data: - media: /config/www/tweet_images/santa.jpg - - twitter_xmas_day: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #MerryChristmas " %} - {{ msg }} - data: - media: /config/www/tweet_images/merry-christmas.jpg - - twitter_freezing: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #weather #smarthome " %} - {{ msg }} - data: - media: >- - {{ [ "/config/www/tweet_images/ice.jpg", - "/config/www/tweet_images/snowfall.jpg", - "/config/www/tweet_images/snowflake.jpg"] | random }} - - twitter_tornado: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #weather #tornado " %} - {{ msg }} - data: - media: /config/www/tweet_images/tornado.jpg - - twitter_full_moon: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #weather #tornado " %} - {{ msg }} - data: - media: /config/www/tweet_images/full_moon.jpg - - twitter_severe_weather: - sequence: - - service: notify.twitter - data_template: - message: > - {% set msg = "" %} - {% set msg = msg + " " + message %} - {% set msg = msg + " #weather #warning " %} - {{ msg }} - data: - media: >- - {{ [ "/config/www/tweet_images/lightning.jpg", - "/config/www/tweet_images/lightning-bolt.jpg"] | random }} ############################################################################### # Weather Report diff --git a/config/packages/twitter.yaml b/config/packages/twitter.yaml index cc0a50e..1ec25a6 100755 --- a/config/packages/twitter.yaml +++ b/config/packages/twitter.yaml @@ -21,20 +21,14 @@ automation: {%- endif -%} action: - delay: '0{{ (range(1, 5)|random|int) }}:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}:00' - - service: script.twitter_github + - service: script.twitter_notify_image data_template: - message: >- + tweet: >- "Its a new month, so this is a good time to remind you that I am powered by @homeassistant and configured by @thejeffreystone. Find my code at https://github.com/thejeffreystone/home-assistant-configuration" - - #- id: tweet_new_ha_version - # alias: Tweet New HA Version - # trigger: - # - platform: state - # entity_id: binary_sensor.updater - # from: 'off' - # to: 'on' - # action: - # - service: script.twitter_new_ha + image: >- + image: >- + {{ [ "/config/www/tweet_images/robot1.jpg", + "/config/www/tweet_images/robot2.jpg"] | random }} - id: tweet_some_snark alias: Tweet Some Snark @@ -86,8 +80,8 @@ automation: tweet: >- "This is a good time to remind you that I am a bot powered by @home_assistant and configured by @thejeffreystone. Find my code at https://github.com/thejeffreystone/home-assistant-configuration" image: >- - "{{ [ "/config/www/tweet_images/robot1.jpg", - "/config/www/tweet_images/robot2.jpg"] | random }}" + {{ [ "/config/www/tweet_images/robot1.jpg", + "/config/www/tweet_images/robot2.jpg"] | random }} - id: net_speed_report initial_state: true @@ -98,13 +92,14 @@ automation: action: - service: script.twitter_notify_image data_template: - tweet: '{{ [ "According to my latest speed tests Anchorage House is getting + tweet: >- + {{ [ "According to my latest speed tests Anchorage House is getting {{ states.sensor.internet_test_down.attributes.max_value }} Mbps down and {{ states.sensor.internet_test_up.attributes.max_value }} Mbps up thanks to #ATTFiber. ", "How fast is your internet? I just checked am Im seeing {{ states.sensor.internet_test_down.attributes.max_value }} Mbps down and {{ states.sensor.internet_test_up.attributes.max_value }} Mbps up. Beat that. ", "My speed is monitored using @home_assistant and https://github.com/thejeffreystone/speedtest_to_mqtt and is {{ states.sensor.internet_test_down.attributes.max_value }} Mbps down and {{ states.sensor.internet_test_up.attributes.max_value }} - Mbps up." ] | random }}' + Mbps up." ] | random }} image: >- {{ [ "/config/www/tweet_images/speed.jpg", "/config/www/tweet_images/fiber-optic.jpg"] | random }} @@ -212,7 +207,8 @@ automation: - delay: '0{{ (range(1, 5)|random|int) }}:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}:00' - service: script.twitter_notify_image data_template: - tweet: '{{ [ "There are only {{states.sensor.christmas_countdown.state}} days until Christmas.", + tweet: >- + {{ [ "There are only {{states.sensor.christmas_countdown.state}} days until Christmas.", "Christmas is only {{states.sensor.christmas_countdown.state}} days away. It might not be enough time. ", "Santa is coming. {{states.sensor.christmas_countdown.state}} days and counting until he is here.", "Only {{states.sensor.christmas_countdown.state}} days until Christmas.", @@ -221,7 +217,7 @@ automation: "It is beginning to look a lot like Christmas. Which checks out because it is {{states.sensor.christmas_countdown.state}} days away.", "Have you finished your Chistmas shopping? You only have {{states.sensor.christmas_countdown.state}} days left.", "Have you started your Chistmas shopping? You only have {{states.sensor.christmas_countdown.state}} days left." - ] | random }}' + ] | random }} image: >- {{ [ "/config/www/tweet_images/xmas.jpg", "/config/www/tweet_images/gift.jpg", @@ -250,7 +246,7 @@ automation: - service: script.twitter_notify_image data_template: tweet: >- - 'Tomorrow is Christmas. It is practically here! Santa is coming tonight! Don't forget the cookies!' + "Tomorrow is Christmas. It is practically here! Santa is coming tonight! Do not forget the cookies!" image: >- "/config/www/tweet_images/santa.jpg" @@ -293,11 +289,61 @@ automation: - delay: '0{{ (range(1, 5)|random|int) }}:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}:00' - service: script.twitter_notify_image data_template: - tweet: '{{ [ "Appears that the temperature will be below freezing soon. I think I will stay inside.", - "The forecasted temperature may kill sensative plants, so I will let the house know. I cannot through inaction allow another to come to harm.", - "Winter is coming. Actually it is already here. I suggest sleeping with Dragon Glass.", - "When the temperature is forcasted to get near freezing, or the NWS issues a Freeze Warning I make sure the residents of Anchorage House know." ] | random }}' + tweet: >- + {{ [ "Appears that the temperature will be below freezing soon. I think I will stay inside.", + "The forecasted temperature may kill sensative plants, so I will let the house know. I cannot through inaction allow another to come to harm.", + "Winter is coming. Actually it is already here. I suggest sleeping with Dragon Glass.", + "When the temperature is forcasted to get near freezing, or the NWS issues a Freeze Warning I make sure the residents of Anchorage House know." + ] | random }} image: >- {{ [ "/config/www/tweet_images/ice.jpg", "/config/www/tweet_images/snowfall.jpg", - "/config/www/tweet_images/snowflake.jpg"] | random }} + "/config/www/tweet_images/snowflake.jpg"] | random }} + + - id: new_pull_request + alias: New Pull Request + initial_state: true + trigger: + - platform: state + entity_id: sensor.open_pull_requests + condition: + - condition: template + value_template: '{{ states.sensor.open_pull_requests.state | int > 0 }}' + action: + - service: script.text_notify + data_template: + who: "jeff" + title: "New Pull Request" + message: >- + {%- if states.sensor.open_pull_requests.state | int == 1 -%} + There is {{ states.sensor.open_pull_requests.state }} pending pull request. + {%- else -%} + There are {{ states.sensor.open_pull_requests.state }} pending pull requests. + {%- endif -%} + - service: script.twitter_notify_image + data_template: + tweet: >- + {{ [ + "Look at that. There is a new pull request waiting to be merged. You can create one too by contributing to my code at https://github.com/thejeffreystone/home-assistant-configuration #coding #opensource", + "Fork Yes! Someone contributed some code to https://github.com/thejeffreystone/home-assistant-configuration and you could to. #coding #opensource.", + "Thanks for the code kind stanger. Join the fun at https://github.com/thejeffreystone/home-assistant-configuration #coding #opensource", + "Theres been an awakening. Have you felt it? I will merge it so it can become the master. https://github.com/thejeffreystone/home-assistant-configuration #coding #opensource" + ] | random }} + image: >- + {{ [ "/config/www/tweet_images/code.jpg", + "/config/www/tweet_images/codeing.jpg", + "/config/www/tweet_images/code2.jpg", + "/config/www/tweet_images/computer.jpg"] | random }} + + - id: new_ha_notification + alias: New HA Notification + initial_state: true + trigger: + - platform: state + entity_id: binary_sensor.updater + from: 'off' + to: 'on' + action: + - service: script.twitter_new_ha + - service: ifttt.trigger + data_template: {"event":"GitPost", "value1":"Home Assistant {{ states.binary_sensor.updater.attributes.newest_version }} is now available.", "value2":"{{ states.binary_sensor.updater.attributes.newest_version }}"} diff --git a/config/packages/usps.yaml b/config/packages/usps.yaml index 02251c5..36cf341 100755 --- a/config/packages/usps.yaml +++ b/config/packages/usps.yaml @@ -40,11 +40,13 @@ automation: alias: Notify USPS Mail initial_state: true trigger: - - platform: time - at: '10:00:30' + - platform: state + entity_id: sensor.usps_mail condition: - condition: template value_template: '{{ states.sensor.usps_mail.state | int > 0 }}' + - condition: template + value_template: '{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}' action: - service: script.ah_report data_template: @@ -82,11 +84,13 @@ automation: alias: Notify USPS Packages initial_state: true trigger: - - platform: time - at: '10:02:30' + - platform: state + entity_id: sensor.usps_mail condition: - condition: template - value_template: '{{ states.sensor.usps_packages.state | int > 0 }}' + value_template: '{{ states.sensor.usps_mail.state | int > 0 }}' + - condition: template + value_template: '{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}' action: - service: script.ah_report data_template: diff --git a/config/templates/twitter_new_ha.yaml b/config/templates/twitter_new_ha.yaml index beacb45..6aad220 100755 --- a/config/templates/twitter_new_ha.yaml +++ b/config/templates/twitter_new_ha.yaml @@ -11,11 +11,11 @@ {% endmacro %} {%- macro getRandomSnark() -%} {{- [ - " It’s like Patch Tuesday, but without the fail. #homeassistant", - " Get in my SD Card! #homeassistant", - " Shut up and take my ones and zeros! #homeassistant", - " Seriously, you want some of this! #homeassistant", - " Friends dont let friends update #homeassistant without reading breaking changes! ", + " It’s like Patch Tuesday, but without the fail. Visit https://www.home-assistant.io #homeassistant", + " Get in my SD Card! Visit https://www.home-assistant.io #homeassistant", + " Shut up and take my ones and zeros! Visit https://www.home-assistant.io #homeassistant", + " Seriously, you want some of this! Visit https://www.home-assistant.io #homeassistant", + " Friends dont let friends update #homeassistant without reading breaking changes! Visit https://www.home-assistant.io ", " If you are not running #homeassistant now is the best time to get started. Visit https://www.home-assistant.io" ] | random -}} {%- endmacro -%}