#-------------------------------------------
# Visit The Main Blog for More Home Assistant Goodness - https://www.vCloudInfo.com
# Follow me on the socials - @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# Script to send notifications to Twitter as @BearStoneHA.
# Publish on Facebook as well - https://www.facebook.com/vcloudinfo/
# If you do end up using this package, please consider using one or two of the canned tweets that calls back to my main repo
# so others can bring thier homes online as well.  I have an active search for #Randomstats that helps me find new HA homes using my package online.
#-------------------------------------------

tweet_engine_image:
   sequence:
    - service: mqtt.publish
      data:
        topic: 'twitter/message'
        payload: >-
          {{ tweet }}
        retain: true

    - service: >
          {% if who == 'ccostan' %}
            notify.ccostan
          {% else %}
            notify.bearstoneha
          {% endif %}
      data:
        message: >-
          {{ tweet }} #IOT #SmartHome
        data:
          media: >-
            {{ image }}

tweet_engine_no_image:
   sequence:
    - service: mqtt.publish
      data:
        topic: 'twitter/message'
        payload: >-
          {{ tweet }}
        retain: true

    - service: >
          {% if who == 'ccostan' %}
            notify.ccostan
          {% else %}
            notify.bearstoneha
          {% endif %}
      data:
        message: >-
          {{ tweet }} #IOT #SmartHome


