<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>ESPHome ratgdo</title>
    <meta
      name="description"
      content="Install ratgdo on your ESPHome devices."
    />
    <meta name="viewport" content="width=device-width" />
    <meta name="color-scheme" content="dark light" />
    <meta property="og:title" content="ESPHome ratgdo" />
    <meta property="og:site_name" content="ESPHome ratgdo" />
    <meta
      property="og:url"
      content="https://ratgdo.github.io/esphome-ratgdo/"
    />
    <meta property="og:type" content="website" />
    <meta
      property="og:description"
      content="Install RATGTO on your ESPHome devices."
    />
    <meta
      property="og:image"
      content="https://ratgdo.github.io/esphome-ratgdo/header.png"
    />
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:site" content="@esphome_ratgdo" />
    <meta name="twitter:title" content="ESPHome ratgdo" />
    <meta
      name="twitter:description"
      content="Install ratgdo on your ESPHome devices."
    />
    <meta
      name="twitter:image"
      content="https://ratgdo.github.io/esphome-ratgdo/header.png"
    />

    <style>
      body {
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI",
          Roboto, Ubuntu, sans-serif;
        padding: 0;
        margin: 0;
        line-height: 1.4;
      }
      .content {
        max-width: 600px;
        margin: 0 auto;
        padding: 12px;
      }
      .header {
        display: block;
        width: 100%;
        aspect-ratio: 1200 / 675;
        border-radius: 12px;
      }
      h3 {
        margin-top: 1.5em;
      }
      a {
        color: #03a9f4;
      }
      .hidden {
        display: none;
      }
      li {
        padding: 4px 0;
      }
      .footer {
        margin-top: 24px;
        border-top: 1px solid #ccc;
        padding-top: 24px;
        text-align: center;
      }
      .footer .initiative {
        font-style: italic;
        margin-top: 16px;
      }
      .radios {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
      }
      .radios label {
        padding: 4px;
        cursor: pointer;
        width: calc(33.3% - 16px);
        display: block;
        position: relative;
      }
      .radios input {
        position: absolute;
        top: 12px;
        left: 12px;
      }
      .radios img {
        display: block;
        width: calc(100% - 8px);
        border: 4px solid rgba(0, 0, 0, 0);
        aspect-ratio: 1;
      }
      input:checked ~ img,
    img:has(+ input:checked){
    border-color: #58a6ff;
      }
      @media (prefers-color-scheme: dark) {
        body {
          background-color: #333;
          color: #fff;
        }
        a {
          color: #58a6ff;
        }
      }
      @media only screen and (max-width: 450px) {
        .radios label {
          width: calc(50% - 16px);
          max-width: initial;
        }
      }
      .diy::after {
        content: "DIY";
        background-color: #f44336;
        color: #fff;
        padding: 2px 4px;
        border-radius: 4px;
        font-size: 0.8em;
        position: absolute;
        bottom: 12px;
        left: 12px;
      }
      body .diy {
        display: none;
      }
      body.show-diy .diy {
        display: initial;
      }

      div.radios{
        display: flex;
    align-items: start;
        font-size: 75%;
      }
      div.radios label{
        /* padding: 10px; */
        width: 32%;
      }
      div.radios img{
        width: 150px;
        border-radius: 10px;
      }

    div.radios .note{
    font-size: 80%;
    color: #DDD;
    font-style:italic;
    }

    #wiring_diagram{
    width: 600px;
    border-radius: 15px;
    }
    </style>
    <script
      type="module"
      src="https://unpkg.com/esp-web-tools@9/dist/web/install-button.js?module"
    ></script>
  </head>
  <body>
    <div class="content">
      <img
        class="header"
        src="./header.png"
        alt="ESPHome ratgdo"
      />
      <h1>ESPHome ratgdo</h1>
      <p>
        In order to install the firmware, first pick your door opener control protocol, then pick your <a href="https://ratcloud.llc/">ratgdo control board</a> version.
        No programming or other software required.
      </p>

      <h2>Choose your GDO Control Protocol:</h2>
      <div class="protocol radios">
        <label>
          <img src="./yellow_learn_button.jpg" alt="Security + 2.0, round yellow learn button." />
          <input type="radio" name="protocol" value="secplusv2" checked />
          Security + 2.0<br/>
      round yellow learn button<br/>
      <span class="note">excluding models 8500/RJ020 &amp; 8500C/RJ020C</span>
        </label>

        <label>
          <img src="./purple_learn_button.jpg" alt="Security + 1.0, purple, orange, or red learn button." />
          <input type="radio" name="protocol" value="secplusv1" />
          Security + 1.0<br/>
      purple, brown, orange or red learn button<br/>
      <span class="note">or jackshaft models 8500/RJ020 &amp; 8500C/RJ020C</span><br/>
      <span class="note">Security + 1.0 support is experimental and may not work for all openers/wall panels.</span>
        </label>

        <label>
          <img src="./dry_contact.jpg" alt="Dry contact control." />
          <input type="radio" name="protocol" value="drycontact" />
          Dry Contact control<br/>Requires open &amp; close limit switches
        </label>
      </div>

    <h2>Choose your ratgdo control board:</h2>
    <div class="hardware radios">
      <label>
        <img src="./ratgdo32_disco.jpg" alt="v32 disco" />
        <input type="radio" name="hardware" value="v32disco" checked />
        ratgdo32 disco
      </label>

      <label>
        <img src="./ratgdo32.jpg" alt="v32 board" />
        <input type="radio" name="hardware" value="v32board" checked />
        ratgdo32
      </label>

      <label>
        <img src="./ratgdo_v2.5xi.jpg" alt="v2.5i, v2.52i, v2.53i" />
        <input type="radio" name="hardware" value="v25iboard" checked />
        ratgdo v2.5x<br/>
      v2.5, v2.5i, v2.52i, v2.53i (black PCB)
      </label>
    </div>

    <a id="show_legacy_hardware" style="text-decoration: underline;" onclick="toggleLegacy()">Show Legacy Hardware &raquo;</a>

    <div class="hardware radios" id="legacy_hardware" style="display: none">
        <label>
            <img src="./ratgdo_v2.0.jpg" alt="v2.0" />
            <input type="radio" name="hardware" value="v2board_esp8266_d1_mini" />
            ratgdo v2.0<br/>
            ESP8266 / D1 Mini (white PCB)
        </label>

        <label>
            <img src="./v25board_esp32_d1_mini.png" alt="v2.5 esp32" />
            <input type="radio" name="hardware" value="v25board_esp32_d1_mini" />
            ratgdo v2.5<br/>
            ESP32 (black PCB)
        </label>

        <label>
            <img src="./v2board_esp32_d1_mini.png" alt="v2.0 esp32" />
            <input type="radio" name="hardware" value="v2board_esp32_d1_mini" />
            ratgdo v2.0<br/>
            ESP32 (white PCB)
        </label>
    </div>

    <p>
      <esp-web-install-button></esp-web-install-button>
    </p>


    <h2>Wiring Diagram</h2>
    <img id="wiring_diagram" src="wiring_diagrams/v25iboard_secplus.png" alt="Security + 1 and 2 wiring diagram" />

    <h3>Documentation</h3>
    <ul>
      <li><a href="webui_documentation.html">Web User Interface Documentation</a></li>
    </ul>


    <h3>Drivers</h3>
    <p>If you can't connect to your ratgdo board make sure you have the right driver installed for the type of board you have.</p>
    <ul>
      <li>ratgdo32 and ratgdo32 disco use a CH9102 USB to Serial chipset. Modern versions of Windows &amp; macOS include the necessary drivers natively. Installing a standalone driver can create a conflict preventing you from connecting to ratgdo32.</li>
      <li>ratgdo v2.5i uses a CH340 USB to Serial chipset. [<a href="https://www.wch-ic.com/downloads/CH341SER_EXE.html" target="_blank">driver download</a>]</li>
    </ul>
    <p>Watch the v2.5i driver and firmware installation [<a href="https://www.youtube.com/watch?v=9WecAUTC9iI">video on YouTube</a>].</p>

      <h3>Advanced Users</h3>
      <ul>
        <li>
          The device is adoptable in
          <a
            href="https://my.home-assistant.io/redirect/supervisor_addon/?addon=5c53de3b_esphome&repository_url=https%3A%2F%2Fgithub.com%2Fesphome%2Fhome-assistant-addon"
            >the ESPHome dashboard</a
          >
        </li>
        <li>
          The YAML configuration for additional boards and chips is available on
          <a href="https://github.com/RATGDO/esphome-ratgdo/tree/main/static">GitHub</a>
        </li>
      </ul>

      <div class="footer">
        <a href="https://esphome.io">ESPHome</a>
        &mdash; Installer powered by
        <a href="https://esphome.github.io/esp-web-tools/">ESP Web Tools</a>.
      </div>
    </div>
    <script>
      function toggleLegacy() {
          var x = document.querySelector("#legacy_hardware");
          var y = document.querySelector("#show_legacy_hardware");
          if (x.style.display === "none") {
              x.style.display = "flex";
              y.innerHTML = "hide legacy hardware &raquo;";
          } else {
              x.style.display = "none";
              y.innerHTML = "show legacy hardware &raquo;";
          }
      }

      document.querySelectorAll('div.radios input').forEach((radio) =>
        radio.addEventListener("change", () => {
        const button = document.querySelector("esp-web-install-button");
        var protocol = document.querySelector('input[name="protocol"]:checked').value;
        var hardware = document.querySelector('input[name="hardware"]:checked').value;

        var diagram_protocol = protocol.replace("v1","").replace("v2","");
        var img = document.querySelector("#wiring_diagram");
        img.onerror = function() {
            console.log(`img not found: ${this.src}`);
            this.src = "wiring_diagrams/v25iboard_secplus.png";
        }
        img.src = `wiring_diagrams/${hardware}_${diagram_protocol}.png`;

        if(protocol !== "secplusv2" && (hardware === "v2board_esp8266_d1_mini" || hardware === "v2board_esp32_d1_mini")){
          alert("ratgdo version 2.0 only works with Security + 2.0");
          document.querySelector('input[name="protocol"][value="secplusv2"]').checked = true;
          return;
        }

        if(protocol === "secplusv2"){
          protocol = "";
        }else{
          protocol = `_${protocol}`;
        }

        button.manifest = `${hardware}${protocol}-manifest.json`;
      })
    );

      document
        .querySelector('input[name="protocol"]:checked')
        .dispatchEvent(new Event("change"));
    </script>
  </body>
</html>