Keypad

Keypad

Its a 3d printed keypad with 16 keys I bought from Etsy.

Overview

// https://stackoverflow.com/a/59363959/2115513 digraph SEQ_DIAGRAM { graph [overlap = true, splines = line, nodesep = 1.0, ordering = out]; edge [arrowhead = none]; node [shape = none, width = 0, height = 0, label = ""]; { rank = same; node [shape = rectangle, height = 0.7, width = 2]; keypad [label = "Keypad"]; raspberry_pi [label = "keypad2mqtt (raspberry pi)"]; homeassistant [label = "MQTT Broker (Home Assistant)"]; } // Draw vertical lines { edge [style = dashed, weight = 6]; keypad -> a1 -> a2 -> a3; a3 -> a5; } { edge [style = dashed, weight = 6]; raspberry_pi -> b1 b1 -> b2 [penwidth = 5, style = solid]; b2 -> b3 -> b4 -> b5; } { edge [style = dashed, weight = 6]; homeassistant -> c1; c1 -> c2; c2 -> c3 [penwidth = 5, style = solid]; c3 -> c4 -> c5; } { rank = same; a1 -> b1 [label = "send keydown event through USB", arrowhead = normal]; } { rank = same; b2 -> c2 [label ="publish to topic \"keypad/F1\" (to F16)", arrowhead = normal]; } }

Keypad

I mapped the keys from F1 to F16 using QMK or Vial… I can’t remember which one I used.

I used a P-touch label maker to label the keys.

The keypad is plugged to the raspberry pi.

The red X button will:

  • power off all the Smart Plugs except the one for the TV I keep always active;

  • send CEC message to turn off the TV;

  • stop the streaming on the Chromecasts;

  • close the light;

  • (I still manage the power of my consoles manually, however the PS5 will detect via CEC the TV is turned off so it will go to sleep automatically).

keypad2mqtt

Python program interfacing the keypad with Home Assistant. It is installed on the Raspberry pi and runs as a service.

sources

Installing the program

git clone git@github.com:jrobichaud/keypad2mqtt.git
cd keypad2mqtt
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Running the program

Make sure to change the arguments to match your mqtt broker configuration.

python3 -m "keypad2mqtt" "<homeassistant url>" -d "ZiddyMakes ZMK_16_KEY" -u "<mqtt user>" -p "<mqtt password>"

Service configuration

[Unit]
Description=keypad2mqtt
Documentation=
After=network.target

[Service]
Type=simple
User=retro
ExecStart=/usr/bin/python3 -m "keypad2mqtt" "<homeassistant url>" -d "ZiddyMakes ZMK_16_KEY" -u "<mqtt user>" -p "<mqtt password>"
Restart=always
MemorySwapMax=0

[Install]
WantedBy=multi-user.target

Home Assistant configuration

Create an Home Assistant automation for each key using a MQTT trigger for each topic.

trigger:
  - platform: mqtt
    topic: keypad/F1