<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>Remote control fireplace</title>
 <link rel="stylesheet" type="text/css" href="/style.css">
</head>
<body>
 <header>
   <h1 class="title">Remote control fireplace</h1>
   <p class="date">2020-11-25</p>
 </header>
<p>Last year Sarah and I bought a <em>Regal Flame Spectrum Modern Linear Electric 3 Sided Wall Mounted Built-in Recessed Fireplace (50")</em> and installed it under our TV. One problem is that it comes with an annoying little remote that we keep losing track of, so I decided to hook up a Raspberry Pi to allow us to control it with our phones.</p>
<div class="figure">
<a href="photos/product.jpg"><img src="photos/thumbnails/product.jpg" alt="Product photo from online"></a>
<p class="caption">
Product photo from online
</p>
</div>
<div class="figure">
<a href="photos/installed.jpg"><img src="photos/thumbnails/installed.jpg" alt="Installed under TV"></a>
<p class="caption">
Installed under TV
</p>
</div>
<p>First I set up a Raspberry Pi Zero W with Void Linux, and connected a 38kHz Vishay TSOP38238 receiver to one of its GPIO pins. These IR receivers are well supported on Raspberry Pi, and all I needed to do was add these line to /boot/config.txt:</p>
<pre><code>dtoverlay=gpio-ir,gpio_pin=17
dtoverlay=gpio-ir-tx,gpio_pin=4</code></pre>
<h2 id="hardware">Hardware</h2>
<p>I needed to know what type of codes were being sent by the remote (Sony, Philips, NEC). I looked at the waveform with an oscilloscope and figured out that it was sending NEC codes. Then I used the program <strong>ir-ctl</strong> from <strong>v4l-utils</strong> to figure out which codes were sent for which buttons.</p>
<p>Then I breadboarded a small circuit to drive an LED with a transistor, and I went to my parts bin and found a bunch of IR LEDs tried each of them until I found an LED that transmitted at the correct IR wavelength to be picked up by the fireplace. I soldered the LED and the transistor to a piece of protoboard and mounted it tucked under the mantel aiming at the IR receiver.</p>
<h2 id="software">Software</h2>
<p>The heater temperature needs to be set every time the unit is turned on. I wrote a shell script that simulates the sequence of button presses that turns on the heater to full strength and sets the temperature cutoff to 82°F.</p>
<pre class="sh"><code>#!/bin/sh

TIMER=0x8006
BG_BRIGHTNESS=0x800a
ON=0x8012
LOG_BRIGHTNESS=0x8019
STRENGTH=0x801e
TEMP=0x801f

press () {
   ir-ctl -S nec:$1
}

press $ON

press $STRENGTH
press $STRENGTH
press $STRENGTH

press $TEMP
press $TEMP
press $TEMP
press $TEMP
press $TEMP
press $TEMP
press $TEMP</code></pre>
<h2 id="idempotent-power-control">Idempotent power control</h2>
<p>I would prefer to have some way of explicitly turning the fireplace on or off, rather than just toggling the power state. I found that if I quickly send a sequence like TEMP-POWER, the fireplace will skip processing the POWER keypress if it's already on, which can be used as a "turn the fireplace on, or leave the fireplace on" primitive. However it's not very reliable and I haven't found a more reliable method yet, so for now I just have a single "toggle" control that switches it from off-&gt;on or vice versa. The fireplace beeps after every button press so we can hear when it's toggled on because it beeps a bunch of times, whereas when it's toggled off it only beeps once for the initial POWER button press.</p>
<h2 id="homeassistant">Homeassistant</h2>
<p>I use Homeassistant to control some things in my house, so I added these lines to configuration.yaml to allow us to toggle the fireplace from our phones:</p>
<p><em>configuration.yaml</em>:</p>
<pre class="yaml"><code>shell_command:
 fireplace_toggle: ssh -i /config/fireplace_ssh -o UserKnownHostsFile=/config/ssh_known_hosts root@fireplace toggle

light:
  - platform: template
    lights:
      fireplace:
        turn_on:
          service: shell_command.fireplace_toggle
        turn_off:
          service: shell_command.fireplace_toggle</code></pre>
<p>And then I'm using <a href="http://blog.qartis.com/lazy_hardened_void_linux_raspberry_pi/#optional-allow-some-unprivileged-ssh-commands"><code>ssh_command</code> as described in another post</a> to only allow the fireplace_ssh key to run the <code>toggle</code> command.</p>
</body>
</html>