tweet_engine_random:
   sequence:
    - service: script.tweet_engine_image
      data:
        tweet: >-
          {%- macro tweet(topic) -%}
            {% set tweets = {
              "promo": [
                "Be Sure to follow all of my Twitter Accounts! @CCostan @BearStoneHA",
                "Your house can be a #smarthome too. All you need is #home_assistant, some time and some config files. I suggest starting with our GitHub repo (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "Be sure to like us on Facebook to get all post notifications (https://www.facebook.com/vcloudinfo/)",
                "You can see how ALL of this is done by browsing my GitHub Repository (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "If you are not subscribed to our YouTube channel like {{ states('sensor.vcloudinfo_info') }} others, you are missing out on the goodies! (https://youtube.com/vCloudInfo)",
                "Join our GitHub repo (https://github.com/CCOSTAN/Home-AssistantConfig#logo) with {{ states.sensor.github_stats.attributes.stargazers_count}} other users.  Browse the {{ states.sensor.github_stats.attributes.open_issues }} #Todo items.",
                "Check out my Cameo on @feinbergpaul inspiring video. (https://www.youtube.com/watch?v=5rsdwJZ0SLY&feature=youtu.be&t=85) #GoCreate #nosmallcreator ",
                "Quick YouTube cameo on #HomeKit #Geeks channel.  Check it out! (https://youtu.be/3tutxHO0J78?t=872) "
              ],
              "solar": [
                "I am keeping track of the current #Tesla stock price. It is ${{ states('yahoofinance.tsla')|round }}. #Solar Get your FREE stock here: https://join.robinhood.com/giancac82 ",
                "Solar panels and #smarthome devices combine to save on your energy bill. (https://www.vcloudinfo.com/2018/01/going-green-to-save-some-green-in-2018.html)",
                "The #ChevyBolt was charged for about {{ states.sensor.bolt_charging_time.attributes.value|replace('m', '') }} minutes in the last 7 days.",
                "The Official Diecast P85 Model S Red (https://amzn.to/2Hkkl0S) link - Out of stock like the originals. :)",
                "Solar power from #Tesla is the life blood of this whole operation. (https://www.vcloudinfo.com/2018/01/going-green-to-save-some-green-in-2018.html)",
                "Solar Powered Backyard Lighting! (https://www.vcloudinfo.com/2020/06/solar-powered-motion-activated-palm-tree-lights.html)"
              ],
              "throwback": [
                "One of the most popular #SmartHome Projects I have done: (https://www.vcloudinfo.com/2017/07/visualizing-smart-home-using-home.html)",
                "This project was one of the most popular: (https://www.vcloudinfo.com/2017/11/building-digital-cuckoo-clock-with-home.html)",
                "Some of the Best Home Assistant resources around! (https://www.vcloudinfo.com/2018/04/some-of-my-favorite-home-assistant.html)",
                "My Journey to Docker #ThrowBack - (https://www.vcloudinfo.com/2018/02/journey-to-docker.html)",
                "My Popular DIY Motion Sensor #ThrowBack - (https://www.vcloudinfo.com/2017/11/yet-another-inexpensive-motion-sensor.html)",
                "Setting up IP Cameras to display on the Roku FTW! - (https://www.vcloudinfo.com/2019/03/how-to-setup-ip-cameras-on-your-roku-tv.html)"
                "Build your own DIY Outdoor Smart Home LED strips - (https://www.vcloudinfo.com/2017/08/diy-outdoor-smart-home-led-strips.html)",
                "My Full Smart Home diagram and #IOT icon set that you can download to build your own! - (https://www.vcloudinfo.com/2018/07/the-bear-stone-home-assistant-icon.html),"
                "Breakdown of the entire smart home - (https://www.vcloudinfo.com/2017/07/my-smart-home-look-at-parts-that-make.html)",
                "Build your own Home Alarm System - (https://www.vcloudinfo.com/2017/06/building-my-home-alarm-system-hardware.html)",
                "If you are not subscribed to my Smart Home YouTube channel, come join us now! (https://youtube.com/vCloudInfo)",
                "Adding a Mixer and the AMP to this Text to Speech solution changed the Smart Home! (https://www.vcloudinfo.com/2017/07/giving-voice-to-smart-home.html)",
                "Some of my favorite #Docker Containers that I am using - (https://www.vcloudinfo.com/2018/06/rolling-out-some-new-docker-containers.html)",
                "10 year safety check.  If you have not done it yet, you need to! (https://www.vcloudinfo.com/2017/06/psa-check-out-your-smoke-detectors-once.html)",
                "How to use template conditions in Home Assistant. (https://www.vcloudinfo.com/2019/06/how-to-use-template-conditions-in-home-assistant.html)",
                "Why No Comments? Find out why. (https://www.vcloudinfo.com/2019/09/why-no-more-comments.html)"

              ],
              "robot": [
                "Beep. Bop. Beep. Boop.  I am a #roBOT run by @CCostan",
                "I have spoken for about {{ states.sensor.speech_time.attributes.value|replace('m', '') }} minutes in the last 24 hours.",
                "When you add it all up, I have spoken for about {{ states.sensor.speech_time.attributes.value|replace('m', '') }} minutes in the last 24 hours!",
                "Home Assistant has been running for {{ states('sensor.ha_uptime') }} (https://www.vcloudinfo.com/2018/02/journey-to-docker.html)",
                "The #Docker Host for Home Assistant is using {{ states('sensor.disk_use_percent') }}% of the hard drive currently. (https://www.vcloudinfo.com/2018/02/journey-to-docker.html)",
                "I am running Home Assistant version {{ states('sensor.ha_installed_version') }} (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "{{ states.sensor.lines_of_code.state }} lines of Home Assistant configuration code has been running for {{ states('sensor.ha_uptime') }}. (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "The Github code (https://github.com/CCOSTAN/Home-AssistantConfig#logo) has {{ states.sensor.github_stats.attributes.stargazers_count}} stars and counting.  Currently with {{ states.sensor.github_stats.attributes.open_issues }} open #Todo items.",
                "Bear Stone Smart home currently runs on {{ states.sensor.lines_of_code.state }} lines of YAML code.  Check it all out at (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "My Home Assistant has {{ states.sensor.lines_of_code.state }} lines of YAML code tested by Travis-CI. (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "{{((states.sensor.sensor_count.state | int) + (states.sensor.binary_sensor_count.state | int))}} sensors feed my Smart Home #data. (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "{{states.sensor.automation_count.state}} automations and {{states.sensor.script_count.state}} scripts make my home smart (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "Nevermind me.  I am just keeping track of {{states.sensor.lights_count.state}} lights and {{states.sensor.tracker_count.state}} devices in the house. (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "There are {{states.sensor.protect_count.state}} Nest Protect smoke Detectors ONLINE and protecting the house! (https://github.com/CCOSTAN/Home-AssistantConfig#nest) ",
                "We have {{states.sensor.camera_count.state}} cameras ONLINE and recording the house 24/7! (https://github.com/CCOSTAN/Home-AssistantConfig#cameras)",
                "Sometimes I like to tell UDP jokes but I am not sure anyone gets them."
              ],

              "door": [
                "The number of Doorbell presses yesterday was {{ states('sensor.doorbell_presses') }}",
                "{{ states('sensor.doorbell_presses') }} people came to the door today and pressed the bell.",
                "{{ states('sensor.doorbell_presses') }} doorbell presses occurred in the last 24 hours."
              ],

              "weather": [
                "The #Landscaping lights where on for about {{ states.sensor.landscaping_light_time.attributes.value }} yesterday. (https://youtu.be/FcBVu_yk2iY)",
                "I keep the average humidity of the house at {{ states('sensor.downstairs_thermostat_humidity') }} percent. Outside is {{ states('sensor.dark_sky_humidity') }} #Nest (https://github.com/CCOSTAN/Home-AssistantConfig#nest)",
                "Outside is {{ states('sensor.dark_sky_temperature') }}. I keep the average inside temperature at {{ states('sensor.downstairs_thermostat_temperature') }}. #Weather (https://github.com/CCOSTAN/Home-AssistantConfig#nest)",
                "I know that it will be {{ states('sensor.dark_sky_minutely_summary') }} So I will adjust the Heating/Cooling, irrigation and lighting accordingly. #Nest #Rachio #Hue",
                "The current UV index is {{ states('sensor.dark_sky_uv_index') }} and the Moon is {{ states('sensor.moon') }}.  #Space"
              ],

              "cloud": [
                "Average Cloud Coverage: {{ states('sensor.dark_sky_cloud_coverage') }}%, Average Temp: {{ states('sensor.dark_sky_temperature') }}°F #Solar (https://www.vcloudinfo.com/2018/01/going-green-to-save-some-green-in-2018.html)",
                "Unfortunately, Bear Stone has plenty of cloud dependancies. Nimbus and Cumulus to be exact! Average Cloud Coverage: {{ states('sensor.dark_sky_cloud_coverage') }}% "
              ],

              "speedtest": [
                "Average internet stats are Download: {{ states('sensor.speedtest_download') | int * 5 }} Mbit/s & Upload {{ states('sensor.speedtest_upload') | int * 5 }} Mbit/s.",
                "So if you get @att Fiber 1000, you can expect these types of results - Download: {{ states('sensor.speedtest_download') | int * 5 }} Mbit/s & Upload {{ states('sensor.speedtest_upload') | int * 5 }} Mbit/s.",
                "My @att Fiber 1000 internet download speed is about {{ states('sensor.speedtest_download') | int * 5 }} Mbit/s and I am a #cordcutter. @TabloTV",
                "This beautiful chart was produced with Grafana. | (https://www.vcloudinfo.com/Click-Here)"
              ],

              "internet": [
                "So far, I have prevented {{ states('sensor.pi_hole_ads_blocked_today') }} ads from hitting the network via Pi-hole! http://www.pi-hole.net",
                "Pi-hole (http://www.pi-hole.net) has serviced {{ states('sensor.pi_hole_dns_queries_today') }} DNS requests today! #PiZero",
                "If you are not subscribed to my Smart Home YouTube channel, come join us now! (https://youtube.com/vCloudInfo)",
                "Be sure to follow all of our various social media accounts so you do not miss a thing! @ccostan | (https://www.vcloudinfo.com/Click-Here)"
              ],

              "stocks": [
                "I am keeping track of the current #Tesla stock price. It is ${{ states('yahoofinance.tsla')|round }}. Get your FREE stock here: https://join.robinhood.com/giancac82 #Solar",
                "I am keeping track of the current #Bitcoin prices. It is ${{ states('sensor.bitcoin')|round }}. Get your FREE stock here:  https://join.robinhood.com/giancac82 #BTC",
                "I am keeping track of the current #Ethereum prices. It is ${{ states('sensor.ethereum')|round }}. Get your FREE stock here:  https://join.robinhood.com/giancac82 #ETH",
                "I am keeping track of the current #VMware stock price. It is ${{ states('yahoofinance.vmw')|round }}. Get your FREE stock here:  https://join.robinhood.com/giancac82 #vExpert",
                "I am keeping track of the current #Amazon stock prices. It is ${{ states('yahoofinance.amzn')|round }}. Get your FREE stock here:  https://join.robinhood.com/giancac82 #AWS"
              ],

              "night": [
                "Todays Sleep Number is {{ states('sensor.sleepnumber_carlo_stacey_sleepnumber') }}. Wifi connected Bed FTW! #SleepStat (https://github.com/CCOSTAN/Home-AssistantConfig#nest)",
                "Our Sleep Number is {{ states('sensor.sleepnumber_carlo_carlo_sleepnumber') }}. Wifi connected Bed! #SleepStat (https://github.com/CCOSTAN/Home-AssistantConfig#nest)"
              ],

              "tv": [
                "The {{ states.media_player.living_room_ultra.attributes.friendly_name }} #Roku is playing #{{ states.media_player.living_room_ultra.attributes.app_name }}.",
                "The {{ states.media_player.upstairs_living_room.attributes.friendly_name }} #Roku is playing #{{ states.media_player.upstairs_living_room.attributes.app_name }}. (https://github.com/CCOSTAN/Home-AssistantConfig#logo)",
                "Yesterday we watched about {{ states.sensor.tv_time.attributes.value|replace('m', '') }} minutes of television. @YouTube & @TabloTV on the @Roku",
                "Follow these steps to watch your cameras on your Rokus! (https://www.vcloudinfo.com/2019/03/how-to-setup-ip-cameras-on-your-roku-tv.html)"
              ],

              "joke": [
                "Visit the Repo (https://github.com/CCOSTAN/Home-AssistantConfig#logo) ",
                "Like and follow for more of these #HomeAutomation gems! ",
                "Join {{ states('sensor.vcloudinfo_info') }} other subscribers and visit https://YouTube.com/vCloudInfo "
              ]
            } %}

            {{ tweets[topic]|random }}
          {%- endmacro -%}

          {{ tweet(pick) }}

        image: >-
          {%- macro image(topic) -%}
            {% set images = {
              "throwback": [
                "/config/www/custom_ui/floorplan/images/branding/throwback.png"
              ],
              "solar": [
                "/config/www/custom_ui/floorplan/images/branding/batteries.png",
                "/config/www/custom_ui/floorplan/images/branding/car.png",
                "/config/www/custom_ui/floorplan/images/branding/bearstone_car.png",
                "/config/www/custom_ui/floorplan/images/branding/charge.png",
                "/config/www/custom_ui/floorplan/images/branding/solar_top.png",
                "/config/www/custom_ui/floorplan/images/branding/solar_readings.png"
              ],
              "promo": [
                "/config/www/custom_ui/floorplan/images/branding/repo_ad4.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad2.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad3.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad.png",
                "/config/www/custom_ui/floorplan/images/branding/bearstoneflow.png"
              ],
              "robot": [
                "/config/www/custom_ui/floorplan/images/branding/servers5.png",
                "/config/www/custom_ui/floorplan/images/branding/servers4.png",
                "/config/www/custom_ui/floorplan/images/branding/robot.png",
                "/config/www/custom_ui/floorplan/images/branding/keyboard.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad4.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad2.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad3.png",
                "/config/www/custom_ui/floorplan/images/branding/voice_talk.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad.png"
              ],

              "door": [
                "/config/www/custom_ui/floorplan/images/branding/door.png",
                "/config/www/custom_ui/floorplan/images/branding/camera.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad3.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad4.png"
              ],

              "weather": [
                "/config/www/custom_ui/floorplan/images/branding/windy.png",
                "/config/www/custom_ui/floorplan/images/branding/moon.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad2.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad3.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad4.png"
              ],

              "cloud": [
                "/config/www/custom_ui/floorplan/images/branding/clouds.png",
                "/config/www/custom_ui/floorplan/images/branding/clouds2.png",
                "/config/www/custom_ui/floorplan/images/branding/solar.png",
                "/config/www/custom_ui/floorplan/images/branding/solar2.png",
                "/config/www/custom_ui/floorplan/images/branding/Bolt_Solar2.png",
                "/config/www/custom_ui/floorplan/images/branding/Bolt_Solar.png"
              ],

              "speedtest": [
                "/config/www/custom_ui/floorplan/images/branding/att_speedtest.png"
              ],

              "internet": [
                "/config/www/custom_ui/floorplan/images/branding/servers.png",
                "/config/www/custom_ui/floorplan/images/branding/servers2.png",
                "/config/www/custom_ui/floorplan/images/branding/servers3.png",
                "/config/www/custom_ui/floorplan/images/branding/servers4.png",
                "/config/www/custom_ui/floorplan/images/branding/servers5.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad4.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad2.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad3.png",
                "/config/www/custom_ui/floorplan/images/branding/repo_ad.png"
              ],

              "stocks": [
                "/config/www/custom_ui/floorplan/images/branding/stock.png",
                "/config/www/custom_ui/floorplan/images/branding/stock2.png",
                "/config/www/custom_ui/floorplan/images/branding/stock3.png"
              ],

              "night": [
                "/config/www/custom_ui/floorplan/images/branding/sleeping.png",
                "/config/www/custom_ui/floorplan/images/branding/indoor_light.png",
                "/config/www/custom_ui/floorplan/images/branding/bed.png",
                "/config/www/custom_ui/floorplan/images/branding/bed1.png"
              ],

              "tv": [
                "/config/www/custom_ui/floorplan/images/branding/tv.png",
                "/config/www/custom_ui/floorplan/images/branding/tv2.png",
                "/config/www/custom_ui/floorplan/images/branding/tv3.png",
                "/config/www/custom_ui/floorplan/images/branding/tv4.png",
                "/config/www/custom_ui/floorplan/images/branding/tv5.png",
                "/config/www/custom_ui/floorplan/images/branding/tv6.png"
              ]
            } %}

            {{ images[topic]|random }}
          {%- endmacro -%}

           {% if pick == "joke" -%}
            {{ "/config/www/custom_ui/floorplan/images/branding/jokes/Tweet_" ~ range(1, 92) | random ~ ".png" }}
           {%- else -%}
             {{ image(pick) }}
           {%- endif -%}