#-------------------------------------------
#  @CCOSTAN
#  Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
#  PiHole ad Blocking Related Packages
#  https://www.vcloudinfo.com/2019/03/revisiting-the-pi-on-pi-day-with-home-assistant.html
#  YouTube Video - https://youtu.be/woA88DFlH5c
#-------------------------------------------

automation:
  - alias: PiHole Daily stats Tweet!
    id: c25b033e-c6df-445f-86fa-878b447c765a
    trigger:
      platform: time
      at: '23:50:00'
    action:
      - delay: '00:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}:00'
      - service: script.tweet_engine_image
        data:
          tweet: >
            {{ [
            "I blocked {{states.sensor.pi_hole_ads_blocked_today.state}} ads. That is {{states.sensor.pi_hole_ads_percentage_blocked_today.state}}% of my internet traffic.",
            "Today was a good day! Why, you ask? Because I blocked {{states.sensor.pi_hole_ads_blocked_today.state}} ads via Pi-Hole!",
            ] | random + " #PiHole #Security Status:({{states.switch.pi_hole.state}})"}}
          image: >-
            {{ [
            "/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"
            ] | random }}

  - alias: PiHole Daily Client Tweet!
    id: 8d85032d-4852-43df-9751-4a1918325287
    trigger:
      platform: time
      at: '04:30:00'
    action:
      - delay: '0{{ (range(1, 5)|random|int) }}:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}:00'
      - service: script.tweet_engine_image
        data:
          tweet: >
            {{ [
            "There are currently {{states.sensor.pi_hole_dns_unique_clients.state}} clients on my network.",
            "As reported by #Ubiquiti Routers, There are {{states.sensor.pi_hole_dns_unique_clients.state}} clients on my network.",
            ] | random + "#Security https://github.com/CCOSTAN/Home-AssistantConfig#networking"}}
          image: >-
            {{ [
            "/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"
            ] | random }}