input_boolean:
  floorplan_night_mode:
    initial: off
  floorplan_show_all:

binary_sensor:
  - platform: template
    sensors:
      floorplan_night_mode:
        value_template: >-
          {{ states('sun.sun') == 'below_horizon'
              or is_state('input_boolean.floorplan_night_mode', 'on') }}

sensor:
  - platform: time_date
    display_options:
      - "time"
      - "date"

  - platform: uptime

  - platform: filesize
    file_paths:
      - /config/home-assistant_v2.db
      - /config/home-assistant.log

  - platform: template
    sensors:
      sarah_url:
        friendly_name: "SARAH's URL"
        value_template: !secret sarah_url
      automations_count:
        friendly_name: "Number of automations"
        value_template: "{{ states.automation | count }}"


shell_command:
  clear_logs: truncate -s 0 /config/home-assistant.log

script:
  sarah_restart:
    alias: System · Restart SARAH
    sequence:
      service: homeassistant.restart

automation:
  - alias: System · Announce start
    trigger:
      platform: homeassistant
      event: start
    action:
      - delay: 00:00:03
      - service: script.say
        data:
          message: "Hey! I was out for a bit, but I'm back online!"
          # - service: notify.telegram
          #   data:
          #     title: "⚙️ *System Module*"
          #     message: "Ask me to do something anytime!"
          #     data:
          #       keyboard:
          #         - "/guest_mode_on, /guest_mode_off"
          #         - "/status"

  - alias: System · Telegram · Announce status
    trigger:
      platform: event
      event_type: telegram_command
      event_data:
        command: "/status"
    action:
      - service: notify.telegram
        data_template:
          title: "⚙️ *System Module · Status*"
          message: >-

            Guest mode: {{ states('input_boolean.guest_mode') }}

            Windows:
              Living room: {{ states('binary_sensor.living_room_right_window') }}
              Master bedroom: {{ states('binary_sensor.bedroom_right_window') }}

            Lights:
              Living room: {{ states('light.living_room') }}
              Master bedroom: {{ states('light.master_bedroom') }}
              Kitchen: {{ states('light.kitchen') }}
              Hallway: {{ states('light.hallway') }}

  - alias: IFTTT · Call service
    trigger:
      platform: event
      event_type: ifttt_webhook_received
      event_data:
        action: "call-service"
    action:
      - service: "{{ trigger.event.data.service }}"
        data_template:
          entity_id: "{{ trigger.event.data.entity_id }}"
